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 test
= TestSCons
.TestSCons()
32 # foo1 = test.workpath('foo1.txt')
33 # foo2 = test.workpath('foo2.txt')
34 # foo1a = test.workpath('foo1a.txt')
35 # foo2a = test.workpath('foo2a.txt')
37 # Must be read binary as now we're including unicode characters in our textparts
40 test
.file_fixture('fixture/SConstruct', 'SConstruct')
42 test
.run(arguments
='.')
46 textparts
= ['lalala', '42',
49 '×'] # <-- this is unicode /xd7 symbol
50 foo1Text
= linesep
.join(textparts
)
51 foo2Text
= '|*'.join(textparts
)
52 foo1aText
= foo1Text
+ linesep
53 foo2aText
= foo2Text
+ '|*'
55 issue_4021_text
= r
'<HintPath>..\..\..\NETCore\bin\$(Platform)\$(Configuration)\Datalogics.PDFL.dll</HintPath>'
57 test
.up_to_date(arguments
='.')
59 files
= list(map(test
.workpath
, (
60 'foo1.txt', 'foo2.txt', 'foo1a.txt', 'foo2a.txt',
61 'bar1', 'bar2', 'bar1a.txt', 'bar2a.txt',
67 make sure the files didn't get rewritten, because nothing changed:
69 before
= list(map(os
.path
.getmtime
, files
))
70 # introduce a small delay, to make the test valid
72 # should still be up-to-date
73 test
.up_to_date(arguments
='.')
74 after
= list(map(os
.path
.getmtime
, files
))
75 test
.fail_test(before
!= after
)
78 # make sure that the file content is as expected
79 test
.must_match('foo1.txt', foo1Text
, mode
=match_mode
)
80 test
.must_match('bar1', foo1Text
, mode
=match_mode
)
81 test
.must_match('foo2.txt', foo2Text
, mode
=match_mode
)
82 test
.must_match('bar2', foo2Text
, mode
=match_mode
)
83 test
.must_match('foo1a.txt', foo1aText
, mode
=match_mode
)
84 test
.must_match('bar1a.txt', foo1aText
, mode
=match_mode
)
85 test
.must_match('foo2a.txt', foo2aText
, mode
=match_mode
)
86 test
.must_match('bar2a.txt', foo2aText
, mode
=match_mode
)
87 test
.must_match('issue-4021.txt', issue_4021_text
, mode
=match_mode
)
90 # write the contents and make sure the files
91 # didn't get rewritten, because nothing changed:
92 test
.write('foo1.txt', foo1Text
)
93 test
.write('bar1', foo1Text
)
94 test
.write('foo2.txt', foo2Text
)
95 test
.write('bar2', foo2Text
)
96 test
.write('foo1a.txt', foo1aText
)
97 test
.write('bar1a.txt', foo1aText
)
98 test
.write('foo2a.txt', foo2aText
)
99 test
.write('bar2a.txt', foo2aText
)
102 # now that textfile is part of default tool list, run one testcase
103 # without adding it explicitly as a tool to make sure.
104 test
.file_fixture('fixture/SConstruct.2', 'SConstruct.2')
106 test
.run(options
='-f SConstruct.2', arguments
='.')
108 line1
= 'This line has no substitutions'
109 line2a
= 'This line has @subst@ substitutions'
110 line2b
= 'This line has most substitutions'
111 line3a
= 'This line has %subst% substitutions'
112 line3b
= 'This line has many substitutions'
115 def matchem(match_file
, lines
):
117 Join all the lines with correct line separator,
120 lines
= linesep
.join(lines
)
121 test
.must_match(match_file
, lines
, mode
=match_mode
, message
="Expected:\n%s\n" % lines
)
124 matchem('text.txt', [line1
, line2a
, line3a
])
125 matchem('sub1', [line1
, line2a
, line3a
])
126 matchem('sub2', [line1
, line2b
, line3a
])
127 matchem('sub3', [line1
, line2b
, line3b
])
128 matchem('sub4', [line1
, line2a
, line3b
])
129 matchem('sub5', [line1
, line2b
, line3b
])
130 matchem('sub6', [line1
, line2b
, line3b
])
132 test
.up_to_date(options
='-f SConstruct.2', arguments
='.')