Ant-like tasks: Chmod(), Copy(), Delete(), Mkdir(), Move(), Touch().
[scons.git] / test / Touch.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 that the Touch() Action works.
29 """
30
31 import os.path
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 test.write('SConstruct', """
38 Execute(Touch('f1'))
39 def cat(env, source, target):
40     target = str(target[0])
41     source = map(str, source)
42     f = open(target, "wb")
43     for src in source:
44         f.write(open(src, "rb").read())
45     f.close()
46 Cat = Action(cat)
47 env = Environment()
48 env.Command('f2.out', 'f2.in', [Cat, Touch("f3")])
49 env = Environment(FILE='f4')
50 env.Command('f5.out', 'f5.in', [Touch("$FILE"), Cat])
51 env.Command('f6.out', 'f6.in', [Cat,
52                                 Touch("Touch-$SOURCE"),
53                                 Touch("$TARGET-Touch")])
54 """)
55
56 test.write('f1', "f1\n")
57 test.write('f2.in', "f2.in\n")
58 test.write('f5.in', "f5.in\n")
59 test.write('f6.in', "f6.in\n")
60
61 oldtime = os.path.getmtime(test.workpath('f1'))
62
63 expect = test.wrap_stdout(read_str = 'Touch("f1")\n',
64                           build_str = """\
65 cat("f2.out", "f2.in")
66 Touch("f3")
67 Touch("f4")
68 cat("f5.out", "f5.in")
69 cat("f6.out", "f6.in")
70 Touch("Touch-f6.in")
71 Touch("f6.out-Touch")
72 """)
73 test.run(options = '-n', arguments = '.', stdout = expect)
74
75 test.sleep(2)
76
77 newtime = os.path.getmtime(test.workpath('f1'))
78 test.fail_test(oldtime != newtime)
79
80 test.must_not_exist(test.workpath('f2.out'))
81 test.must_not_exist(test.workpath('f3'))
82 test.must_not_exist(test.workpath('f4'))
83 test.must_not_exist(test.workpath('f5.out'))
84 test.must_not_exist(test.workpath('f6.out'))
85 test.must_not_exist(test.workpath('Touch-f6.in'))
86 test.must_not_exist(test.workpath('f6.out-Touch'))
87
88 test.run()
89
90 newtime = os.path.getmtime(test.workpath('f1'))
91 test.fail_test(oldtime == newtime)
92
93 test.must_match('f2.out', "f2.in\n")
94 test.must_exist(test.workpath('f3'))
95 test.must_exist(test.workpath('f4'))
96 test.must_match('f5.out', "f5.in\n")
97 test.must_match('f6.out', "f6.in\n")
98 test.must_exist(test.workpath('Touch-f6.in'))
99 test.must_exist(test.workpath('f6.out-Touch'))
100
101 test.pass_test()