| 146 | return relpath(tmp_dir) if tmp_dir is not None else None, error |
| 147 | |
| 148 | def run_tests(self, tests): |
| 149 | tests = list(tests) |
| 150 | print("running {} test{}".format(len(tests), "s" if len(tests) != 1 else "")) |
| 151 | start = time() |
| 152 | failed = [] |
| 153 | num_passed = 0 |
| 154 | num_skipped = 0 |
| 155 | for test in tests: |
| 156 | if test.requires_mastersrv and self.ddnet_mastersrv is None: |
| 157 | print(f"{test.name} ... {YELLOW}skipped{RESET}") |
| 158 | num_skipped += 1 |
| 159 | continue |
| 160 | print(f"{test.name} ... ", end="", flush=True) |
| 161 | tmp_dir, error = self.run_test(test) |
| 162 | tmp_dir_formatted = f" ({tmp_dir})" if tmp_dir is not None else "" |
| 163 | if error: |
| 164 | print(f"{RED}FAILED{RESET}{tmp_dir_formatted}") |
| 165 | failed.append((test.name, error)) |
| 166 | else: |
| 167 | print(f"{GREEN}ok{RESET}{tmp_dir_formatted}") |
| 168 | num_passed += 1 |
| 169 | print() |
| 170 | if len(tests) != len(failed) + num_passed + num_skipped: |
| 171 | raise AssertionError("invalid counts") |
| 172 | if failed: |
| 173 | print("failures:") |
| 174 | print() |
| 175 | for test, details in failed: |
| 176 | print(f"---- {test} ----") |
| 177 | print(details) |
| 178 | if failed: |
| 179 | print("failures:") |
| 180 | for test, _ in failed: |
| 181 | print(f" {test}") |
| 182 | print() |
| 183 | result = f"{RED}FAILED{RESET}" if failed else f"{GREEN}ok{RESET}" |
| 184 | duration = time() - start |
| 185 | print(f"test result: {result}. {num_passed} passed; {num_skipped} skipped, {len(failed)} failed; finished in {duration:.2f}s") |
| 186 | print() |
| 187 | return bool(failed) |
| 188 | |
| 189 | |
| 190 | class TestEnvironment: |