Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Precious.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')
36
37 test.write('build.py', r"""
38 import sys
39 sys.exit(0)
40 """)
41
42 SUBDIR_f4_out = os.path.join('$SUBDIR', 'f4.out')
43
44 test.write('SConstruct', """\
45 B = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES')
46 env = Environment(BUILDERS = { 'B' : B }, SUBDIR = 'subdir')
47 f1 = env.B(target = 'f1.out', source = 'f1.in')
48 env.B(target = 'f2.out', source = 'f2.in')
49 env.B(target = 'f3.out', source = 'f3.in')
50 env.B(target = 'subdir/f4.out', source = 'f4.in')
51 env.Precious(f1, 'f2.out', r'%(SUBDIR_f4_out)s')
52 SConscript('subdir/SConscript', "env")
53 """ % locals())
54
55 test.write(['subdir', 'SConscript'], """
56 Import("env")
57 env.B(target = 'f5.out', source = 'f5.in')
58 f6 = env.B(target = 'f6.out', source = 'f6.in')
59 env.B(target = 'f7.out', source = 'f7.in')
60 Precious(['f5.out', f6])
61 """)
62
63 test.write('f1.in', "f1.in\n")
64 test.write('f2.in', "f2.in\n")
65 test.write('f3.in', "f3.in\n")
66 test.write('f4.in', "f4.in\n")
67
68 test.write(['subdir', 'f5.in'], "subdir/f5.in\n")
69 test.write(['subdir', 'f6.in'], "subdir/f6.in\n")
70 test.write(['subdir', 'f7.in'], "subdir/f7.in\n")
71
72 test.write('f1.out', "SHOULD NOT BE REMOVED\n")
73 test.write('f2.out', "SHOULD NOT BE REMOVED\n")
74 test.write('f3.out', "SHOULD BE REMOVED\n")
75 test.write(['subdir', 'f4.out'], "SHOULD NOT BE REMOVED\n")
76
77 test.write(['subdir', 'f5.out'], "SHOULD NOT BE REMOVED\n")
78 test.write(['subdir', 'f6.out'], "SHOULD NOT BE REMOVED\n")
79 test.write(['subdir', 'f7.out'], "SHOULD BE REMOVED\n")
80
81 test.run(arguments = '.')
82
83 test.fail_test(not os.path.exists(test.workpath('f1.out')))
84 test.fail_test(not os.path.exists(test.workpath('f2.out')))
85 test.fail_test(os.path.exists(test.workpath('f3.out')))
86 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
87
88 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
89 test.fail_test(not os.path.exists(test.workpath('subdir', 'f6.out')))
90 test.fail_test(os.path.exists(test.workpath('subdir', 'f7.out')))
91
92 test.write('f3.out', "SHOULD BE REMOVED\n")
93 test.write(['subdir', 'f7.out'], "SHOULD BE REMOVED\n")
94
95 test.run(arguments = '.')
96
97 test.fail_test(not os.path.exists(test.workpath('f1.out')))
98 test.fail_test(not os.path.exists(test.workpath('f2.out')))
99 test.fail_test(not os.path.exists(test.workpath('f3.out')))
100 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
101
102 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
103 test.fail_test(not os.path.exists(test.workpath('subdir', 'f6.out')))
104 test.fail_test(not os.path.exists(test.workpath('subdir', 'f7.out')))
105
106 test.write('f3.in', "f3.in 2\n")
107 test.write(['subdir', 'f7.in'], "subdir/f7.in 2\n")
108
109 test.run(arguments = '.')
110
111 test.fail_test(not os.path.exists(test.workpath('f1.out')))
112 test.fail_test(not os.path.exists(test.workpath('f2.out')))
113 test.fail_test(os.path.exists(test.workpath('f3.out')))
114 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
115
116 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
117 test.fail_test(not os.path.exists(test.workpath('subdir', 'f6.out')))
118 test.fail_test(os.path.exists(test.workpath('subdir', 'f7.out')))
119
120 test.pass_test()
121
122 # Local Variables:
123 # tab-width:4
124 # indent-tabs-mode:nil
125 # End:
126 # vim: set expandtab tabstop=4 shiftwidth=4: