Fix the test on all Python versions (failed on versions before 2.5 due
[scons.git] / test / ParseDepends.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import os.path
28
29 import TestSCons
30
31 _python_ = TestSCons._python_
32
33 test = TestSCons.TestSCons()
34
35 test.subdir('subdir', 'sub2')
36
37 test.write('build.py', r"""
38 import sys
39 contents = open(sys.argv[2], 'rb').read() + open(sys.argv[3], 'rb').read()
40 file = open(sys.argv[1], 'wb')
41 file.write(contents)
42 file.close()
43 """)
44
45 test.write('SConstruct', """
46 Foo = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES subdir/foo.dep')
47 Bar = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES subdir/bar.dep')
48 env = Environment(BUILDERS = { 'Foo' : Foo, 'Bar' : Bar }, SUBDIR='subdir')
49 env.ParseDepends('foo.d')
50 env.ParseDepends('bar.d')
51 env.Foo(target = 'f1.out', source = 'f1.in')
52 env.Foo(target = 'f2.out', source = 'f2.in')
53 env.Bar(target = 'subdir/f3.out', source = 'f3.in')
54 SConscript('subdir/SConscript', "env")
55 env.Foo(target = 'f5.out', source = 'f5.in')
56 env.Bar(target = 'sub2/f6.out', source = 'f6.in')
57 """ % locals())
58
59 test.write('foo.d', "f1.out f2.out: %s\n" % os.path.join('subdir', 'foo.dep'))
60 test.write('bar.d', "%s: %s\nf5.out: sub2" % (os.path.join('subdir', 'f3.out'),
61                                   os.path.join('subdir', 'bar.dep')))
62
63 test.write(['subdir', 'SConscript'], """
64 Import("env")
65 ParseDepends('bar.d')
66 env.Bar(target = 'f4.out', source = 'f4.in')
67 """)
68
69 test.write(['subdir', 'bar.d'], "f4.out: bar.dep\n")
70
71 test.write('f1.in', "f1.in\n")
72 test.write('f2.in', "f2.in\n")
73 test.write('f3.in', "f3.in\n")
74 test.write(['subdir', 'f4.in'], "subdir/f4.in\n")
75 test.write('f5.in', "f5.in\n")
76 test.write('f6.in', "f6.in\n")
77
78 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 1\n")
79 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 1\n")
80
81 test.run(arguments = '.')
82
83 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 1\n")
84 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 1\n")
85 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 1\n")
86 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 1\n")
87 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 1\n")
88 test.must_match(['sub2', 'f6.out'], "f6.in\nsubdir/bar.dep 1\n")
89
90 #
91 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 2\n")
92 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 2\n")
93 test.write('f6.in', "f6.in 2\n")
94
95 test.run(arguments = '.')
96
97 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 2\n")
98 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 2\n")
99 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 2\n")
100 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 2\n")
101 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
102 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
103
104 #
105 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 3\n")
106
107 test.run(arguments = '.')
108
109 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
110 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
111 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 2\n")
112 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 2\n")
113 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
114 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
115
116 #
117 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 3\n")
118
119 test.run(arguments = '.')
120
121 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
122 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
123 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 3\n")
124 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 3\n")
125 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
126 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
127
128 #
129 test.write('f6.in', "f6.in 3\n")
130
131 test.run(arguments = '.')
132
133 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
134 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
135 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 3\n")
136 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 3\n")
137 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 3\n")
138 test.must_match(['sub2', 'f6.out'], "f6.in 3\nsubdir/bar.dep 3\n")
139
140
141
142 test.write('SConstruct', """
143 ParseDepends('nonexistent_file')
144 """)
145
146 test.run()
147
148 test.write('SConstruct', """
149 ParseDepends('nonexistent_file', must_exist=1)
150 """)
151
152 test.run(status=2, stderr=None)
153
154 test.must_contain_all_lines(test.stderr(), ["No such file or directory"])
155
156 test.pass_test()
157
158 # Local Variables:
159 # tab-width:4
160 # indent-tabs-mode:nil
161 # End:
162 # vim: set expandtab tabstop=4 shiftwidth=4: