Forward port benchmark for type checking
[scons.git] / test / Depends / Depends.py
blob3ed9e121c424e5a03e86e71ce88f8285b9ba4fb2
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verifies basic execution of the Depends() function.
29 """
31 import os.path
33 import TestSCons
35 _python_ = TestSCons._python_
37 test = TestSCons.TestSCons()
39 test.subdir('subdir', 'sub2')
41 test.write('build.py', r"""
42 import sys
43 with open(sys.argv[1], 'wb') as ofp:
44 for fname in sys.argv[2:]:
45 with open(fname, 'rb') as ifp:
46 ofp.write(ifp.read())
47 sys.exit(0)
48 """)
50 SUBDIR_foo_dep = os.path.join('$SUBDIR', 'foo.dep')
51 SUBDIR_f3_out = os.path.join('$SUBDIR', 'f3.out')
53 test.write('SConstruct', """
54 DefaultEnvironment(tools=[])
55 Foo = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES subdir/foo.dep')
56 Bar = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES subdir/bar.dep')
57 env = Environment(tools=[], BUILDERS = { 'Foo' : Foo, 'Bar' : Bar }, SUBDIR='subdir')
58 env.Depends(target = ['f1.out', 'f2.out'], dependency = r'%(SUBDIR_foo_dep)s')
59 env.Depends(target = r'%(SUBDIR_f3_out)s', dependency = 'subdir/bar.dep')
60 env.Foo(target = 'f1.out', source = 'f1.in')
61 env.Foo(target = 'f2.out', source = 'f2.in')
62 env.Bar(target = 'subdir/f3.out', source = 'f3.in')
63 SConscript('subdir/SConscript', "env")
64 env.Foo(target = 'f5.out', source = 'f5.in')
65 env.Bar(target = 'sub2/f6.out', source = 'f6.in')
66 env.Depends(target = 'f5.out', dependency = 'sub2')
67 """ % locals())
69 test.write(['subdir', 'SConscript'], """
70 Import("env")
71 Depends(target = 'f4.out', dependency = 'bar.dep')
72 env.Bar(target = 'f4.out', source = 'f4.in')
73 """)
75 test.write('f1.in', "f1.in\n")
76 test.write('f2.in', "f2.in\n")
77 test.write('f3.in', "f3.in\n")
78 test.write(['subdir', 'f4.in'], "subdir/f4.in\n")
79 test.write('f5.in', "f5.in\n")
80 test.write('f6.in', "f6.in\n")
82 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 1\n")
83 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 1\n")
85 test.run(arguments = '.')
87 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 1\n")
88 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 1\n")
89 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 1\n")
90 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 1\n")
91 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 1\n")
92 test.must_match(['sub2', 'f6.out'], "f6.in\nsubdir/bar.dep 1\n")
95 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 2\n")
96 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 2\n")
97 test.write('f6.in', "f6.in 2\n")
99 test.run(arguments = '.')
101 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 2\n")
102 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 2\n")
103 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 2\n")
104 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 2\n")
105 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
106 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
109 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 3\n")
111 test.run(arguments = '.')
113 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
114 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
115 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 2\n")
116 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 2\n")
117 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
118 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
121 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 3\n")
123 test.run(arguments = '.')
125 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
126 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
127 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 3\n")
128 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 3\n")
129 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
130 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
133 test.write('f6.in', "f6.in 3\n")
135 test.run(arguments = '.')
137 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
138 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
139 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 3\n")
140 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 3\n")
141 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 3\n")
142 test.must_match(['sub2', 'f6.out'], "f6.in 3\nsubdir/bar.dep 3\n")
145 test.pass_test()
147 # Local Variables:
148 # tab-width:4
149 # indent-tabs-mode:nil
150 # End:
151 # vim: set expandtab tabstop=4 shiftwidth=4: