Put the Copyright years in by script, not by hand.
[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
28 import sys
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 })
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.Precious(f1, 'f2.out')
49 SConscript('subdir/SConscript', "env")
50 """ % python)
51
52 test.write(['subdir', 'SConscript'], """
53 Import("env")
54 env.B(target = 'f4.out', source = 'f4.in')
55 f5 = env.B(target = 'f5.out', source = 'f5.in')
56 env.B(target = 'f6.out', source = 'f6.in')
57 env.Precious(['f4.out', f5])
58 """)
59
60 test.write('f1.in', "f1.in\n")
61 test.write('f2.in', "f2.in\n")
62 test.write('f3.in', "f3.in\n")
63
64 test.write(['subdir', 'f4.in'], "subdir/f4.in\n")
65 test.write(['subdir', 'f5.in'], "subdir/f5.in\n")
66 test.write(['subdir', 'f6.in'], "subdir/f6.in\n")
67
68 test.write('f1.out', "SHOULD NOT BE REMOVED\n")
69 test.write('f2.out', "SHOULD NOT BE REMOVED\n")
70 test.write('f3.out', "SHOULD BE REMOVED\n")
71
72 test.write(['subdir', 'f4.out'], "SHOULD NOT BE REMOVED\n")
73 test.write(['subdir', 'f5.out'], "SHOULD NOT BE REMOVED\n")
74 test.write(['subdir', 'f6.out'], "SHOULD BE REMOVED\n")
75
76 test.run(arguments = '.')
77
78 test.fail_test(not os.path.exists(test.workpath('f1.out')))
79 test.fail_test(not os.path.exists(test.workpath('f2.out')))
80 test.fail_test(os.path.exists(test.workpath('f3.out')))
81
82 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
83 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
84 test.fail_test(os.path.exists(test.workpath('subdir', 'f6.out')))
85
86 test.write('f3.out', "SHOULD BE REMOVED\n")
87 test.write(['subdir', 'f6.out'], "SHOULD BE REMOVED\n")
88
89 test.run(arguments = '.')
90
91 test.fail_test(not os.path.exists(test.workpath('f1.out')))
92 test.fail_test(not os.path.exists(test.workpath('f2.out')))
93 test.fail_test(not os.path.exists(test.workpath('f3.out')))
94
95 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
96 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
97 test.fail_test(not os.path.exists(test.workpath('subdir', 'f6.out')))
98
99 test.write('f3.in', "f3.in 2\n")
100 test.write(['subdir', 'f6.in'], "subdir/f6.in 2\n")
101
102 test.run(arguments = '.')
103
104 test.fail_test(not os.path.exists(test.workpath('f1.out')))
105 test.fail_test(not os.path.exists(test.workpath('f2.out')))
106 test.fail_test(os.path.exists(test.workpath('f3.out')))
107
108 test.fail_test(not os.path.exists(test.workpath('subdir', 'f4.out')))
109 test.fail_test(not os.path.exists(test.workpath('subdir', 'f5.out')))
110 test.fail_test(os.path.exists(test.workpath('subdir', 'f6.out')))
111
112 test.pass_test()