From d4e57deb7edf480a8c95542d4dd2afe4e756a137 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Wed, 27 Oct 2004 11:36:40 +0000 Subject: Better test handling of File lines in stack traces. (Chad Austin) --- etc/TestSCons.py | 12 ++++++++ test/Alias.py | 6 +++- test/ParseConfig.py | 1 + test/QT.py | 84 ++++++++++++++++------------------------------------ test/SConstruct.py | 3 +- test/multi.py | 2 +- test/option--warn.py | 4 +-- test/option-f.py | 3 +- test/overrides.py | 6 ++-- 9 files changed, 51 insertions(+), 70 deletions(-) diff --git a/etc/TestSCons.py b/etc/TestSCons.py index 64bb90d..28f882b 100644 --- a/etc/TestSCons.py +++ b/etc/TestSCons.py @@ -85,6 +85,18 @@ else: fortran_lib = gccFortranLibs() + +file_expr = r"""File "[^"]*", line \d+, in .+ +""" + +# re.escape escapes too much. +def re_escape(str): + for c in ['.', '[', ']', '(', ')', '*', '+', '?']: # Not an exhaustive list. + str = string.replace(str, c, '\\' + c) + return str + + + class TestSCons(TestCommon): """Class for testing SCons. diff --git a/test/Alias.py b/test/Alias.py index 631aa30..1facd28 100644 --- a/test/Alias.py +++ b/test/Alias.py @@ -158,7 +158,11 @@ test.fail_test(not os.path.exists(test.workpath('f1.out'))) test.write('f3.in', "f3.in 3 \n") test.run(arguments = 'f1.out', - stdout = test.wrap_stdout('.* build.py f3.out f3.in\n.* build.py f1.out f1.in\n')) + match = TestCmd.match_exact, + stdout = test.wrap_stdout("""\ +%s build.py f3.out f3.in +%s build.py f1.out f1.in +""" % (python, python))) test.up_to_date(arguments = 'f1.out') diff --git a/test/ParseConfig.py b/test/ParseConfig.py index e7f50e5..c70bc3c 100644 --- a/test/ParseConfig.py +++ b/test/ParseConfig.py @@ -27,6 +27,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import sys +import TestCmd import TestSCons test = TestSCons.TestSCons() diff --git a/test/QT.py b/test/QT.py index 680784f..a03384e 100644 --- a/test/QT.py +++ b/test/QT.py @@ -73,9 +73,8 @@ sys.exit(0) """ ) test.write(['qt', 'bin', 'myuic.py'], """ -import os.path -import re import sys +import os.path import string output_arg = 0 impl_arg = 0 @@ -99,11 +98,10 @@ for arg in sys.argv[1:]: sourceFile = arg if impl: output.write( '#include "' + impl + '"\\n' ) - includes = re.findall('(.*?)', source.read()) - for incFile in includes: - # this is valid for ui.h files, at least - if os.path.exists(incFile): - output.write('#include "' + incFile + '"\\n') + if string.find(source.read(), '// ui.h') != -1: + output.write( + '#include "' + + os.path.basename(os.path.splitext(sourceFile)[0]) + '.ui.h"\\n') else: output.write( '#include "my_qobject.h"\\n' + source.read() + " Q_OBJECT \\n" ) output.close() @@ -273,22 +271,21 @@ test.not_up_to_date(chdir='work2', options = '-n', arguments = moc) test.not_up_to_date(chdir='work2', options = '-n', arguments = cpp) test.not_up_to_date(chdir='work2', options = '-n', arguments = h) test.run(chdir='work2', arguments = aaa_dll) -test.write(['work2', 'aaa.ui'], r""" -void aaa(void) -//aaa.ui.h -""") -test.run(chdir='work2', arguments = aaa_dll) # test that non-existant ui.h files are ignored (as uic does) test.write(['work2', 'aaa.ui.h'], r""" /* test dependency to .ui.h */ """) +test.write(['work2', 'aaa.ui'], r""" +void aaa(void) +// ui.h +""") test.run(chdir='work2', arguments = aaa_dll) test.write(['work2', 'aaa.ui.h'], r""" /* changed */ """) test.not_up_to_date(chdir='work2', options = '-n', arguments = obj) -test.not_up_to_date(chdir='work2', options = '-n', arguments = cpp) -test.not_up_to_date(chdir='work2', options = '-n', arguments = h) -test.not_up_to_date(chdir='work2', options = '-n', arguments = moc) +test.up_to_date(chdir='work2', options = '-n', arguments = cpp) +test.up_to_date(chdir='work2', options = '-n', arguments = h) +test.up_to_date(chdir='work2', options = '-n', arguments = moc) # clean up test.run(chdir='work2', arguments = '-c ' + aaa_dll) @@ -301,9 +298,6 @@ test.fail_test(not os.path.exists(test.workpath('work2','build',moc)) or os.path.exists(test.workpath('work2', moc)) or os.path.exists(test.workpath('work2', cpp)) or os.path.exists(test.workpath('work2', h))) -cppContents = test.read(test.workpath('work2', 'build', cpp)) -test.fail_test(string.find(cppContents, '#include "aaa.ui.h"') == -1) - test.run(chdir='work2', arguments = "build_dir=1 chdir=1 " + test.workpath('work2', 'build', aaa_dll) ) @@ -325,6 +319,7 @@ test.must_not_exist(['work2', moc], ['work2', cpp], ['work2', h]) + ############################################################################## # 3. create a moc file from a cpp file @@ -527,16 +522,16 @@ env = Environment(tools=['default','qt'], CXXFILESUFFIX=".cpp") conf = env.Configure() -if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0): +if not conf.CheckLib(env.subst("$QT_LIB")): conf.env['QT_LIB'] = 'qt-mt' - if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0): + if not conf.CheckLib(env.subst("$QT_LIB")): Exit(0) env = conf.Finish() -BuildDir('bld', '.') -env.Program('bld/test_realqt', ['bld/mocFromCpp.cpp', - 'bld/mocFromH.cpp', - 'bld/anUiFile.ui', - 'bld/main.cpp']) + +env.Program('test_realqt', ['mocFromCpp.cpp', + 'mocFromH.cpp', + 'anUiFile.ui', + 'main.cpp']) """) test.write( ['work7', 'mocFromCpp.h'],""" @@ -593,56 +588,29 @@ void mocFromH() { MyWidget - - anUiFile.ui.h - - - testSlot() - """) - test.write( ['work7', 'anUiFile.ui.h'], r""" -#include -#if QT_VERSION >= 0x030100 -void MyWidget::testSlot() -{ - printf("Hello World\n"); -} -#endif -""") - test.write( ['work7', 'main.cpp'], r""" -#include + test.write( ['work7', 'main.cpp'], """ #include "mocFromCpp.h" #include "mocFromH.h" #include "anUiFile.h" -#include - -int main(int argc, char **argv) { - QApplication app(argc, argv); +int main() { mocFromCpp(); mocFromH(); - MyWidget mywidget; -#if QT_VERSION >= 0x030100 - mywidget.testSlot(); -#else - printf("Hello World\n"); -#endif - return 0; + MyWidget mywidget(); } """) - test.run(chdir='work7', arguments="bld/test_realqt" + _exe) - test.run(program=test.workpath("work7", "bld", "test_realqt"), - stdout="Hello World\n") + test.run(chdir='work7', arguments="test_realqt" + _exe) QTDIR=os.environ['QTDIR'] del os.environ['QTDIR'] PATH=os.environ['PATH'] os.environ['PATH']='.' - test.run(chdir='work7', stderr=None, arguments="-c bld/test_realqt" + _exe) + test.run(chdir='work7', stderr=None, arguments="-c test_realqt" + _exe) test.fail_test(not test.match_re_dotall(test.stderr(), r""".* scons: warning: Could not detect qt, using empty QTDIR """ + TestSCons.file_expr)) @@ -650,7 +618,7 @@ scons: warning: Could not detect qt, using empty QTDIR os.environ['PATH'] = PATH test.run(chdir='work7', stderr=None, - arguments="PATH=%s%sbin bld%stest_realqt%s"%(QTDIR,os.sep,os.sep,_exe)) + arguments="PATH=%s%sbin test_realqt%s"%(QTDIR,os.sep,_exe)) test.fail_test(not test.match_re(test.stderr(), (r""" scons: warning: Could not detect qt, using moc executable as a hint \(QTDIR=%s\) """ + TestSCons.file_expr) % re.escape(QTDIR))) diff --git a/test/SConstruct.py b/test/SConstruct.py index a3ad3aa..b3fe9a0 100644 --- a/test/SConstruct.py +++ b/test/SConstruct.py @@ -34,8 +34,7 @@ test.run(arguments = ".", stdout = "", stderr = r""" scons: \*\*\* No SConstruct file found. -File "[^"]+", line \d+, in \S+ -""") +""" + TestSCons.file_expr) test.match_func = TestCmd.match_exact diff --git a/test/multi.py b/test/multi.py index 8e590d9..ef8a207 100644 --- a/test/multi.py +++ b/test/multi.py @@ -161,7 +161,7 @@ test.write('file5b.in', 'file5b.in\n') test.run(arguments='file5.out', stderr=TestSCons.re_escape(""" scons: warning: Two different environments were specified for target file5.out, - but they appear to have the same action: build(target, source, env) + but they appear to have the same action: build(["file5.out"], ["file5b.in"]) """) + TestSCons.file_expr) test.must_match('file5.out', "file5a.in\nfile5b.in\n") diff --git a/test/option--warn.py b/test/option--warn.py index 62245ab..20d274b 100644 --- a/test/option--warn.py +++ b/test/option--warn.py @@ -123,7 +123,7 @@ test.write('file1b.in', 'file1b.in\n') test.run(arguments='file1.out', stderr=r""" scons: warning: Two different environments were specified for target file1.out, - but they appear to have the same action: build\(target, source, env\) + but they appear to have the same action: build\(\["file1.out"\], \["file1b.in"\]\) """ + TestSCons.file_expr) test.must_match('file1.out', "file1a.in\nfile1b.in\n") @@ -131,7 +131,7 @@ test.must_match('file1.out', "file1a.in\nfile1b.in\n") test.run(arguments='--warn=duplicate-environment file1.out', stderr=r""" scons: warning: Two different environments were specified for target file1.out, - but they appear to have the same action: build\(target, source, env\) + but they appear to have the same action: build\(\["file1.out"\], \["file1b.in"\]\) """ + TestSCons.file_expr) test.run(arguments='--warn=no-duplicate-environment file1.out') diff --git a/test/option-f.py b/test/option-f.py index 06afece..da3a364 100644 --- a/test/option-f.py +++ b/test/option-f.py @@ -89,7 +89,6 @@ test.run(arguments = '-f no_such_file .', stderr = None) test.fail_test(not test.match_re(test.stderr(), """ scons: warning: Ignoring missing SConscript 'no_such_file' -File "[^"]+", line \d+, in .* -""")) +""" + TestSCons.file_expr)) test.pass_test() diff --git a/test/overrides.py b/test/overrides.py index 1013413..69f7440 100644 --- a/test/overrides.py +++ b/test/overrides.py @@ -118,11 +118,9 @@ open('goodbye.not_exe', 'wt').write('this is not a program!') test.run(arguments='goodbye.not_exe', stderr=None) test.fail_test(not test.match_re(test.stderr(), r""" scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\? -File "SConstruct", line \d+, in .+ - +""" + TestSCons.file_expr + r""" scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\? -File "SConstruct", line \d+, in .+ -""")) +""" + TestSCons.file_expr)) assert test.read('goodbye.not_obj') == 'this is no object file!' assert test.read('goodbye.not_exe') == 'this is not a program!' -- cgit v0.12