Skip to content

Commit ff83509

Browse files
committed
Add AddOption tests and fix runtest.py
The two tests originally proposed in SCons#3436, now withdrawn, are added along with a new .exclude_tests to not run them, since they'd currently be in a failing state. Needed to fix runtest.py, wasn't completely correctly processing .exclude_tests files. Signed-off-by: Mats Wichmann <[email protected]>
1 parent 91e5157 commit ff83509

File tree

4 files changed

+204
-3
lines changed

4 files changed

+204
-3
lines changed

runtest.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,19 @@ def find_e2e_tests(directory):
563563
# Skip folders containing a sconstest.skip file
564564
if 'sconstest.skip' in filenames:
565565
continue
566+
567+
p = Path(dirpath).joinpath( ".exclude_tests")
566568
try:
567-
with open(os.path.join(dirpath, ".exclude_tests")) as f:
568-
excludes = scanlist(f)
569-
except EnvironmentError:
569+
if sys.version_info.major == 3 and sys.version_info.minor < 6:
570+
excludefile = p.resolve()
571+
else:
572+
excludefile = p.resolve(strict=True)
573+
except FileNotFoundError:
570574
excludes = []
575+
else:
576+
with excludefile.open() as f:
577+
excludes = scanlist(f)
578+
571579
for fname in filenames:
572580
if fname.endswith(".py") and fname not in excludes:
573581
result.append(os.path.join(dirpath, fname))

test/AddOption/.exclude_tests

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# for now, thee tests showing problems with processing space-separated
2+
# arguments are excluded, pending an implementation that doesn't fail.
3+
args-and-targets.py
4+
multi-arg.py

test/AddOption/args-and-targets.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 that when an option is specified which takes args,
28+
those do not end up treated as targets.
29+
"""
30+
31+
import TestSCons
32+
33+
test = TestSCons.TestSCons()
34+
35+
test.write(
36+
'SConstruct',
37+
"""\
38+
env = Environment()
39+
AddOption(
40+
'--extra',
41+
nargs=1,
42+
dest='extra',
43+
action='store',
44+
type='string',
45+
metavar='ARG1',
46+
default=(),
47+
help='An argument to the option',
48+
)
49+
print(str(GetOption('extra')))
50+
print(COMMAND_LINE_TARGETS)
51+
""",
52+
)
53+
54+
# arg using =
55+
test.run('-Q -q --extra=A TARG', status=1, stdout="A\n['TARG']\n")
56+
# arg not using =
57+
test.run('-Q -q --extra A TARG', status=1, stdout="A\n['TARG']\n")
58+
59+
test.pass_test()
60+
61+
# Local Variables:
62+
# tab-width:4
63+
# indent-tabs-mode:nil
64+
# End:
65+
# vim: set expandtab tabstop=4 shiftwidth=4:

test/AddOption/multi-arg.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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 that when an option is specified with nargs > 1,
28+
SCons consumes those correctly into the args.
29+
"""
30+
31+
import TestSCons
32+
33+
test = TestSCons.TestSCons()
34+
35+
# First, test an option with nargs=2 and no others:
36+
test.write(
37+
'SConstruct',
38+
"""\
39+
env = Environment()
40+
AddOption('--extras',
41+
nargs=2,
42+
dest='extras',
43+
action='store',
44+
type='string',
45+
metavar='FILE1 FILE2',
46+
default=(),
47+
help='two extra files to install')
48+
print(str(GetOption('extras')))
49+
""",
50+
)
51+
52+
# no args
53+
test.run('-Q -q .', stdout="()\n")
54+
# one arg, should fail
55+
test.run(
56+
'-Q -q . --extras A',
57+
status=2,
58+
stderr="""\
59+
usage: scons [OPTION] [TARGET] ...
60+
61+
SCons Error: --extras option requires 2 arguments
62+
""",
63+
)
64+
# two args
65+
test.run('-Q -q . --extras A B', status=1, stdout="('A', 'B')\n")
66+
# -- means the rest are not processed as args
67+
test.run('-Q -q . -- --extras A B', status=1, stdout="()\n")
68+
69+
# Now test what has been a bug: another option is
70+
# also defined, this impacts the collection of args for the nargs>1 opt
71+
test.write(
72+
'SConstruct',
73+
"""\
74+
env = Environment()
75+
AddOption(
76+
'--prefix',
77+
nargs=1,
78+
dest='prefix',
79+
action='store',
80+
type='string',
81+
metavar='DIR',
82+
help='installation prefix',
83+
)
84+
AddOption(
85+
'--extras',
86+
nargs=2,
87+
dest='extras',
88+
action='store',
89+
type='string',
90+
metavar='FILE1 FILE2',
91+
default=(),
92+
help='two extra files to install',
93+
)
94+
print(str(GetOption('prefix')))
95+
print(str(GetOption('extras')))
96+
""",
97+
)
98+
99+
# no options
100+
test.run('-Q -q .', stdout="None\n()\n")
101+
# one single-arg option
102+
test.run('-Q -q . --prefix=/home/foo', stdout="/home/foo\n()\n")
103+
# one two-arg option
104+
test.run('-Q -q . --extras A B', status=1, stdout="None\n('A', 'B')\n")
105+
# single-arg option followed by two-arg option
106+
test.run(
107+
'-Q -q . --prefix=/home/foo --extras A B',
108+
status=1,
109+
stdout="/home/foo\n('A', 'B')\n",
110+
)
111+
# two-arg option followed by single-arg option
112+
test.run(
113+
'-Q -q . --extras A B --prefix=/home/foo',
114+
status=1,
115+
stdout="/home/foo\n('A', 'B')\n",
116+
)
117+
118+
test.pass_test()
119+
120+
# Local Variables:
121+
# tab-width:4
122+
# indent-tabs-mode:nil
123+
# End:
124+
# vim: set expandtab tabstop=4 shiftwidth=4:

0 commit comments

Comments
 (0)