Skip to content

Commit c273de6

Browse files
committed
Test and correct GCC version check
1 parent 8c17a31 commit c273de6

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

tools/test/toolchains/api_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,37 @@ def test_iar_version_check(_run_cmd):
6060
assert len(notifier.messages) == 2
6161

6262

63+
@patch('tools.toolchains.gcc.run_cmd')
64+
def test_gcc_version_check(_run_cmd):
65+
_run_cmd.return_value = ("""
66+
arm-none-eabi-gcc (Arch Repository) 6.4.4
67+
Copyright (C) 2018 Free Software Foundation, Inc.
68+
This is free software; see the source for copying conditions. There is NO
69+
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
70+
""", "", 0)
71+
notifier = MockNotifier()
72+
toolchain = TOOLCHAIN_CLASSES["GCC_ARM"](
73+
TARGET_MAP["K64F"], notify=notifier)
74+
toolchain.version_check()
75+
assert notifier.messages == []
76+
_run_cmd.return_value = ("""
77+
arm-none-eabi-gcc (Arch Repository) 8.1.0
78+
Copyright (C) 2018 Free Software Foundation, Inc.
79+
This is free software; see the source for copying conditions. There is NO
80+
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
81+
""", "", 0)
82+
toolchain.version_check()
83+
assert len(notifier.messages) == 1
84+
_run_cmd.return_value = ("""
85+
arm-none-eabi-gcc (Arch Repository)
86+
Copyright (C) 2018 Free Software Foundation, Inc.
87+
This is free software; see the source for copying conditions. There is NO
88+
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
89+
""", "", 0)
90+
toolchain.version_check()
91+
assert len(notifier.messages) == 2
92+
93+
6394
@given(fixed_dictionaries({
6495
'common': lists(text()),
6596
'c': lists(text()),

tools/toolchains/gcc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GCC(mbedToolchain):
3131
DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(?P<col>\d+):? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')
3232

3333
GCC_RANGE = (LooseVersion("6.0.0"), LooseVersion("7.0.0"))
34-
GCC_VERSION_RE = re.compile("[0-9]*\.[0-9]*\.[0-9]*")
34+
GCC_VERSION_RE = re.compile("\d+\.\d+\.\d+")
3535

3636
def __init__(self, target, notify=None, macros=None, build_profile=None,
3737
build_dir=None):
@@ -122,7 +122,7 @@ def version_check(self):
122122
msg = ("Compiler version mismatch: Have {}; "
123123
"expected version >= {} and < {}"
124124
.format(found_version, min_ver, max_ver))
125-
elif not match or len(match.groups()) != 1:
125+
elif not match:
126126
msg = ("Compiler version mismatch: Could not detect version; "
127127
"expected version >= {} and < {}"
128128
.format(min_ver, max_ver))

0 commit comments

Comments
 (0)