run_project_tests: Fix it to actually work

This move the sorting logic into the TestDef class itself, which
simplifies sorting them.

Additionally it remove overcomplicated sort logic, because python
strings are compared character by character, we don't need to do the
split and cast to int, we know that realistically a maximum of 4
characters (the first 4 numbers) are going to be compared in most cases.
pull/6550/head
Dylan Baker 5 years ago
parent 3ba0073df6
commit 3689e49f4e
  1. 15
      run_project_tests.py

@ -15,6 +15,7 @@
# limitations under the License.
import typing as T
import functools
import itertools
import os
import subprocess
@ -76,6 +77,7 @@ class TestResult:
self.testtime = testtime
@functools.total_ordering
class TestDef:
def __init__(self, path: Path, name: T.Optional[str], args: T.List[str], skip: bool = False):
self.path = path
@ -91,6 +93,12 @@ class TestDef:
return '{} ({})'.format(self.path.as_posix(), self.name)
return self.path.as_posix()
def __lt__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]:
if isinstance(other, TestDef):
# None is not sortable, so replace it with an empty string
return (self.path, self.name or '') < (other.path, other.name or '')
return NotImplemented
class AutoDeletedDir:
def __init__(self, d):
self.dir = d
@ -492,7 +500,7 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen
return TestResult(validate_install(testdir, install_dir, compiler, builddata.environment),
BuildStep.validate, stdo, stde, mesonlog, cicmds, gen_time, build_time, test_time)
def gather_tests(testdir: Path) -> T.List[TestDef]:
def gather_tests(testdir: Path) -> T.Iterator[TestDef]:
tests = [t.name for t in testdir.glob('*') if t.is_dir()]
tests = [t for t in tests if not t.startswith('.')] # Filter non-tests files (dot files, etc)
tests = [TestDef(testdir / t, None, []) for t in tests]
@ -538,10 +546,7 @@ def gather_tests(testdir: Path) -> T.List[TestDef]:
skip = any([x[1] for x in i])
all_tests += [TestDef(t.path, name, opts, skip)]
all_tests = [(int(t.path.name.split()[0]), t.name or '', t) for t in all_tests]
all_tests.sort()
all_tests = [t[2] for t in all_tests]
return all_tests
return sorted(all_tests)
def have_d_compiler():
if shutil.which("ldc2"):

Loading…
Cancel
Save