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