Merged revisions 2527-2645 via svnmerge from
[scons.git] / test / Copy.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 Delete() Action works.
29 """
30
31 import os.path
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 test.write('SConstruct', """
38 Execute(Copy('f1.out', 'f1.in'))
39 Execute(Copy(File('d2.out'), 'd2.in'))
40 Execute(Copy('d3.out', File('f3.in')))
41 def cat(env, source, target):
42     target = str(target[0])
43     source = map(str, source)
44     f = open(target, "wb")
45     for src in source:
46         f.write(open(src, "rb").read())
47     f.close()
48 Cat = Action(cat)
49 env = Environment()
50 env.Command('bar.out', 'bar.in', [Cat,
51                                   Copy("f4.out", "f4.in"),
52                                   Copy("d5.out", "d5.in"),
53                                   Copy("d6.out", "f6.in")])
54 env = Environment(OUTPUT = 'f7.out', INPUT = 'f7.in')
55 env.Command('f8.out', 'f8.in', [Copy('$OUTPUT', '$INPUT'), Cat])
56 env.Command('f9.out', 'f9.in', [Cat, Copy('${TARGET}-Copy', '$SOURCE')])
57
58 env.CopyTo( 'd4', 'f10.in' )
59 env.CopyAs( 'd4/f11.out', 'f11.in')
60 env.CopyAs( 'd4/f12.out', 'd5/f12.in')
61 """)
62
63 test.write('f1.in', "f1.in\n")
64 test.subdir('d2.in')
65 test.write(['d2.in', 'file'], "d2.in/file\n")
66 test.write('f3.in', "f3.in\n")
67 test.subdir('d3.out')
68 test.write('bar.in', "bar.in\n")
69 test.write('f4.in', "f4.in\n")
70 test.subdir('d5.in')
71 test.write(['d5.in', 'file'], "d5.in/file\n")
72 test.write('f6.in', "f6.in\n")
73 test.subdir('d6.out')
74 test.write('f7.in', "f7.in\n")
75 test.write('f8.in', "f8.in\n")
76 test.write('f9.in', "f9.in\n")
77 test.write('f10.in', "f10.in\n")
78 test.write('f11.in', "f11.in\n")
79 test.subdir('d5')
80 test.write(['d5', 'f12.in'], "f12.in\n")
81
82 d4_f10_in   = os.path.join('d4', 'f10.in')
83 d4_f11_out  = os.path.join('d4', 'f11.out')
84 d4_f12_out  = os.path.join('d4', 'f12.out')
85 d5_f12_in   = os.path.join('d5', 'f12.in')
86
87 expect = test.wrap_stdout(read_str = """\
88 Copy("f1.out", "f1.in")
89 Copy("d2.out", "d2.in")
90 Copy("d3.out", "f3.in")
91 """,
92                           build_str = """\
93 cat(["bar.out"], ["bar.in"])
94 Copy("f4.out", "f4.in")
95 Copy("d5.out", "d5.in")
96 Copy("d6.out", "f6.in")
97 Copy file(s): "f10.in" to "%(d4_f10_in)s"
98 Copy file(s): "f11.in" to "%(d4_f11_out)s"
99 Copy file(s): "%(d5_f12_in)s" to "%(d4_f12_out)s"
100 Copy("f7.out", "f7.in")
101 cat(["f8.out"], ["f8.in"])
102 cat(["f9.out"], ["f9.in"])
103 Copy("f9.out-Copy", "f9.in")
104 """ % locals())
105 test.run(options = '-n', arguments = '.', stdout = expect)
106
107 test.must_not_exist('f1.out')
108 test.must_not_exist('d2.out')
109 test.must_not_exist(os.path.join('d3.out', 'f3.in'))
110 test.must_not_exist('f4.out')
111 test.must_not_exist('d5.out')
112 test.must_not_exist(os.path.join('d6.out', 'f6.in'))
113 test.must_not_exist('f7.out')
114 test.must_not_exist('f8.out')
115 test.must_not_exist('f9.out')
116 test.must_not_exist('f9.out-Copy')
117 test.must_not_exist('d4/f10.in')
118 test.must_not_exist('d4/f11.out')
119 test.must_not_exist('d4/f12.out')
120
121 test.run()
122
123 test.must_match('f1.out', "f1.in\n")
124 test.must_match(['d2.out', 'file'], "d2.in/file\n")
125 test.must_match(['d3.out', 'f3.in'], "f3.in\n")
126 test.must_match('f4.out', "f4.in\n")
127 test.must_match(['d5.out', 'file'], "d5.in/file\n")
128 test.must_match(['d6.out', 'f6.in'], "f6.in\n")
129 test.must_match('f7.out', "f7.in\n")
130 test.must_match('f8.out', "f8.in\n")
131 test.must_match('f9.out', "f9.in\n")
132 test.must_match('f9.out-Copy', "f9.in\n")
133 test.must_match('d4/f10.in', 'f10.in\n')
134 test.must_match('d4/f11.out', 'f11.in\n')
135 test.must_match('d4/f12.out', 'f12.in\n')
136
137 test.pass_test()