Updates and slight refactor in fix
[scons.git] / test / Copy-Symlinks.py
blobd2f5f4be7aaef39c2fcc532e921660a09ef3d6c3
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verify that the Copy() Action symlink soft-copy support works.
29 """
31 import os
32 import TestSCons
34 import SCons.Defaults
35 SCons.Defaults.DefaultEnvironment( tools = [] )
37 test = TestSCons.TestSCons()
39 if not test.platform_has_symlink():
40 test.skip_test('No os.symlink() method, no symlinks to test.\n')
42 filelinkToCopy = 'filelinkToCopy'
43 fileToLink = 'file.in'
44 fileContents = 'stuff n things\n'
45 dirToLink = 'dir'
46 dirlinkToCopy = 'dirlinkToCopy'
47 treeToLink = 'tree'
48 treelinkToCopy = 'treelinkToCopy'
49 badToLink = 'None' # do not write this item
50 badlinkToCopy = 'badlinkToCopy'
51 relToLink = os.path.join( treeToLink, fileToLink )
52 rellinkToCopy = 'relLinkToCopy'
54 test.symlink( fileToLink, filelinkToCopy )
55 test.symlink( dirToLink, dirlinkToCopy )
56 test.symlink( treeToLink, treelinkToCopy )
57 test.symlink( badToLink, badlinkToCopy )
58 test.symlink( relToLink, rellinkToCopy )
60 test.write( fileToLink, fileContents )
61 test.subdir( dirToLink )
62 test.subdir( treeToLink )
63 test.write( relToLink, fileContents )
65 sconstructPath = 'SConstruct'
66 sconscriptPath = os.path.join( treeToLink, 'SConscript' )
68 test.write( sconstructPath,
69 """\
70 import SCons.Defaults
71 SCons.Defaults.DefaultEnvironment( tools = [] )
73 Execute( Copy( 'F1', '%(filelinkToCopy)s', False ) )
74 Execute( Copy( 'L1', '%(filelinkToCopy)s' ) )
75 Execute( Copy( 'L2', '%(filelinkToCopy)s', True ) )
77 Execute( Copy( 'D1', '%(dirlinkToCopy)s', False ) )
78 Execute( Copy( 'L3', '%(dirlinkToCopy)s' ) )
79 Execute( Copy( 'L4', '%(dirlinkToCopy)s', True ) )
81 Execute( Copy( 'T1', '%(treelinkToCopy)s', False ) )
82 Execute( Copy( 'L5', '%(treelinkToCopy)s' ) )
83 Execute( Copy( 'L6', '%(treelinkToCopy)s', True ) )
85 Execute( Copy( 'Fails', '%(badlinkToCopy)s', False ) )
86 Execute( Copy( 'L7', '%(badlinkToCopy)s' ) )
87 Execute( Copy( 'L8', '%(badlinkToCopy)s', True ) )
89 SConscript( '%(sconscriptPath)s' )
90 """
91 % locals()
94 relLinkCopyPath = os.path.join( '..', rellinkToCopy )
96 test.write( sconscriptPath,
97 """\
98 Execute( Copy( 'F2', '%(relLinkCopyPath)s', False ) )
99 Execute( Copy( 'L9', '%(relLinkCopyPath)s' ) )
100 Execute( Copy( 'L10', '%(relLinkCopyPath)s', True ) )
102 % locals()
105 test.must_exist( sconstructPath )
106 test.must_exist( sconscriptPath )
107 test.must_exist( fileToLink )
108 test.must_exist( filelinkToCopy )
109 test.must_exist( dirlinkToCopy )
110 test.must_exist( treelinkToCopy )
111 test.must_not_exist( badToLink )
112 test.must_exist( badlinkToCopy )
113 test.must_exist( rellinkToCopy )
115 expectStdout = test.wrap_stdout(
116 read_str =
117 '''\
118 Copy("F1", "%(filelinkToCopy)s")
119 Copy("L1", "%(filelinkToCopy)s")
120 Copy("L2", "%(filelinkToCopy)s")
121 Copy("D1", "%(dirlinkToCopy)s")
122 Copy("L3", "%(dirlinkToCopy)s")
123 Copy("L4", "%(dirlinkToCopy)s")
124 Copy("T1", "%(treelinkToCopy)s")
125 Copy("L5", "%(treelinkToCopy)s")
126 Copy("L6", "%(treelinkToCopy)s")
127 Copy("Fails", "%(badlinkToCopy)s")
128 Copy("L7", "%(badlinkToCopy)s")
129 Copy("L8", "%(badlinkToCopy)s")
130 Copy("F2", "%(relLinkCopyPath)s")
131 Copy("L9", "%(relLinkCopyPath)s")
132 Copy("L10", "%(relLinkCopyPath)s")
133 ''' % locals(),
134 build_str =
135 '''\
136 scons: `.' is up to date.
140 expectStderr = \
141 '''\
142 scons: *** %s: No such file or directory
143 ''' % os.path.join( os.getcwd(), badToLink )
145 test.run( stdout = expectStdout, stderr = expectStderr, status = None )
147 F2 = os.path.join( treeToLink, 'F2' )
148 L9 = os.path.join( treeToLink, 'L9' )
149 L10 = os.path.join( treeToLink, 'L10' )
151 test.must_exist('D1')
152 test.must_exist('F1')
153 test.must_exist( F2 )
154 test.must_exist('L2')
155 test.must_exist('L3')
156 test.must_exist('L4')
157 test.must_exist('L5')
158 test.must_exist('L6')
159 test.must_exist('L7')
160 test.must_exist('L8')
161 test.must_exist( L9 )
162 test.must_exist( L10 )
163 test.must_exist('T1')
164 test.must_not_exist( 'Fails' )
166 test.must_match( fileToLink, fileContents )
167 test.must_match( 'F1', fileContents )
168 test.must_match( F2 , fileContents )
169 test.must_match( 'L1', fileContents )
170 test.must_match( 'L2', fileContents )
171 test.must_match( os.path.join( treeToLink, fileToLink ), fileContents )
173 test.fail_test( condition=os.path.islink('D1') )
174 test.fail_test( condition=os.path.islink('F1') )
175 test.fail_test( condition=os.path.islink( F2 ) )
176 test.fail_test( condition=os.path.islink('T1') )
177 test.fail_test( condition=(not os.path.isdir('D1')) )
178 test.fail_test( condition=(not os.path.isfile('F1')) )
179 test.fail_test( condition=(not os.path.isdir('T1')) )
180 test.fail_test( condition=(not os.path.islink('L1')) )
181 test.fail_test( condition=(not os.path.islink('L2')) )
182 test.fail_test( condition=(not os.path.islink('L3')) )
183 test.fail_test( condition=(not os.path.islink('L4')) )
184 test.fail_test( condition=(not os.path.islink('L5')) )
185 test.fail_test( condition=(not os.path.islink('L6')) )
186 test.fail_test( condition=(not os.path.islink('L7')) )
187 test.fail_test( condition=(not os.path.islink('L8')) )
188 test.fail_test( condition=(not os.path.islink( L9 )) )
189 test.fail_test( condition=(not os.path.islink( L10 )) )
190 test.fail_test( condition=(os.path.exists('L7')) )
191 test.fail_test( condition=(os.path.exists('L8')) )
192 test.fail_test( condition=(os.path.exists( L9 )) )
193 test.fail_test( condition=(os.path.exists( L10 )) )
194 test.fail_test( condition=(os.readlink(filelinkToCopy) != os.readlink('L1')) )
195 test.fail_test( condition=(os.readlink(filelinkToCopy) != os.readlink('L2')) )
196 test.fail_test( condition=(os.readlink(dirlinkToCopy) != os.readlink('L3')) )
197 test.fail_test( condition=(os.readlink(dirlinkToCopy) != os.readlink('L4')) )
198 test.fail_test( condition=(os.readlink(treelinkToCopy) != os.readlink('L5')) )
199 test.fail_test( condition=(os.readlink(treelinkToCopy) != os.readlink('L6')) )
200 test.fail_test( condition=(os.readlink(badlinkToCopy) != os.readlink('L7')) )
201 test.fail_test( condition=(os.readlink(badlinkToCopy) != os.readlink('L8')) )
202 test.fail_test( condition=(os.readlink(rellinkToCopy) != os.readlink( L9 )) )
203 test.fail_test( condition=(os.readlink(rellinkToCopy) != os.readlink( L10 )) )
205 test.pass_test()
207 # Local Variables:
208 # tab-width:4
209 # indent-tabs-mode:nil
210 # End:
211 # vim: set expandtab tabstop=4 shiftwidth=4: