Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Clean / function.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 """
28 Verify use of the Clean() function.
29 """
30
31 import os
32
33 import TestSCons
34
35 _python_ = TestSCons._python_
36
37 test = TestSCons.TestSCons()
38
39 test.write('build.py', r"""
40 import sys
41 contents = open(sys.argv[2], 'rb').read()
42 file = open(sys.argv[1], 'wb')
43 file.write(contents)
44 file.close()
45 """)
46
47 test.subdir('subd')
48
49 subd_SConscript = os.path.join('subd', 'SConscript')
50 subd_foon_in = os.path.join('subd', 'foon.in')
51 subd_foox_in = os.path.join('subd', 'foox.in')
52
53 test.write('SConstruct', """
54 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
55 env = Environment(BUILDERS = { 'B' : B }, FOO = 'foo2')
56 env.B(target = 'foo1.out', source = 'foo1.in')
57 env.B(target = 'foo2.out', source = 'foo2.xxx')
58 foo2_xxx = env.B(target = 'foo2.xxx', source = 'foo2.in')
59 env.B(target = 'foo3.out', source = 'foo3.in')
60 SConscript('subd/SConscript')
61 Clean(foo2_xxx, ['aux1.x'])
62 env.Clean(['${FOO}.xxx'], ['aux2.x'])
63 Clean('.', ['subd'])
64 """ % locals())
65
66 test.write(['subd', 'SConscript'], """
67 Clean('.', 'foox.in')
68 """)
69
70 test.write('foo1.in', "foo1.in\n")
71 test.write('foo2.in', "foo2.in\n")
72 test.write('foo3.in', "foo3.in\n")
73 test.write(['subd', 'foon.in'], "foon.in\n")
74 test.write(['subd', 'foox.in'], "foox.in\n")
75 test.write('aux1.x', "aux1.x\n")
76 test.write('aux2.x', "aux2.x\n")
77
78 test.run()
79
80 expect = test.wrap_stdout("""Removed foo2.xxx
81 Removed aux1.x
82 Removed aux2.x
83 """, cleaning=1)
84 test.run(arguments = '-c foo2.xxx', stdout=expect)
85 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
86 test.must_not_exist(test.workpath('foo2.xxx'))
87 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
88 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
89
90 expect = test.wrap_stdout("Removed %s\n" % subd_foox_in, cleaning = 1)
91 test.run(arguments = '-c subd', stdout=expect)
92 test.must_not_exist(test.workpath('foox.in'))
93
94 expect = test.wrap_stdout("""Removed foo1.out
95 Removed foo2.xxx
96 Removed foo2.out
97 Removed foo3.out
98 Removed %(subd_SConscript)s
99 Removed %(subd_foon_in)s
100 Removed directory subd
101 """ % locals(), cleaning = 1)
102 test.run(arguments = '-c -n .', stdout=expect)
103
104 expect = test.wrap_stdout("""Removed foo1.out
105 Removed foo2.out
106 Removed foo3.out
107 Removed %(subd_SConscript)s
108 Removed %(subd_foon_in)s
109 Removed directory subd
110 """ % locals(), cleaning = 1)
111 test.run(arguments = '-c .', stdout=expect)
112 test.must_not_exist(test.workpath('subdir', 'foon.in'))
113 test.must_not_exist(test.workpath('subdir'))
114
115 test.pass_test()
116
117 # Local Variables:
118 # tab-width:4
119 # indent-tabs-mode:nil
120 # End:
121 # vim: set expandtab tabstop=4 shiftwidth=4: