Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[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 test.write('SConstruct', """\
43 B = Builder(action = r"%s build.py $TARGET $SOURCES")
44 env = Environment(BUILDERS = { 'B' : B }, SUBDIR = 'subdir')
45 f1 = env.B(target = 'f1.out', source = 'f1.in')
46 env.B(target = 'f2.out', source = 'f2.in')
47 env.B(target = 'f3.out', source = 'f3.in')
48 env.B(target = 'subdir/f4.out', source = 'f4.in')
49 env.Precious(f1, 'f2.out', r'%s')
50 SConscript('subdir/SConscript', "env")
51 """ % (python,
52        os.path.join('$SUBDIR', 'f4.out')))
53
54 test.write(['subdir', 'SConscript'], """
55 Import("env")
56 env.B(target = 'f5.out', source = 'f5.in')
57 f6 = env.B(target = 'f6.out', source = 'f6.in')
58 env.B(target = 'f7.out', source = 'f7.in')
59 Precious(['f5.out', f6])
60 """)
61
62 test.write('f1.in', "f1.in\n")
63 test.write('f2.in', "f2.in\n")
64 test.write('f3.in', "f3.in\n")
65 test.write('f4.in', "f4.in\n")
66
67 test.write(['subdir', 'f5.in'], "subdir/f5.in\n")
68 test.write(['subdir', 'f6.in'], "subdir/f6.in\n")
69 test.write(['subdir', 'f7.in'], "subdir/f7.in\n")
70
71 test.write('f1.out', "SHOULD NOT BE REMOVED\n")
72 test.write('f2.out', "SHOULD NOT BE REMOVED\n")
73 test.write('f3.out', "SHOULD BE REMOVED\n")
74 test.write(['subdir', 'f4.out'], "SHOULD NOT BE REMOVED\n")
75
76 test.write(['subdir', 'f5.out'], "SHOULD NOT BE REMOVED\n")
77 test.write(['subdir', 'f6.out'], "SHOULD NOT BE REMOVED\n")
78 test.write(['subdir', 'f7.out'], "SHOULD BE REMOVED\n")
79
80 test.run(arguments = '.')
81
82 test.fail_test(not os.path.exists(test.workpath('f1.out')))
83 test.fail_test(not os.path.exists(test.workpath('f2.out')))
84 test.fail_test(os.path.exists(test.workpath('f3.out')))
85 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
86
87 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
88 test.fail_test(not os.path.exists(test.workpath('subdir', 'f6.out')))
89 test.fail_test(os.path.exists(test.workpath('subdir', 'f7.out')))
90
91 test.write('f3.out', "SHOULD BE REMOVED\n")
92 test.write(['subdir', 'f7.out'], "SHOULD BE REMOVED\n")
93
94 test.run(arguments = '.')
95
96 test.fail_test(not os.path.exists(test.workpath('f1.out')))
97 test.fail_test(not os.path.exists(test.workpath('f2.out')))
98 test.fail_test(not os.path.exists(test.workpath('f3.out')))
99 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
100
101 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
102 test.fail_test(not os.path.exists(test.workpath('subdir', 'f6.out')))
103 test.fail_test(not os.path.exists(test.workpath('subdir', 'f7.out')))
104
105 test.write('f3.in', "f3.in 2\n")
106 test.write(['subdir', 'f7.in'], "subdir/f7.in 2\n")
107
108 test.run(arguments = '.')
109
110 test.fail_test(not os.path.exists(test.workpath('f1.out')))
111 test.fail_test(not os.path.exists(test.workpath('f2.out')))
112 test.fail_test(os.path.exists(test.workpath('f3.out')))
113 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
114
115 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
116 test.fail_test(not os.path.exists(test.workpath('subdir', 'f6.out')))
117 test.fail_test(os.path.exists(test.workpath('subdir', 'f7.out')))
118
119 test.pass_test()