Skip to content

Commit 1535671

Browse files
committed
minimize tool initialization in tests
1 parent f8bb7b9 commit 1535671

File tree

6 files changed

+109
-107
lines changed

6 files changed

+109
-107
lines changed

test/CPPDEFINES/basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
test = TestSCons.TestSCons()
3333

3434
test.write('SConstruct', """\
35+
DefaultEnvironment(tools=[])
3536
test_list = [
3637
'xyz',
3738
['x', 'y', 'z'],
@@ -47,7 +48,7 @@ def generator(target, source, env, for_signature):
4748
return 'TARGET_AND_SOURCE_ARE_MISSING'
4849
4950
for i in test_list:
50-
env = Environment(
51+
env = Environment(tools=['cc'],
5152
CPPDEFPREFIX='-D',
5253
CPPDEFSUFFIX='',
5354
INTEGER=0,
@@ -65,7 +66,7 @@ def generator(target, source, env, for_signature):
6566
)
6667
6768
for i in test_list:
68-
env = Environment(
69+
env = Environment(tools=['cc'],
6970
CPPDEFPREFIX='|',
7071
CPPDEFSUFFIX='|',
7172
INTEGER=1,

test/CPPDEFINES/fixture/SConstruct-Append

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,46 @@ DefaultEnvironment(tools=[])
88

99
# Special cases:
1010
# https://github.com/SCons/scons/issues/1738
11-
env_1738_2 = Environment(CPPDEFPREFIX='-D')
11+
env_1738_2 = Environment(tools=['gcc'],CPPDEFPREFIX='-D')
1212
env_1738_2['CPPDEFINES'] = ['FOO']
1313
env_1738_2.Append(CPPDEFINES={'value': '1'})
1414
print(env_1738_2.subst('$_CPPDEFFLAGS'))
1515
# env_1738_2.Object('test_1738_2', 'main.c')
1616

1717
# https://github.com/SCons/scons/issues/2300
18-
env_2300_1 = Environment(CPPDEFINES='foo', CPPDEFPREFIX='-D')
18+
env_2300_1 = Environment(tools=['gcc'],CPPDEFINES='foo', CPPDEFPREFIX='-D')
1919
env_2300_1.Append(CPPDEFINES='bar')
2020
print(env_2300_1.subst('$_CPPDEFFLAGS'))
2121

22-
env_2300_2 = Environment(CPPDEFINES=['foo'], CPPDEFPREFIX='-D') # note the list
22+
env_2300_2 = Environment(tools=['gcc'],CPPDEFINES=['foo'], CPPDEFPREFIX='-D') # note the list
2323
env_2300_2.Append(CPPDEFINES='bar')
2424
print(env_2300_2.subst('$_CPPDEFFLAGS'))
2525

2626
# An initial space-separated string will be split, but not a string in a list.
27-
env_multi = Environment(CPPDEFPREFIX='-D')
27+
env_multi = Environment(tools=['gcc'],CPPDEFPREFIX='-D')
2828
env_multi['CPPDEFINES'] = "foo bar"
2929
env_multi.Append(CPPDEFINES="baz")
3030
print(env_multi.subst('$_CPPDEFFLAGS'))
3131

32-
env_multi = Environment(CPPDEFPREFIX='-D')
32+
env_multi = Environment(tools=['gcc'],CPPDEFPREFIX='-D')
3333
env_multi['CPPDEFINES'] = ["foo bar"]
3434
env_multi.Append(CPPDEFINES="baz")
3535
print(env_multi.subst('$_CPPDEFFLAGS'))
3636

37-
env_multi = Environment(CPPDEFPREFIX='-D')
37+
env_multi = Environment(tools=['gcc'],CPPDEFPREFIX='-D')
3838
env_multi['CPPDEFINES'] = "foo"
3939
env_multi.Append(CPPDEFINES=["bar baz"])
4040
print(env_multi.subst('$_CPPDEFFLAGS'))
4141

42-
env_multi = Environment(CPPDEFPREFIX='-D')
42+
env_multi = Environment(tools=['gcc'],CPPDEFPREFIX='-D')
4343
env_multi['CPPDEFINES'] = "foo"
4444
env_multi.Append(CPPDEFINES="bar baz")
4545
print(env_multi.subst('$_CPPDEFFLAGS'))
4646

4747
# Check that AppendUnique(..., delete_existing=True) works as expected.
4848
# Each addition is in different but matching form, and different order
4949
# so we expect a reordered list, but with the same macro defines.
50-
env_multi = Environment(CPPDEFPREFIX='-D')
50+
env_multi = Environment(tools=['gcc'],CPPDEFPREFIX='-D')
5151
env_multi.Append(CPPDEFINES=["Macro1=Value1", ("Macro2", "Value2"), {"Macro3": "Value3"}, "Macro4"])
5252
try:
5353
env_multi.AppendUnique(CPPDEFINES="Macro2=Value2", delete_existing=True)
@@ -60,9 +60,9 @@ else:
6060
print(env_multi.subst('$_CPPDEFFLAGS'))
6161

6262
# A lone tuple handled differently than a lone list.
63-
env_multi = Environment(CPPDEFPREFIX='-D', CPPDEFINES=("Macro1", "Value1"))
63+
env_multi = Environment(tools=['gcc'],CPPDEFPREFIX='-D', CPPDEFINES=("Macro1", "Value1"))
6464
print(env_multi.subst('$_CPPDEFFLAGS'))
65-
env_multi = Environment(CPPDEFPREFIX='-D', CPPDEFINES=["Macro1", "Value1"])
65+
env_multi = Environment(tools=['gcc'],CPPDEFPREFIX='-D', CPPDEFINES=["Macro1", "Value1"])
6666
print(env_multi.subst('$_CPPDEFFLAGS'))
6767

6868
# https://github.com/SCons/scons/issues/1152
@@ -114,15 +114,15 @@ for (t1, c1) in cases:
114114
orig = f"{c1!r}" if isinstance(c1, str) else c1
115115
app = f"{c2!r}" if isinstance(c2, str) else c2
116116
print(f" orig = {orig}, append = {app}")
117-
env = Environment(CPPDEFINES=c1, CPPDEFPREFIX='-D')
117+
env = Environment(tools=['gcc'],CPPDEFINES=c1, CPPDEFPREFIX='-D')
118118
try:
119119
env.Append(CPPDEFINES=c2)
120120
final = env.subst('$_CPPDEFFLAGS', source="src", target="tgt")
121121
print(f"Append:\n result={dlist(env['CPPDEFINES'])}\n final={final}")
122122
except Exception as t:
123123
print(f"Append:\n FAILED: {t}")
124124

125-
env = Environment(CPPDEFINES=c1, CPPDEFPREFIX='-D')
125+
env = Environment(tools=['gcc'],CPPDEFINES=c1, CPPDEFPREFIX='-D')
126126
try:
127127
env.AppendUnique(CPPDEFINES=c2)
128128
final = env.subst('$_CPPDEFFLAGS', source="src", target="tgt")

test/CPPDEFINES/fixture/SConstruct-Prepend

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,46 @@ DefaultEnvironment(tools=[])
88

99
# Special cases:
1010
# https://github.com/SCons/scons/issues/1738
11-
env_1738_2 = Environment(CPPDEFPREFIX='-D')
11+
env_1738_2 = Environment(tools=['cc'],CPPDEFPREFIX='-D')
1212
env_1738_2['CPPDEFINES'] = ['FOO']
1313
env_1738_2.Prepend(CPPDEFINES={'value': '1'})
1414
print(env_1738_2.subst('$_CPPDEFFLAGS'))
1515
# env_1738_2.Object('test_1738_2', 'main.c')
1616

1717
# https://github.com/SCons/scons/issues/2300
18-
env_2300_1 = Environment(CPPDEFINES='foo', CPPDEFPREFIX='-D')
18+
env_2300_1 = Environment(tools=['cc'],CPPDEFINES='foo', CPPDEFPREFIX='-D')
1919
env_2300_1.Prepend(CPPDEFINES='bar')
2020
print(env_2300_1.subst('$_CPPDEFFLAGS'))
2121

22-
env_2300_2 = Environment(CPPDEFINES=['foo'], CPPDEFPREFIX='-D') # note the list
22+
env_2300_2 = Environment(tools=['cc'],CPPDEFINES=['foo'], CPPDEFPREFIX='-D') # note the list
2323
env_2300_2.Prepend(CPPDEFINES='bar')
2424
print(env_2300_2.subst('$_CPPDEFFLAGS'))
2525

2626
# An initial space-separated string will be split, but not a string in a list.
27-
env_multi = Environment(CPPDEFPREFIX='-D')
27+
env_multi = Environment(tools=['cc'],CPPDEFPREFIX='-D')
2828
env_multi['CPPDEFINES'] = "foo bar"
2929
env_multi.Prepend(CPPDEFINES="baz")
3030
print(env_multi.subst('$_CPPDEFFLAGS'))
3131

32-
env_multi = Environment(CPPDEFPREFIX='-D')
32+
env_multi = Environment(tools=['cc'],CPPDEFPREFIX='-D')
3333
env_multi['CPPDEFINES'] = ["foo bar"]
3434
env_multi.Prepend(CPPDEFINES="baz")
3535
print(env_multi.subst('$_CPPDEFFLAGS'))
3636

37-
env_multi = Environment(CPPDEFPREFIX='-D')
37+
env_multi = Environment(tools=['cc'],CPPDEFPREFIX='-D')
3838
env_multi['CPPDEFINES'] = "foo"
3939
env_multi.Prepend(CPPDEFINES=["bar baz"])
4040
print(env_multi.subst('$_CPPDEFFLAGS'))
4141

42-
env_multi = Environment(CPPDEFPREFIX='-D')
42+
env_multi = Environment(tools=['cc'],CPPDEFPREFIX='-D')
4343
env_multi['CPPDEFINES'] = "foo"
4444
env_multi.Prepend(CPPDEFINES="bar baz")
4545
print(env_multi.subst('$_CPPDEFFLAGS'))
4646

4747
# Check that PrependUnique(..., delete_existing=True) works as expected.
4848
# Each addition is in different but matching form, and different order
4949
# so we expect a reordered list, but with the same macro defines.
50-
env_multi = Environment(CPPDEFPREFIX='-D')
50+
env_multi = Environment(tools=['cc'],CPPDEFPREFIX='-D')
5151
env_multi.Prepend(CPPDEFINES=["Macro1=Value1", ("Macro2", "Value2"), {"Macro3": "Value3"}])
5252
try:
5353
env_multi.PrependUnique(CPPDEFINES="Macro2=Value2", delete_existing=True)
@@ -60,9 +60,9 @@ else:
6060
print(env_multi.subst('$_CPPDEFFLAGS'))
6161

6262
# A lone tuple handled differently than a lone list.
63-
env_tuple = Environment(CPPDEFPREFIX='-D', CPPDEFINES=("Macro1", "Value1"))
63+
env_tuple = Environment(tools=['cc'],CPPDEFPREFIX='-D', CPPDEFINES=("Macro1", "Value1"))
6464
print(env_tuple.subst('$_CPPDEFFLAGS'))
65-
env_multi = Environment(CPPDEFPREFIX='-D', CPPDEFINES=["Macro1", "Value1"])
65+
env_multi = Environment(tools=['cc'],CPPDEFPREFIX='-D', CPPDEFINES=["Macro1", "Value1"])
6666
print(env_multi.subst('$_CPPDEFFLAGS'))
6767

6868
# https://github.com/SCons/scons/issues/1152
@@ -115,15 +115,15 @@ for (t1, c1) in cases:
115115
orig = f"{c1!r}" if isinstance(c1, str) else c1
116116
pre = f"{c2!r}" if isinstance(c2, str) else c2
117117
print(f" orig = {orig}, prepend = {pre}")
118-
env = Environment(CPPDEFINES=c1, CPPDEFPREFIX='-D')
118+
env = Environment(tools=['cc'],CPPDEFINES=c1, CPPDEFPREFIX='-D')
119119
try:
120120
env.Prepend(CPPDEFINES=c2)
121121
final = env.subst('$_CPPDEFFLAGS', source="src", target="tgt")
122122
print(f"Prepend:\n result={dlist(env['CPPDEFINES'])}\n final={final}")
123123
except Exception as t:
124124
print(f"Prepend:\n FAILED: {t}")
125125

126-
env = Environment(CPPDEFINES=c1, CPPDEFPREFIX='-D')
126+
env = Environment(tools=['cc'],CPPDEFINES=c1, CPPDEFPREFIX='-D')
127127
try:
128128
env.PrependUnique(CPPDEFINES=c2)
129129
final = env.subst('$_CPPDEFFLAGS', source="src", target="tgt")

test/CPPDEFINES/live.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
test = TestSCons.TestSCons()
3333

3434
test.write('SConstruct', """\
35+
DefaultEnvironment(tools=[])
3536
foo = Environment(CPPDEFINES=['FOO', ('VAL', '$VALUE')], VALUE=7)
3637
bar = Environment(CPPDEFINES={'BAR': None, 'VAL': 8})
3738
baz = Environment(CPPDEFINES=['BAZ', ('VAL', 9)])

test/CPPDEFINES/undefined.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
test = TestSCons.TestSCons()
3333

3434
test.write('SConstruct', """\
35-
env = Environment()
35+
DefaultEnvironment(tools=[])
36+
env = Environment(tools=['cc'])
3637
print(env.subst('$_CPPDEFFLAGS'))
3738
""")
3839

test/Climb/filename--D.py

Lines changed: 79 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,79 @@
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 the ability to use the -D option with the -f option to
29-
specify a different top-level file name.
30-
"""
31-
32-
import TestSCons
33-
34-
test = TestSCons.TestSCons()
35-
36-
test.subdir('subdir', 'other')
37-
38-
test.write('main.scons', """\
39-
DefaultEnvironment(tools=[])
40-
print("main.scons")
41-
SConscript('subdir/sub.scons')
42-
""")
43-
44-
test.write(['subdir', 'sub.scons'], """\
45-
print("subdir/sub.scons")
46-
""")
47-
48-
49-
50-
read_str = """\
51-
main.scons
52-
subdir/sub.scons
53-
"""
54-
55-
expect = "scons: Entering directory `%s'\n" % test.workpath() \
56-
+ test.wrap_stdout(read_str = read_str,
57-
build_str = "scons: `subdir' is up to date.\n")
58-
59-
test.run(chdir='subdir', arguments='-D -f main.scons .', stdout=expect)
60-
61-
62-
63-
expect = test.wrap_stdout(read_str = "subdir/sub.scons\n",
64-
build_str = "scons: `.' is up to date.\n")
65-
66-
test.run(chdir='other', arguments='-D -f ../subdir/sub.scons .', stdout=expect)
67-
68-
test.run(chdir='other',
69-
arguments='-D -f %s .' % test.workpath('subdir', 'sub.scons'),
70-
stdout=expect)
71-
72-
73-
74-
test.pass_test()
75-
76-
# Local Variables:
77-
# tab-width:4
78-
# indent-tabs-mode:nil
79-
# End:
80-
# vim: set expandtab tabstop=4 shiftwidth=4:
1+
#!/usr/bin/env python
2+
#
3+
# MIT License
4+
#
5+
# Copyright The SCons Foundation
6+
#
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:
14+
#
15+
# The above copyright notice and this permission notice shall be included
16+
# in all copies or substantial portions of the Software.
17+
#
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.
25+
26+
"""
27+
Verify the ability to use the -D option with the -f option to
28+
specify a different top-level file name.
29+
"""
30+
31+
import TestSCons
32+
33+
test = TestSCons.TestSCons()
34+
35+
test.subdir('subdir', 'other')
36+
37+
test.write('main.scons', """\
38+
DefaultEnvironment(tools=[])
39+
print("main.scons")
40+
SConscript('subdir/sub.scons')
41+
""")
42+
43+
test.write(['subdir', 'sub.scons'], """\
44+
print("subdir/sub.scons")
45+
""")
46+
47+
48+
49+
read_str = """\
50+
main.scons
51+
subdir/sub.scons
52+
"""
53+
54+
expect = "scons: Entering directory `%s'\n" % test.workpath() \
55+
+ test.wrap_stdout(read_str = read_str,
56+
build_str = "scons: `subdir' is up to date.\n")
57+
58+
test.run(chdir='subdir', arguments='-D -f main.scons .', stdout=expect)
59+
60+
61+
62+
expect = test.wrap_stdout(read_str = "subdir/sub.scons\n",
63+
build_str = "scons: `.' is up to date.\n")
64+
65+
test.run(chdir='other', arguments='-D -f ../subdir/sub.scons .', stdout=expect)
66+
67+
test.run(chdir='other',
68+
arguments='-D -f %s .' % test.workpath('subdir', 'sub.scons'),
69+
stdout=expect)
70+
71+
72+
73+
test.pass_test()
74+
75+
# Local Variables:
76+
# tab-width:4
77+
# indent-tabs-mode:nil
78+
# End:
79+
# vim: set expandtab tabstop=4 shiftwidth=4:

0 commit comments

Comments
 (0)