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__"
32 test = TestSCons.TestSCons()
34 foo1 = test.workpath('foo1.txt')
35 #foo2 = test.workpath('foo2.txt')
36 #foo1a = test.workpath('foo1a.txt')
37 #foo2a = test.workpath('foo2a.txt')
39 test.write('SConstruct', """
40 env = Environment(tools=['textfile'])
41 data0 = ['Goethe', 'Schiller']
42 data = ['lalala', 42, data0, 'tanteratei']
44 env.Textfile('foo1', data)
45 env.Textfile('foo2', data, LINESEPARATOR='|*')
46 env.Textfile('foo1a.txt', data + [''])
47 env.Textfile('foo2a.txt', data + [''], LINESEPARATOR='|*')
49 # recreate the list with the data wrapped in Value()
50 data0 = map(Value, data0)
51 data = map(Value, data)
54 env.Substfile('bar1', data)
55 env.Substfile('bar2', data, LINESEPARATOR='|*')
56 data.append(Value(''))
57 env.Substfile('bar1a.txt', data)
58 env.Substfile('bar2a.txt', data, LINESEPARATOR='|*')
61 test.run(arguments = '.')
63 textparts = ['lalala', '42',
66 foo1Text = string.join(textparts, os.linesep)
67 foo2Text = string.join(textparts, '|*')
68 foo1aText = foo1Text + os.linesep
69 foo2aText = foo2Text + '|*'
71 test.up_to_date(arguments = '.')
73 files = map(test.workpath, (
74 'foo1.txt', 'foo2.txt', 'foo1a.txt', 'foo2a.txt',
75 'bar1', 'bar2', 'bar1a.txt', 'bar2a.txt',
78 # make sure the files didn't get rewritten, because nothing changed:
79 before = map(os.path.getmtime, files)
80 # introduce a small delay, to make the test valid
82 # should still be up-to-date
83 test.up_to_date(arguments = '.')
84 after = map(os.path.getmtime, files)
85 test.fail_test(before != after)
87 # make sure that the file content is as expected
88 test.must_match('foo1.txt', foo1Text)
89 test.must_match('bar1', foo1Text)
90 test.must_match('foo2.txt', foo2Text)
91 test.must_match('bar2', foo2Text)
92 test.must_match('foo1a.txt', foo1aText)
93 test.must_match('bar1a.txt', foo1aText)
94 test.must_match('foo2a.txt', foo2aText)
95 test.must_match('bar2a.txt', foo2aText)
98 # write the contents and make sure the files
99 # didn't get rewritten, because nothing changed:
100 test.write('foo1.txt', foo1Text)
101 test.write('bar1', foo1Text)
102 test.write('foo2.txt', foo2Text)
103 test.write('bar2', foo2Text)
104 test.write('foo1a.txt', foo1aText)
105 test.write('bar1a.txt', foo1aText)
106 test.write('foo2a.txt', foo2aText)
107 test.write('bar2a.txt', foo2aText)
110 test.write('SConstruct', """
111 textlist = ['This line has no substitutions',
112 'This line has @subst@ substitutions',
113 'This line has %subst% substitutions',
116 sub1 = { '@subst@' : 'most' }
117 sub2 = { '%subst%' : 'many' }
118 sub3 = { '@subst@' : 'most' , '%subst%' : 'many' }
120 env = Environment(tools = ['textfile'])
122 t = env.Textfile('text', textlist)
124 s = env.Substfile('sub1', t)
126 s = env.Substfile('sub2', s, SUBST_DICT = sub1)
127 # the other substution
128 s = env.Substfile('sub3', s, SUBST_DICT = sub2)
129 # the reverse direction
130 s = env.Substfile('sub4', t, SUBST_DICT = sub2)
131 s = env.Substfile('sub5', s, SUBST_DICT = sub1)
133 s = env.Substfile('sub6', t, SUBST_DICT = sub3)
136 test.run(arguments = '.')
138 line1 = 'This line has no substitutions'
139 line2a = 'This line has @subst@ substitutions'
140 line2b = 'This line has most substitutions'
141 line3a = 'This line has %subst% substitutions'
142 line3b = 'This line has many substitutions'
144 def matchem(file, lines):
145 lines = string.join(lines, '\n')
146 test.must_match(file, lines)
148 matchem('text.txt', [line1, line2a, line3a])
149 matchem('sub1', [line1, line2a, line3a])
150 matchem('sub2', [line1, line2b, line3a])
151 matchem('sub3', [line1, line2b, line3b])
152 matchem('sub4', [line1, line2a, line3b])
153 matchem('sub5', [line1, line2b, line3b])
154 matchem('sub6', [line1, line2b, line3b])
156 test.up_to_date(arguments = '.')