Update regression tests to match changes in runtest.py
[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 Execute(Touch(File('f1-File')))
40 def cat(env, source, target):
41     target = str(target[0])
42     source = map(str, source)
43     f = open(target, "wb")
44     for src in source:
45         f.write(open(src, "rb").read())
46     f.close()
47 Cat = Action(cat)
48 env = Environment()
49 env.Command('f2.out', 'f2.in', [Cat, Touch("f3")])
50 env = Environment(FILE='f4')
51 env.Command('f5.out', 'f5.in', [Touch("$FILE"), Cat])
52 env.Command('f6.out', 'f6.in', [Cat,
53                                 Touch("Touch-$SOURCE"),
54                                 Touch("$TARGET-Touch")])
55
56 # Make sure Touch works with a list of arguments
57 env = Environment()
58 env.Command('f7.out', 'f7.in', [Cat,
59                                 Touch(["Touch-$SOURCE",
60                                        "$TARGET-Touch",
61                                        File("f8")])])
62 """)
63
64 test.write('f1', "f1\n")
65 test.write('f1-File', "f1-File\n")
66 test.write('f2.in', "f2.in\n")
67 test.write('f5.in', "f5.in\n")
68 test.write('f6.in', "f6.in\n")
69 test.write('f7.in', "f7.in\n")
70
71 old_f1_time = os.path.getmtime(test.workpath('f1'))
72 old_f1_File_time = os.path.getmtime(test.workpath('f1-File'))
73
74 expect = test.wrap_stdout(read_str = """\
75 Touch("f1")
76 Touch("f1-File")
77 """,
78                           build_str = """\
79 cat(["f2.out"], ["f2.in"])
80 Touch("f3")
81 Touch("f4")
82 cat(["f5.out"], ["f5.in"])
83 cat(["f6.out"], ["f6.in"])
84 Touch("Touch-f6.in")
85 Touch("f6.out-Touch")
86 cat(["f7.out"], ["f7.in"])
87 Touch(["Touch-f7.in", "f7.out-Touch", "f8"])
88 """)
89 test.run(options = '-n', arguments = '.', stdout = expect)
90
91 test.sleep(2)
92
93 new_f1_time = os.path.getmtime(test.workpath('f1'))
94 test.fail_test(old_f1_time != new_f1_time)
95 new_f1_File_time = os.path.getmtime(test.workpath('f1-File'))
96 test.fail_test(old_f1_File_time != new_f1_File_time)
97
98 test.must_not_exist(test.workpath('f2.out'))
99 test.must_not_exist(test.workpath('f3'))
100 test.must_not_exist(test.workpath('f4'))
101 test.must_not_exist(test.workpath('f5.out'))
102 test.must_not_exist(test.workpath('f6.out'))
103 test.must_not_exist(test.workpath('Touch-f6.in'))
104 test.must_not_exist(test.workpath('f6.out-Touch'))
105 test.must_not_exist(test.workpath('f7.out'))
106 test.must_not_exist(test.workpath('Touch-f7.in'))
107 test.must_not_exist(test.workpath('f7.out-Touch'))
108 test.must_not_exist(test.workpath('f8'))
109
110 test.run()
111
112 new_f1_time = os.path.getmtime(test.workpath('f1'))
113 test.fail_test(old_f1_time == new_f1_time)
114 new_f1_File_time = os.path.getmtime(test.workpath('f1-File'))
115 test.fail_test(old_f1_File_time == new_f1_File_time)
116
117 test.must_match('f2.out', "f2.in\n")
118 test.must_exist(test.workpath('f3'))
119 test.must_exist(test.workpath('f4'))
120 test.must_match('f5.out', "f5.in\n")
121 test.must_match('f6.out', "f6.in\n")
122 test.must_exist(test.workpath('Touch-f6.in'))
123 test.must_exist(test.workpath('f6.out-Touch'))
124 test.must_match('f7.out', "f7.in\n")
125 test.must_exist(test.workpath('Touch-f7.in'))
126 test.must_exist(test.workpath('f7.out-Touch'))
127 test.must_exist(test.workpath('f8'))
128
129 test.pass_test()
130
131 # Local Variables:
132 # tab-width:4
133 # indent-tabs-mode:nil
134 # End:
135 # vim: set expandtab tabstop=4 shiftwidth=4: