Updates and slight refactor in fix
[scons.git] / test / Touch.py
blob3538c7d338bdf7b9e80395ce6f0f8de36de5e44a
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Verify that the Touch() Action works.
28 """
30 import os.path
32 import TestSCons
34 test = TestSCons.TestSCons()
36 test.write('SConstruct', """\
37 Execute(Touch('f1'))
38 Execute(Touch(File('f1-File')))
40 def cat(env, source, target):
41 target = str(target[0])
42 with open(target, "wb") as f:
43 for src in source:
44 with open(str(src), "rb") as ifp:
45 f.write(ifp.read())
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, Touch("Touch-$SOURCE"), Touch("$TARGET-Touch")])
54 # Make sure Touch works with a list of arguments
55 env = Environment()
56 env.Command(
57 'f7.out', 'f7.in', [Cat, Touch(["Touch-$SOURCE", "$TARGET-Touch", File("f8")])]
59 """)
61 test.write('f1', "f1\n")
62 test.write('f1-File', "f1-File\n")
63 test.write('f2.in', "f2.in\n")
64 test.write('f5.in', "f5.in\n")
65 test.write('f6.in', "f6.in\n")
66 test.write('f7.in', "f7.in\n")
68 old_f1_time = os.path.getmtime(test.workpath('f1'))
69 old_f1_File_time = os.path.getmtime(test.workpath('f1-File'))
71 expect = test.wrap_stdout(
72 read_str="""\
73 Touch("f1")
74 Touch("f1-File")
75 """,
76 build_str="""\
77 cat(["f2.out"], ["f2.in"])
78 Touch("f3")
79 Touch("f4")
80 cat(["f5.out"], ["f5.in"])
81 cat(["f6.out"], ["f6.in"])
82 Touch("Touch-f6.in")
83 Touch("f6.out-Touch")
84 cat(["f7.out"], ["f7.in"])
85 Touch(["Touch-f7.in", "f7.out-Touch", "f8"])
86 """,
88 test.run(options='-n', arguments='.', stdout=expect)
90 test.sleep() # delay for timestamps
91 new_f1_time = os.path.getmtime(test.workpath('f1'))
92 test.fail_test(old_f1_time != new_f1_time)
93 new_f1_File_time = os.path.getmtime(test.workpath('f1-File'))
94 test.fail_test(old_f1_File_time != new_f1_File_time)
96 test.must_not_exist(test.workpath('f2.out'))
97 test.must_not_exist(test.workpath('f3'))
98 test.must_not_exist(test.workpath('f4'))
99 test.must_not_exist(test.workpath('f5.out'))
100 test.must_not_exist(test.workpath('f6.out'))
101 test.must_not_exist(test.workpath('Touch-f6.in'))
102 test.must_not_exist(test.workpath('f6.out-Touch'))
103 test.must_not_exist(test.workpath('f7.out'))
104 test.must_not_exist(test.workpath('Touch-f7.in'))
105 test.must_not_exist(test.workpath('f7.out-Touch'))
106 test.must_not_exist(test.workpath('f8'))
108 test.run()
110 new_f1_time = os.path.getmtime(test.workpath('f1'))
111 test.fail_test(old_f1_time == new_f1_time)
112 new_f1_File_time = os.path.getmtime(test.workpath('f1-File'))
113 test.fail_test(old_f1_File_time == new_f1_File_time)
115 test.must_match('f2.out', "f2.in\n")
116 test.must_exist(test.workpath('f3'))
117 test.must_exist(test.workpath('f4'))
118 test.must_match('f5.out', "f5.in\n")
119 test.must_match('f6.out', "f6.in\n")
120 test.must_exist(test.workpath('Touch-f6.in'))
121 test.must_exist(test.workpath('f6.out-Touch'))
122 test.must_match('f7.out', "f7.in\n")
123 test.must_exist(test.workpath('Touch-f7.in'))
124 test.must_exist(test.workpath('f7.out-Touch'))
125 test.must_exist(test.workpath('f8'))
127 test.pass_test()
129 # Local Variables:
130 # tab-width:4
131 # indent-tabs-mode:nil
132 # End:
133 # vim: set expandtab tabstop=4 shiftwidth=4: