# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCmd.py 0.11.D001 2004/09/13 13:22:19 knight"
-__version__ = "0.11"
+__revision__ = "TestCmd.py 0.12.D001 2004/10/21 14:00:53 knight"
+__version__ = "0.12"
import os
import os.path
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCommon.py 0.11.D001 2004/09/13 13:22:19 knight"
-__version__ = "0.11"
+__revision__ = "TestCommon.py 0.12.D001 2004/10/21 14:00:53 knight"
+__version__ = "0.12"
import os
import os.path
apply(TestCmd.__init__, [self], kw)
os.chdir(self.workdir)
- def must_contain(self, file, required):
+ def must_contain(self, file, required, mode = 'rb'):
"""Ensures that the specified file contains the required text.
"""
- file_contents = self.read(file)
+ file_contents = self.read(file, mode)
contains = (string.find(file_contents, required) != -1)
if not contains:
print "File `%s' does not contain required string." % file
print "Missing files: `%s'" % string.join(missing, "', `")
self.fail_test(missing)
- def must_match(self, file, expect):
+ def must_match(self, file, expect, mode = 'rb'):
"""Matches the contents of the specified file (first argument)
against the expected contents (second argument). The expected
contents are a list of lines or a string which will be split
on newlines.
"""
- file_contents = self.read(file)
+ file_contents = self.read(file, mode)
try:
self.fail_test(not self.match(file_contents, expect))
except:
import os
ccc = Environment(tools = ['msvc', 'mslink', 'masm'],
ASFLAGS = '/nologo /coff')
-ccc['ENV']['PATH'] = os.environ['PATH']
+ccc['ENV']['PATH'] = ccc['ENV']['PATH'] + os.pathsep + os.environ['PATH']
ddd = ccc.Copy(AS = r'%s wrapper.py ' + ccc['AS'])
ccc.Program(target = 'ccc', source = ['ccc.asm', 'ccc_main.c'])
ddd.Program(target = 'ddd', source = ['ddd.asm', 'ddd_main.c'])
env.Cat('bbb.out', 'foo/bbb.in')
env.Cat('ccc.out', 'foo/ccc.in')
env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
-env.SourceCode('.', env.CVS(r'%s'))
+env.SourceCode('.', env.CVS(r'%(cvsroot)s'))
SConscript('foo/sub/SConscript', "env")
-""" % cvsroot)
+""" % locals())
test.subdir(['work1', 'foo'])
test.write(['work1', 'foo', 'bbb.in'], "work1/foo/bbb.in\n")
test.run(chdir = 'work1',
arguments = '.',
stdout = test.wrap_stdout(read_str = """\
-cvs -Q -d %s co foo/sub/SConscript
-""" % (cvsroot),
+cvs -Q -d %(cvsroot)s co foo/sub/SConscript
+""" % locals(),
build_str = """\
-cvs -Q -d %s co foo/aaa.in
-cat(["aaa.out"], ["%s"])
-cat(["bbb.out"], ["%s"])
-cvs -Q -d %s co foo/ccc.in
-cat(["ccc.out"], ["%s"])
+cvs -Q -d %(cvsroot)s co foo/aaa.in
+cat(["aaa.out"], ["%(foo_aaa_in)s"])
+cat(["bbb.out"], ["%(foo_bbb_in)s"])
+cvs -Q -d %(cvsroot)s co foo/ccc.in
+cat(["ccc.out"], ["%(foo_ccc_in)s"])
cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
-cvs -Q -d %s co foo/sub/ddd.in
-cat(["%s"], ["%s"])
-cat(["%s"], ["%s"])
-cvs -Q -d %s co foo/sub/fff.in
-cat(["%s"], ["%s"])
-cat(["%s"], ["%s", "%s", "%s"])
-""" % (cvsroot,
- foo_aaa_in,
- foo_bbb_in,
- cvsroot,
- foo_ccc_in,
- cvsroot,
- foo_sub_ddd_out, foo_sub_ddd_in,
- foo_sub_eee_out, foo_sub_eee_in,
- cvsroot,
- foo_sub_fff_out, foo_sub_fff_in,
- foo_sub_all, foo_sub_ddd_out, foo_sub_eee_out, foo_sub_fff_out)))
+cvs -Q -d %(cvsroot)s co foo/sub/ddd.in
+cat(["%(foo_sub_ddd_out)s"], ["%(foo_sub_ddd_in)s"])
+cat(["%(foo_sub_eee_out)s"], ["%(foo_sub_eee_in)s"])
+cvs -Q -d %(cvsroot)s co foo/sub/fff.in
+cat(["%(foo_sub_fff_out)s"], ["%(foo_sub_fff_in)s"])
+cat(["%(foo_sub_all)s"], ["%(foo_sub_ddd_out)s", "%(foo_sub_eee_out)s", "%(foo_sub_fff_out)s"])
+""" % locals()))
# Checking things back out of CVS apparently messes with the line
# endings, so read the result files in non-binary mode.
-test.fail_test(test.read(['work1', 'all'], 'r') != "import/aaa.in\nwork1/foo/bbb.in\nimport/ccc.in\n")
+test.must_match(['work1', 'all'],
+ "import/aaa.in\nwork1/foo/bbb.in\nimport/ccc.in\n",
+ mode='r')
-test.fail_test(test.read(['work1', 'foo', 'sub', 'all'], 'r') != "import/sub/ddd.in\nwork1/foo/sub/eee.in\nimport/sub/fff.in\n")
+test.must_match(['work1', 'foo', 'sub', 'all'],
+ "import/sub/ddd.in\nwork1/foo/sub/eee.in\nimport/sub/fff.in\n",
+ mode='r')
test.fail_test(not is_writable(test.workpath('work1', 'foo', 'sub', 'SConscript')))
test.fail_test(not is_writable(test.workpath('work1', 'foo', 'aaa.in')))
env.Cat('bbb.out', 'bbb.in')
env.Cat('ccc.out', 'ccc.in')
env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
-env.SourceCode('.', env.CVS(r'%s', 'foo'))
+env.SourceCode('.', env.CVS(r'%(cvsroot)s', 'foo'))
SConscript('sub/SConscript', "env")
-""" % cvsroot)
+""" % locals())
test.write(['work2', 'bbb.in'], "work2/bbb.in\n")
test.run(chdir = 'work2',
arguments = '.',
stdout = test.wrap_stdout(read_str = """\
-cvs -q -d %s co -d sub foo/sub/SConscript
+cvs -q -d %(cvsroot)s co -d sub foo/sub/SConscript
U sub/SConscript
-""" % (cvsroot),
+""" % locals(),
build_str = """\
-cvs -q -d %s co -d . foo/aaa.in
+cvs -q -d %(cvsroot)s co -d . foo/aaa.in
U ./aaa.in
cat(["aaa.out"], ["aaa.in"])
cat(["bbb.out"], ["bbb.in"])
-cvs -q -d %s co -d . foo/ccc.in
+cvs -q -d %(cvsroot)s co -d . foo/ccc.in
U ./ccc.in
cat(["ccc.out"], ["ccc.in"])
cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
-cvs -q -d %s co -d sub foo/sub/ddd.in
+cvs -q -d %(cvsroot)s co -d sub foo/sub/ddd.in
U sub/ddd.in
-cat(["%s"], ["%s"])
-cat(["%s"], ["%s"])
-cvs -q -d %s co -d sub foo/sub/fff.in
+cat(["%(sub_ddd_out)s"], ["%(sub_ddd_in)s"])
+cat(["%(sub_eee_out)s"], ["%(sub_eee_in)s"])
+cvs -q -d %(cvsroot)s co -d sub foo/sub/fff.in
U sub/fff.in
-cat(["%s"], ["%s"])
-cat(["%s"], ["%s", "%s", "%s"])
-""" % (cvsroot,
- cvsroot,
- cvsroot,
- sub_ddd_out, sub_ddd_in,
- sub_eee_out, sub_eee_in,
- cvsroot,
- sub_fff_out, sub_fff_in,
- sub_all, sub_ddd_out, sub_eee_out, sub_fff_out)))
+cat(["%(sub_fff_out)s"], ["%(sub_fff_in)s"])
+cat(["%(sub_all)s"], ["%(sub_ddd_out)s", "%(sub_eee_out)s", "%(sub_fff_out)s"])
+""" % locals()))
# Checking things back out of CVS apparently messes with the line
# endings, so read the result files in non-binary mode.
-test.fail_test(test.read(['work2', 'all'], 'r') != "import/aaa.in\nwork2/bbb.in\nimport/ccc.in\n")
+test.must_match(['work2', 'all'],
+ "import/aaa.in\nwork2/bbb.in\nimport/ccc.in\n",
+ mode='r')
-test.fail_test(test.read(['work2', 'sub', 'all'], 'r') != "import/sub/ddd.in\nwork2/sub/eee.in\nimport/sub/fff.in\n")
+test.must_match(['work2', 'sub', 'all'],
+ "import/sub/ddd.in\nwork2/sub/eee.in\nimport/sub/fff.in\n",
+ mode='r')
test.fail_test(not is_writable(test.workpath('work2', 'sub', 'SConscript')))
test.fail_test(not is_writable(test.workpath('work2', 'aaa.in')))
test.run(chdir = 'work3',
arguments = '.',
stdout = test.wrap_stdout(build_str = """\
-cvs -q -d %s co -d . foo/aaa.in
+cvs -q -d %(cvsroot)s co -d . foo/aaa.in
U ./aaa.in
cat(["aaa.out"], ["aaa.in"])
-cvs -q -d %s co -d . foo/bbb.in
+cvs -q -d %(cvsroot)s co -d . foo/bbb.in
U ./bbb.in
cat(["bbb.out"], ["bbb.in"])
-cvs -q -d %s co -d . foo/ccc.in
+cvs -q -d %(cvsroot)s co -d . foo/ccc.in
U ./ccc.in
cat(["ccc.out"], ["ccc.in"])
cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
-""" % (cvsroot,
- cvsroot,
- cvsroot)))
-
-test.must_match(['work3', 'aaa.out'], "import/aaa.in\n")
-test.must_match(['work3', 'bbb.out'], "import/bbb.in\n")
-test.must_match(['work3', 'ccc.out'], "import/ccc.in\n")
-test.must_match(['work3', 'all'], "import/aaa.in\nimport/bbb.in\nimport/ccc.in\n")
+""" % locals()))
+
+test.must_match(['work3', 'aaa.out'],
+ "import/aaa.in\n",
+ mode='r')
+test.must_match(['work3', 'bbb.out'],
+ "import/bbb.in\n",
+ mode='r')
+test.must_match(['work3', 'ccc.out'],
+ "import/ccc.in\n",
+ mode='r')
+test.must_match(['work3', 'all'],
+ "import/aaa.in\nimport/bbb.in\nimport/ccc.in\n",
+ mode='r')
# Test CVS checkouts from a remote server (Tigris.org).
test.subdir(['work4'])
# Test explicit checkouts from local RCS files.
test.subdir('work1', ['work1', 'sub'])
+sub_RCS = os.path.join('sub', 'RCS')
+sub_SConscript = os.path.join('sub', 'SConscript')
+sub_all = os.path.join('sub', 'all')
+sub_ddd_in = os.path.join('sub', 'ddd.in')
+sub_ddd_out = os.path.join('sub', 'ddd.out')
+sub_eee_in = os.path.join('sub', 'eee.in')
+sub_eee_out = os.path.join('sub', 'eee.out')
+sub_fff_in = os.path.join('sub', 'fff.in')
+sub_fff_out = os.path.join('sub', 'fff.out')
+
for file in ['aaa.in', 'bbb.in', 'ccc.in']:
test.write(['work1', file], "work1/%s\n" % file)
args = "-f -t%s %s" % (file, file)
test.write(['work1', 'SConstruct'], """
import os
-ENV = {'PATH' : os.environ['PATH']}
+for key in ['LOGNAME', 'USERNAME', 'USER']:
+ logname = os.environ.get(key)
+ if logname: break
+ENV = {'PATH' : os.environ['PATH'],
+ 'LOGNAME' : logname}
def cat(env, source, target):
target = str(target[0])
source = map(str, source)
env = Environment(ENV=ENV,
BUILDERS={'Cat':Builder(action=cat)},
RCS_COFLAGS='-q')
+DefaultEnvironment()['ENV'] = ENV
env.Cat('aaa.out', 'aaa.in')
env.Cat('bbb.out', 'bbb.in')
env.Cat('ccc.out', 'ccc.in')
test.run(chdir = 'work1',
arguments = '.',
stdout = test.wrap_stdout(read_str = """\
-co -q sub/SConscript
-""",
+co -q %(sub_SConscript)s
+""" % locals(),
build_str = """\
co -q aaa.in
cat(["aaa.out"], ["aaa.in"])
co -q ccc.in
cat(["ccc.out"], ["ccc.in"])
cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
-co -q sub/ddd.in
-cat(["sub/ddd.out"], ["sub/ddd.in"])
-cat(["sub/eee.out"], ["sub/eee.in"])
-co -q sub/fff.in
-cat(["sub/fff.out"], ["sub/fff.in"])
-cat(["sub/all"], ["sub/ddd.out", "sub/eee.out", "sub/fff.out"])
-"""))
+co -q %(sub_ddd_in)s
+cat(["%(sub_ddd_out)s"], ["%(sub_ddd_in)s"])
+cat(["%(sub_eee_out)s"], ["%(sub_eee_in)s"])
+co -q %(sub_fff_in)s
+cat(["%(sub_fff_out)s"], ["%(sub_fff_in)s"])
+cat(["%(sub_all)s"], ["%(sub_ddd_out)s", "%(sub_eee_out)s", "%(sub_fff_out)s"])
+""" % locals()))
+
+# Checking things back out of RCS apparently messes with the line
+# endings, so read the result files in non-binary mode.
-test.must_match(['work1', 'all'], "work1/aaa.in\nchecked-out work1/bbb.in\nwork1/ccc.in\n")
+test.must_match(['work1', 'all'],
+ "work1/aaa.in\nchecked-out work1/bbb.in\nwork1/ccc.in\n",
+ mode='r')
-test.must_match(['work1', 'sub', 'all'], "work1/sub/ddd.in\nchecked-out work1/sub/eee.in\nwork1/sub/fff.in\n")
+test.must_match(['work1', 'sub', 'all'],
+ "work1/sub/ddd.in\nchecked-out work1/sub/eee.in\nwork1/sub/fff.in\n",
+ mode='r')
test.fail_test(is_writable(test.workpath('work1', 'sub', 'SConscript')))
test.fail_test(is_writable(test.workpath('work1', 'aaa.in')))
test.write(['work2', 'SConstruct'], """
import os
-ENV = { 'PATH' : os.environ['PATH'] }
+for key in ['LOGNAME', 'USERNAME', 'USER']:
+ logname = os.environ.get(key)
+ if logname: break
+ENV = {'PATH' : os.environ['PATH'],
+ 'LOGNAME' : logname}
def cat(env, source, target):
target = str(target[0])
source = map(str, source)
for src in source:
f.write(open(src, "rb").read())
f.close()
+DefaultEnvironment()['ENV'] = ENV
DefaultEnvironment()['RCS_COFLAGS'] = '-l'
env = Environment(ENV=ENV, BUILDERS={'Cat':Builder(action=cat)})
env.Cat('aaa.out', 'aaa.in')
test.run(chdir = 'work2',
arguments = '.',
stdout = test.wrap_stdout(read_str = """\
-co -l sub/SConscript
-""",
+co -l %(sub_SConscript)s
+""" % locals(),
build_str = """\
co -l aaa.in
cat(["aaa.out"], ["aaa.in"])
co -l ccc.in
cat(["ccc.out"], ["ccc.in"])
cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
-co -l sub/ddd.in
-cat(["sub/ddd.out"], ["sub/ddd.in"])
-cat(["sub/eee.out"], ["sub/eee.in"])
-co -l sub/fff.in
-cat(["sub/fff.out"], ["sub/fff.in"])
-cat(["sub/all"], ["sub/ddd.out", "sub/eee.out", "sub/fff.out"])
-"""),
+co -l %(sub_ddd_in)s
+cat(["%(sub_ddd_out)s"], ["%(sub_ddd_in)s"])
+cat(["%(sub_eee_out)s"], ["%(sub_eee_in)s"])
+co -l %(sub_fff_in)s
+cat(["%(sub_fff_out)s"], ["%(sub_fff_in)s"])
+cat(["%(sub_all)s"], ["%(sub_ddd_out)s", "%(sub_eee_out)s", "%(sub_fff_out)s"])
+""" % locals()),
stderr = """\
-sub/RCS/SConscript,v --> sub/SConscript
+%(sub_RCS)s/SConscript,v --> %(sub_SConscript)s
revision 1.1 (locked)
done
RCS/aaa.in,v --> aaa.in
RCS/ccc.in,v --> ccc.in
revision 1.1 (locked)
done
-sub/RCS/ddd.in,v --> sub/ddd.in
+%(sub_RCS)s/ddd.in,v --> %(sub_ddd_in)s
revision 1.1 (locked)
done
-sub/RCS/fff.in,v --> sub/fff.in
+%(sub_RCS)s/fff.in,v --> %(sub_fff_in)s
revision 1.1 (locked)
done
-""")
+""" % locals())
+
+# Checking things back out of RCS apparently messes with the line
+# endings, so read the result files in non-binary mode.
-test.must_match(['work2', 'all'], "work2/aaa.in\nchecked-out work2/bbb.in\nwork2/ccc.in\n")
+test.must_match(['work2', 'all'],
+ "work2/aaa.in\nchecked-out work2/bbb.in\nwork2/ccc.in\n",
+ mode='r')
-test.must_match(['work2', 'sub', 'all'], "work2/sub/ddd.in\nchecked-out work2/sub/eee.in\nwork2/sub/fff.in\n")
+test.must_match(['work2', 'sub', 'all'],
+ "work2/sub/ddd.in\nchecked-out work2/sub/eee.in\nwork2/sub/fff.in\n",
+ mode='r')
test.fail_test(not is_writable(test.workpath('work2', 'sub', 'SConscript')))
test.fail_test(not is_writable(test.workpath('work2', 'aaa.in')))