Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[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 import string
29
30 import TestSCons
31
32 python = TestSCons.python
33
34 test = TestSCons.TestSCons()
35
36 test.subdir('subdir', 'sub2')
37
38 test.write('build.py', r"""
39 import sys
40 contents = open(sys.argv[2], 'rb').read() + open(sys.argv[3], 'rb').read()
41 file = open(sys.argv[1], 'wb')
42 file.write(contents)
43 file.close()
44 """)
45
46 test.write('SConstruct', """
47 Foo = Builder(action = r"%s build.py $TARGET $SOURCES subdir/foo.dep")
48 Bar = Builder(action = r"%s build.py $TARGET $SOURCES subdir/bar.dep")
49 env = Environment(BUILDERS = { 'Foo' : Foo, 'Bar' : Bar }, SUBDIR='subdir')
50 env.ParseDepends('foo.d')
51 env.ParseDepends('bar.d')
52 env.Foo(target = 'f1.out', source = 'f1.in')
53 env.Foo(target = 'f2.out', source = 'f2.in')
54 env.Bar(target = 'subdir/f3.out', source = 'f3.in')
55 SConscript('subdir/SConscript', "env")
56 env.Foo(target = 'f5.out', source = 'f5.in')
57 env.Bar(target = 'sub2/f6.out', source = 'f6.in')
58 """ % (python, python))
59
60 test.write('foo.d', "f1.out f2.out: %s\n" % os.path.join('subdir', 'foo.dep'))
61 test.write('bar.d', "%s: %s\nf5.out: sub2" % (os.path.join('subdir', 'f3.out'),
62                                   os.path.join('subdir', 'bar.dep')))
63
64 test.write(['subdir', 'SConscript'], """
65 Import("env")
66 ParseDepends('bar.d')
67 env.Bar(target = 'f4.out', source = 'f4.in')
68 """)
69
70 test.write(['subdir', 'bar.d'], "f4.out: bar.dep\n")
71
72 test.write('f1.in', "f1.in\n")
73 test.write('f2.in', "f2.in\n")
74 test.write('f3.in', "f3.in\n")
75 test.write(['subdir', 'f4.in'], "subdir/f4.in\n")
76 test.write('f5.in', "f5.in\n")
77 test.write('f6.in', "f6.in\n")
78
79 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 1\n")
80 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 1\n")
81
82 test.run(arguments = '.')
83
84 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 1\n")
85 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 1\n")
86 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 1\n")
87 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 1\n")
88 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 1\n")
89 test.must_match(['sub2', 'f6.out'], "f6.in\nsubdir/bar.dep 1\n")
90
91 #
92 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 2\n")
93 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 2\n")
94 test.write('f6.in', "f6.in 2\n")
95
96 test.run(arguments = '.')
97
98 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 2\n")
99 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 2\n")
100 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 2\n")
101 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 2\n")
102 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
103 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
104
105 #
106 test.write(['subdir', 'foo.dep'], "subdir/foo.dep 3\n")
107
108 test.run(arguments = '.')
109
110 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
111 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
112 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 2\n")
113 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 2\n")
114 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
115 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
116
117 #
118 test.write(['subdir', 'bar.dep'], "subdir/bar.dep 3\n")
119
120 test.run(arguments = '.')
121
122 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
123 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
124 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 3\n")
125 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 3\n")
126 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 2\n")
127 test.must_match(['sub2', 'f6.out'], "f6.in 2\nsubdir/bar.dep 2\n")
128
129 #
130 test.write('f6.in', "f6.in 3\n")
131
132 test.run(arguments = '.')
133
134 test.must_match('f1.out', "f1.in\nsubdir/foo.dep 3\n")
135 test.must_match('f2.out', "f2.in\nsubdir/foo.dep 3\n")
136 test.must_match(['subdir', 'f3.out'], "f3.in\nsubdir/bar.dep 3\n")
137 test.must_match(['subdir', 'f4.out'], "subdir/f4.in\nsubdir/bar.dep 3\n")
138 test.must_match('f5.out', "f5.in\nsubdir/foo.dep 3\n")
139 test.must_match(['sub2', 'f6.out'], "f6.in 3\nsubdir/bar.dep 3\n")
140
141
142
143 test.write('SConstruct', """
144 ParseDepends('nonexistent_file')
145 """)
146
147 test.run()
148
149 test.write('SConstruct', """
150 ParseDepends('nonexistent_file', must_exist=1)
151 """)
152
153 test.run(status=2, stderr=None)
154
155 test.fail_test(string.find(test.stderr(), "No such file or directory") == -1)
156
157 test.pass_test()