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.
30 _python_
= TestSCons
._python
_
32 test
= TestSCons
.TestSCons()
36 test
.write('mytar.py', r
"""
41 opts, args = getopt.getopt(sys.argv[1:], 'cf:')
43 if opt == '-f': out = arg
45 def process(outfile, name):
46 if os.path.isdir(name):
47 for entry in sorted(os.listdir(name)):
48 process(outfile, os.path.join(name, entry))
50 with open(name, 'r') as ifp:
51 outfile.write(ifp.read())
53 with open(out, 'w') as ofp:
59 test
.write('SConstruct', """
60 DefaultEnvironment(tools=[]) # test speedup
61 env = Environment(tools = ['tar'], TAR = r'%(_python_)s mytar.py')
62 env.Tar(target = 'aaa.tar', source = ['file1', 'file2'])
63 env.Tar(target = 'aaa.tar', source = 'file3')
64 env.Tar(target = 'bbb', source = 'sub1')
65 env.Tar(target = 'bbb', source = 'file4')
68 test
.write('file1', "file1\n")
69 test
.write('file2', "file2\n")
70 test
.write('file3', "file3\n")
71 test
.write('file4', "file4\n")
73 test
.write(['sub1', 'file5'], "sub1/file5\n")
74 test
.write(['sub1', 'file6'], "sub1/file6\n")
76 test
.run(arguments
= 'aaa.tar', stderr
= None)
78 test
.must_match('aaa.tar', "file1\nfile2\nfile3\n", mode
='r')
80 test
.run(arguments
= 'bbb.tar', stderr
= None)
82 test
.must_match('bbb.tar', "sub1/file5\nsub1/file6\nfile4\n", mode
='r')
85 tar
= test
.detect('TAR', 'tar')
89 test
.file_fixture('wrapper.py')
91 test
.write('SConstruct', """
92 DefaultEnvironment(tools=[]) # test speedup
94 tar = foo.Dictionary('TAR')
95 bar = Environment(TAR = r'%(_python_)s wrapper.py ' + tar)
96 f3 = Environment(TARFLAGS = '-c -z', TARSUFFIX = '.tar.gz')
97 f4 = Environment(TARFLAGS = '-c -z', TARSUFFIX = '.tgz')
98 f5 = Environment(TARFLAGS = '-c -z')
99 foo.Tar(target = 'foo.tar', source = ['file10', 'file11'])
100 foo.Tar(target = 'foo.tar', source = 'file12')
101 bar.Tar(target = 'bar.tar', source = ['file13', 'file14'])
102 bar.Tar(target = 'bar.tar', source = 'file15')
103 f3.Tar(target = 'f3', source = 'file16')
104 f3.Tar(target = 'f3', source = ['file17', 'file18'])
105 f4.Tar(target = 'f4', source = 'file19')
106 f4.Tar(target = 'f4', source = ['file20', 'file21'])
107 f5.Tar(target = 'f5.tgz', source = 'file22')
108 f5.Tar(target = 'f5.tgz', source = ['file23', 'file24'])
111 for f
in ['file10', 'file11', 'file12',
112 'file13', 'file14', 'file15',
113 'file16', 'file17', 'file18',
114 'file19', 'file20', 'file21',
115 'file22', 'file23', 'file24']:
116 test
.write(f
, f
+ "\n")
118 test
.run(arguments
= 'foo.tar', stderr
= None)
120 test
.fail_test(os
.path
.exists(test
.workpath('wrapper.out')))
122 test
.fail_test(not os
.path
.exists(test
.workpath('foo.tar')))
124 test
.run(arguments
= 'bar.tar', stderr
= None)
126 test
.fail_test(not os
.path
.exists(test
.workpath('wrapper.out')))
128 test
.fail_test(not os
.path
.exists(test
.workpath('bar.tar')))
130 test
.run(arguments
= '.', stderr
= None)
132 test
.fail_test(os
.path
.exists(test
.workpath('f3.tar')))
133 test
.fail_test(not os
.path
.exists(test
.workpath('f3.tar.gz')))
135 test
.fail_test(os
.path
.exists(test
.workpath('f4.tar')))
136 test
.fail_test(os
.path
.exists(test
.workpath('f4.tar.gz')))
137 test
.fail_test(not os
.path
.exists(test
.workpath('f4.tgz')))
139 test
.fail_test(os
.path
.exists(test
.workpath('f5.tar')))
140 test
.fail_test(os
.path
.exists(test
.workpath('f5.tar.gz')))
141 test
.fail_test(not os
.path
.exists(test
.workpath('f5.tgz')))
143 test
.run(program
= tar
, arguments
= "-t -f foo.tar", stderr
= None)
144 test
.fail_test(test
.stdout() != "file10\nfile11\nfile12\n")
146 test
.run(program
= tar
, arguments
= "-t -f bar.tar", stderr
= None)
147 test
.fail_test(test
.stdout() != "file13\nfile14\nfile15\n")
149 test
.run(program
= tar
, arguments
= "-t -z -f f3.tar.gz", stderr
= None)
150 test
.fail_test(test
.stdout() != "file16\nfile17\nfile18\n")
152 test
.run(program
= tar
, arguments
= "-t -z -f f4.tgz", stderr
= None)
153 test
.fail_test(test
.stdout() != "file19\nfile20\nfile21\n")
155 test
.run(program
= tar
, arguments
= "-t -z -f f5.tgz", stderr
= None)
156 test
.fail_test(test
.stdout() != "file22\nfile23\nfile24\n")
162 # indent-tabs-mode:nil
164 # vim: set expandtab tabstop=4 shiftwidth=4: