diff options
author | Steven Knight <knight@baldmt.com> | 2002-07-10 22:39:00 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-07-10 22:39:00 (GMT) |
commit | f98a2dabc8603592c74f02674a8dc551533382b6 (patch) | |
tree | 343c9712c76d4e3d5de04ae50a92d65abe2be90e /test | |
parent | 3de3284918acb0add37b818400c1a7309a3316ff (diff) | |
download | SCons-f98a2dabc8603592c74f02674a8dc551533382b6.zip SCons-f98a2dabc8603592c74f02674a8dc551533382b6.tar.gz SCons-f98a2dabc8603592c74f02674a8dc551533382b6.tar.bz2 |
Allow build directories outside the SConstruct tree; add a FindFile() function to search for files with a specified name; add to the shared-object g++ and gcc command lines. (Charles Crain)
Diffstat (limited to 'test')
-rw-r--r-- | test/BuildDir.py | 79 | ||||
-rw-r--r-- | test/CPPFLAGS.py | 43 | ||||
-rw-r--r-- | test/FindFile.py | 64 |
3 files changed, 145 insertions, 41 deletions
diff --git a/test/BuildDir.py b/test/BuildDir.py index aae3a78..14c24e2 100644 --- a/test/BuildDir.py +++ b/test/BuildDir.py @@ -36,34 +36,36 @@ else: test = TestSCons.TestSCons() -foo11 = test.workpath('build', 'var1', 'foo1' + _exe) -foo12 = test.workpath('build', 'var1', 'foo2' + _exe) -foo21 = test.workpath('build', 'var2', 'foo1' + _exe) -foo22 = test.workpath('build', 'var2', 'foo2' + _exe) -foo31 = test.workpath('build', 'var3', 'foo1' + _exe) -foo32 = test.workpath('build', 'var3', 'foo2' + _exe) -foo41 = test.workpath('build', 'var4', 'foo1' + _exe) -foo42 = test.workpath('build', 'var4', 'foo2' + _exe) +foo11 = test.workpath('test', 'build', 'var1', 'foo1' + _exe) +foo12 = test.workpath('test', 'build', 'var1', 'foo2' + _exe) +foo21 = test.workpath('test', 'build', 'var2', 'foo1' + _exe) +foo22 = test.workpath('test', 'build', 'var2', 'foo2' + _exe) +foo31 = test.workpath('test', 'build', 'var3', 'foo1' + _exe) +foo32 = test.workpath('test', 'build', 'var3', 'foo2' + _exe) +foo41 = test.workpath('test', 'build', 'var4', 'foo1' + _exe) +foo42 = test.workpath('test', 'build', 'var4', 'foo2' + _exe) foo51 = test.workpath('build', 'var5', 'foo1' + _exe) foo52 = test.workpath('build', 'var5', 'foo2' + _exe) -bar11 = test.workpath('build', 'var1', 'bar1' + _exe) -bar12 = test.workpath('build', 'var1', 'bar2' + _exe) -bar21 = test.workpath('build', 'var2', 'bar1' + _exe) -bar22 = test.workpath('build', 'var2', 'bar2' + _exe) -bar31 = test.workpath('build', 'var3', 'bar1' + _exe) -bar32 = test.workpath('build', 'var3', 'bar2' + _exe) -bar41 = test.workpath('build', 'var4', 'bar1' + _exe) -bar42 = test.workpath('build', 'var4', 'bar2' + _exe) +bar11 = test.workpath('test', 'build', 'var1', 'bar1' + _exe) +bar12 = test.workpath('test', 'build', 'var1', 'bar2' + _exe) +bar21 = test.workpath('test', 'build', 'var2', 'bar1' + _exe) +bar22 = test.workpath('test', 'build', 'var2', 'bar2' + _exe) +bar31 = test.workpath('test', 'build', 'var3', 'bar1' + _exe) +bar32 = test.workpath('test', 'build', 'var3', 'bar2' + _exe) +bar41 = test.workpath('test', 'build', 'var4', 'bar1' + _exe) +bar42 = test.workpath('test', 'build', 'var4', 'bar2' + _exe) bar51 = test.workpath('build', 'var5', 'bar1' + _exe) bar52 = test.workpath('build', 'var5', 'bar2' + _exe) -test.write('SConstruct', """ +test.subdir('test') + +test.write('test/SConstruct', """ src = Dir('src') var2 = Dir('build/var2') var3 = Dir('build/var3') var4 = Dir('build/var4') -var5 = Dir('build/var5') +var5 = Dir('../build/var5') BuildDir('build/var1', src) @@ -81,11 +83,11 @@ SConscript('build/var3/SConscript', "env") SConscript(File('SConscript', var4), "env") env = Environment(CPPPATH='.', F77PATH='.') -SConscript('build/var5/SConscript', "env") +SConscript('../build/var5/SConscript', "env") """) -test.subdir('src') -test.write(['src', 'SConscript'], """ +test.subdir(['test', 'src']) +test.write(['test', 'src', 'SConscript'], """ import os import os.path @@ -108,7 +110,7 @@ env.Copy(LIBS = 'g2c').Program(target='bar2', source='b2.f') env.Copy(LIBS = 'g2c').Program(target='bar1', source='b1.f') """) -test.write('src/f1.c', r""" +test.write('test/src/f1.c', r""" #include "f1.h" int @@ -120,7 +122,7 @@ main(int argc, char *argv[]) } """) -test.write('src/f2.in', r""" +test.write('test/src/f2.in', r""" #include "f2.h" int @@ -132,37 +134,37 @@ main(int argc, char *argv[]) } """) -test.write('src/f1.h', r""" +test.write('test/src/f1.h', r""" #define F1_STR "f1.c\n" """) -test.write('src/f2.h', r""" +test.write('test/src/f2.h', r""" #define F2_STR "f2.c\n" """) -test.write(['src', 'b1.f'], r""" +test.write(['test', 'src', 'b1.f'], r""" PROGRAM FOO INCLUDE 'b1.for' STOP END """) -test.write(['src', 'b2.in'], r""" +test.write(['test', 'src', 'b2.in'], r""" PROGRAM FOO INCLUDE 'b2.for' STOP END """) -test.write(['src', 'b1.for'], r""" +test.write(['test', 'src', 'b1.for'], r""" PRINT *, 'b1.for' """) -test.write(['src', 'b2.for'], r""" +test.write(['test', 'src', 'b2.for'], r""" PRINT *, 'b2.for' """) -test.run(arguments = '.') +test.run(chdir='test', arguments = '. ../build') test.run(program = foo11, stdout = "f1.c\n") test.run(program = foo12, stdout = "f2.c\n") @@ -187,16 +189,16 @@ test.run(program = bar51, stdout = " b1.for\n") test.run(program = bar52, stdout = " b2.for\n") # Make sure we didn't duplicate the source files in build/var3. -test.fail_test(os.path.exists(test.workpath('build', 'var3', 'f1.c'))) -test.fail_test(os.path.exists(test.workpath('build', 'var3', 'f2.in'))) -test.fail_test(os.path.exists(test.workpath('build', 'var3', 'b1.f'))) -test.fail_test(os.path.exists(test.workpath('build', 'var3', 'b2.in'))) +test.fail_test(os.path.exists(test.workpath('test', 'build', 'var3', 'f1.c'))) +test.fail_test(os.path.exists(test.workpath('test', 'build', 'var3', 'f2.in'))) +test.fail_test(os.path.exists(test.workpath('test', 'build', 'var3', 'b1.f'))) +test.fail_test(os.path.exists(test.workpath('test', 'build', 'var3', 'b2.in'))) # Make sure we didn't duplicate the source files in build/var4. -test.fail_test(os.path.exists(test.workpath('build', 'var4', 'f1.c'))) -test.fail_test(os.path.exists(test.workpath('build', 'var4', 'f2.in'))) -test.fail_test(os.path.exists(test.workpath('build', 'var4', 'b1.f'))) -test.fail_test(os.path.exists(test.workpath('build', 'var4', 'b2.in'))) +test.fail_test(os.path.exists(test.workpath('test', 'build', 'var4', 'f1.c'))) +test.fail_test(os.path.exists(test.workpath('test', 'build', 'var4', 'f2.in'))) +test.fail_test(os.path.exists(test.workpath('test', 'build', 'var4', 'b1.f'))) +test.fail_test(os.path.exists(test.workpath('test', 'build', 'var4', 'b2.in'))) # Make sure we didn't duplicate the source files in build/var5. test.fail_test(os.path.exists(test.workpath('build', 'var5', 'f1.c'))) @@ -204,5 +206,4 @@ test.fail_test(os.path.exists(test.workpath('build', 'var5', 'f2.in'))) test.fail_test(os.path.exists(test.workpath('build', 'var5', 'b1.f'))) test.fail_test(os.path.exists(test.workpath('build', 'var5', 'b2.in'))) - test.pass_test() diff --git a/test/CPPFLAGS.py b/test/CPPFLAGS.py index 9c0295c..7b27233 100644 --- a/test/CPPFLAGS.py +++ b/test/CPPFLAGS.py @@ -74,7 +74,7 @@ else: import getopt import os import sys -opts, args = getopt.getopt(sys.argv[1:], 'o:') +opts, args = getopt.getopt(sys.argv[1:], 'o:s:') for opt, arg in opts: if opt == '-o': out = arg outfile = open(out, 'wb') @@ -92,7 +92,7 @@ import os import sys compiler = sys.argv[1] clen = len(compiler) + 1 -opts, args = getopt.getopt(sys.argv[2:], 'co:x') +opts, args = getopt.getopt(sys.argv[2:], 'co:xf:') for opt, arg in opts: if opt == '-o': out = arg elif opt == '-x': open('mygcc.out', 'ab').write(compiler + "\n") @@ -140,4 +140,43 @@ test.fail_test(test.read('foo' + _exe) != "test1.c\ntest2.cpp\ntest3.F\n") test.fail_test(test.read('mygcc.out') != "cc\nc++\ng77\n") +test.write('SConstruct', """ +env = Environment(CPPFLAGS = '-x', + SHLINK = r'%s mylink.py', + CC = r'%s mygcc.py cc', + CXX = r'%s mygcc.py c++', + F77 = r'%s mygcc.py g77') +env.SharedLibrary(target = File('foo.bar'), + source = Split('test1.c test2.cpp test3.F')) +""" % (python, python, python, python)) + +test.write('test1.c', r"""test1.c +#cc +#link +""") + +test.write('test2.cpp', r"""test2.cpp +#c++ +#link +""") + +test.write('test3.F', r"""test3.F +#g77 +#link +""") + +test.unlink('mygcc.out') + +test.run(arguments = '.', stderr = None) + +test.fail_test(test.read('test1' + _obj) != "test1.c\n#link\n") + +test.fail_test(test.read('test2' + _obj) != "test2.cpp\n#link\n") + +test.fail_test(test.read('test3' + _obj) != "test3.F\n#link\n") + +test.fail_test(test.read('foo.bar') != "test1.c\ntest2.cpp\ntest3.F\n") + +test.fail_test(test.read('mygcc.out') != "cc\nc++\ng77\n") + test.pass_test() diff --git a/test/FindFile.py b/test/FindFile.py new file mode 100644 index 0000000..6c3c347 --- /dev/null +++ b/test/FindFile.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# +# Copyright (c) 2001, 2002 Steven Knight +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir('foo') +test.subdir('bar') +test.subdir(['bar', 'baz']) + +test.write('testfile1', 'test 1\n') +test.write(['foo', 'testfile2'], 'test 2\n') +test.write(['bar', 'testfile1'], 'test 3\n') +test.write(['bar', 'baz', 'testfile2'], 'test 4\n') + +test.write('SConstruct', """ +file1 = FindFile('testfile1', [ 'foo', '.', 'bar', 'bar/baz' ]) +print open(str(file1), 'r').read() +file2 = FindFile('testfile1', [ 'bar', 'foo', '.', 'bar/baz' ]) +print open(str(file2), 'r').read() +file3 = FindFile('testfile2', [ 'foo', '.', 'bar', 'bar/baz' ]) +print open(str(file3), 'r').read() +file4 = FindFile('testfile2', [ 'bar/baz', 'foo', '.', 'bar' ]) +print open(str(file4), 'r').read() +""") + +expect = """test 1 + +test 3 + +test 2 + +test 4 + +""" + +test.run(stdout = expect) + +test.pass_test() + |