Skip to content

Commit 9cfb988

Browse files
committed
test: make invalid-option parsing checks portable across platforms
1 parent 0e04f19 commit 9cfb988

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test/tool-option-parsing.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import itertools
88
import logging
99
import os
10+
import re
1011
import resource
1112
import subprocess
1213
import sys
@@ -39,6 +40,10 @@
3940
)
4041

4142
TIMEOUT = 10.0 # seconds
43+
INVALID_OPTION_ERROR_RE = re.compile(
44+
r"(unrecognized|unknown|illegal|invalid) option|usage|try --help",
45+
re.IGNORECASE,
46+
)
4247

4348
# Unset some environment variables, so that testing --enable-environment-names
4449
# does not actually depend on the current environment.
@@ -242,9 +247,15 @@ def run_command_invalid(
242247

243248
def run_command_unrecognized_option(self, args):
244249
rc, stdout, stderr = self.run_command(args)
245-
assert rc == 2, (rc, stdout, stderr)
250+
assert rc != 0, (rc, stdout, stderr)
246251
assert stdout.startswith("Usage") or stdout == ""
247-
assert "unrecognized option" in stderr
252+
# getopt/argument parsing diagnostics vary across libc/platforms
253+
# (for example GNU/Linux vs. Solaris), even when the option is rejected.
254+
assert INVALID_OPTION_ERROR_RE.search(f"{stdout}\n{stderr}"), (
255+
rc,
256+
stdout,
257+
stderr,
258+
)
248259

249260
def run_command_missing_arg(self, args):
250261
rc, stdout, stderr = self.run_command(args)

0 commit comments

Comments
 (0)