| 1 |
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 2 |
# See https://llvm.org/LICENSE.txt for license information. |
| 3 |
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 |
|
| 5 |
# To run these tests: |
| 6 |
# python -m unittest generate_test_report_lib_test.py |
| 7 |
|
| 8 |
import unittest |
| 9 |
from io import StringIO |
| 10 |
from textwrap import dedent |
| 11 |
import tempfile |
| 12 |
import os |
| 13 |
|
| 14 |
from junitparser import JUnitXml |
| 15 |
|
| 16 |
import generate_test_report_lib |
| 17 |
|
| 18 |
|
| 19 |
def junit_from_xml(xml): |
| 20 |
return JUnitXml.fromfile(StringIO(xml)) |
| 21 |
|
| 22 |
|
| 23 |
class TestReports(unittest.TestCase): |
| 24 |
def test_find_failure_ninja_logs(self): |
| 25 |
failures = generate_test_report_lib.find_failure_in_ninja_logs( |
| 26 |
[ |
| 27 |
[ |
| 28 |
"[1/5] test/1.stamp", |
| 29 |
"[2/5] test/2.stamp", |
| 30 |
"[3/5] test/3.stamp", |
| 31 |
"[4/5] test/4.stamp", |
| 32 |
"FAILED: touch test/4.stamp", |
| 33 |
"Wow! This system is really broken!", |
| 34 |
"[5/5] test/5.stamp", |
| 35 |
], |
| 36 |
] |
| 37 |
) |
| 38 |
self.assertEqual(len(failures), 1) |
| 39 |
self.assertEqual( |
| 40 |
failures[0], |
| 41 |
( |
| 42 |
"touch test/4.stamp", |
| 43 |
dedent( |
| 44 |
"""\ |
| 45 |
FAILED: touch test/4.stamp |
| 46 |
Wow! This system is really broken!""" |
| 47 |
), |
| 48 |
), |
| 49 |
) |
| 50 |
|
| 51 |
def test_no_failure_ninja_log(self): |
| 52 |
failures = generate_test_report_lib.find_failure_in_ninja_logs( |
| 53 |
[ |
| 54 |
[ |
| 55 |
"[1/3] test/1.stamp", |
| 56 |
"[2/3] test/2.stamp", |
| 57 |
"[3/3] test/3.stamp", |
| 58 |
] |
| 59 |
] |
| 60 |
) |
| 61 |
self.assertEqual(failures, []) |
| 62 |
|
| 63 |
def test_ninja_log_end(self): |
| 64 |
failures = generate_test_report_lib.find_failure_in_ninja_logs( |
| 65 |
[ |
| 66 |
[ |
| 67 |
"[1/3] test/1.stamp", |
| 68 |
"[2/3] test/2.stamp", |
| 69 |
"[3/3] test/3.stamp", |
| 70 |
"FAILED: touch test/3.stamp", |
| 71 |
"Wow! This system is really broken!", |
| 72 |
"ninja: build stopped: subcommand failed.", |
| 73 |
] |
| 74 |
] |
| 75 |
) |
| 76 |
self.assertEqual(len(failures), 1) |
| 77 |
self.assertEqual( |
| 78 |
failures[0], |
| 79 |
( |
| 80 |
"touch test/3.stamp", |
| 81 |
dedent( |
| 82 |
"""\ |
| 83 |
FAILED: touch test/3.stamp |
| 84 |
Wow! This system is really broken!""" |
| 85 |
), |
| 86 |
), |
| 87 |
) |
| 88 |
|
| 89 |
def test_ninja_log_multiple_failures(self): |
| 90 |
failures = generate_test_report_lib.find_failure_in_ninja_logs( |
| 91 |
[ |
| 92 |
[ |
| 93 |
"[1/5] test/1.stamp", |
| 94 |
"[2/5] test/2.stamp", |
| 95 |
"FAILED: touch test/2.stamp", |
| 96 |
"Wow! This system is really broken!", |
| 97 |
"[3/5] test/3.stamp", |
| 98 |
"[4/5] test/4.stamp", |
| 99 |
"FAILED: touch test/4.stamp", |
| 100 |
"Wow! This system is maybe broken!", |
| 101 |
"[5/5] test/5.stamp", |
| 102 |
] |
| 103 |
] |
| 104 |
) |
| 105 |
self.assertEqual(len(failures), 2) |
| 106 |
self.assertEqual( |
| 107 |
failures[0], |
| 108 |
( |
| 109 |
"touch test/2.stamp", |
| 110 |
dedent( |
| 111 |
"""\ |
| 112 |
FAILED: touch test/2.stamp |
| 113 |
Wow! This system is really broken!""" |
| 114 |
), |
| 115 |
), |
| 116 |
) |
| 117 |
self.assertEqual( |
| 118 |
failures[1], |
| 119 |
( |
| 120 |
"touch test/4.stamp", |
| 121 |
dedent( |
| 122 |
"""\ |
| 123 |
FAILED: touch test/4.stamp |
| 124 |
Wow! This system is maybe broken!""" |
| 125 |
), |
| 126 |
), |
| 127 |
) |
| 128 |
|
| 129 |
# Test that we can correctly handle the runtimes build. the LLVM runtimes |
| 130 |
# build will involve ninja invoking more ninja processes within the |
| 131 |
# runtimes directory. This means that we see two failures for a failure in |
| 132 |
# the runtimes build: one from the inner ninja containing the actual action |
| 133 |
# that failed, and one for the sub ninja invocation that failed. |
| 134 |
def test_ninja_log_runtimes_failure(self): |
| 135 |
failures = generate_test_report_lib.find_failure_in_ninja_logs( |
| 136 |
[ |
| 137 |
[ |
| 138 |
"[1/5] test/1.stamp", |
| 139 |
"[2/5] test/2.stamp", |
| 140 |
"FAILED: touch test/2.stamp", |
| 141 |
"Wow! This system is really broken!", |
| 142 |
"ninja: build stopped: subcommand failed.", |
| 143 |
"FAILED: running check-runtime failed.", |
| 144 |
"<some random command>", |
| 145 |
"ninja: build stopped: subcommand failed.", |
| 146 |
] |
| 147 |
] |
| 148 |
) |
| 149 |
self.assertEqual(len(failures), 1) |
| 150 |
self.assertEqual( |
| 151 |
failures[0], |
| 152 |
( |
| 153 |
"touch test/2.stamp", |
| 154 |
dedent( |
| 155 |
"""\ |
| 156 |
FAILED: touch test/2.stamp |
| 157 |
Wow! This system is really broken!""" |
| 158 |
), |
| 159 |
), |
| 160 |
) |
| 161 |
|
| 162 |
# Test that we correctly handle cases where the FAILED: line does not |
| 163 |
# match up with the progress indicator. |
| 164 |
def test_ninja_log_mismatched_failed(self): |
| 165 |
failures = generate_test_report_lib.find_failure_in_ninja_logs( |
| 166 |
[ |
| 167 |
[ |
| 168 |
"[1/5] test/1.stamp", |
| 169 |
"[2/5] test/2.stamp", |
| 170 |
"ModuleNotFoundError: No module named 'mount_langley'", |
| 171 |
"FAILED: tools/check-langley", |
| 172 |
"Wow! This system is really broken!", |
| 173 |
"[5/5] test/5.stamp", |
| 174 |
] |
| 175 |
] |
| 176 |
) |
| 177 |
self.assertEqual(len(failures), 1) |
| 178 |
self.assertEqual( |
| 179 |
failures[0], |
| 180 |
( |
| 181 |
"tools/check-langley", |
| 182 |
dedent( |
| 183 |
"""\ |
| 184 |
ModuleNotFoundError: No module named 'mount_langley' |
| 185 |
FAILED: tools/check-langley |
| 186 |
Wow! This system is really broken!""" |
| 187 |
), |
| 188 |
), |
| 189 |
) |
| 190 |
|
| 191 |
def test_title_only(self): |
| 192 |
self.assertEqual( |
| 193 |
generate_test_report_lib.generate_report("Foo", 0, [], []), |
| 194 |
( |
| 195 |
dedent( |
| 196 |
"""\ |
| 197 |
# Foo |
| 198 |
|
| 199 |
:white_check_mark: The build succeeded and no tests ran. This is expected in some build configurations.""" |
| 200 |
), |
| 201 |
True, |
| 202 |
), |
| 203 |
) |
| 204 |
|
| 205 |
def test_title_only_failure(self): |
| 206 |
self.assertEqual( |
| 207 |
generate_test_report_lib.generate_report("Foo", 1, [], []), |
| 208 |
( |
| 209 |
dedent( |
| 210 |
"""\ |
| 211 |
# Foo |
| 212 |
|
| 213 |
The build failed before running any tests. Detailed information about the build failure could not be automatically obtained. |
| 214 |
|
| 215 |
Download the build's log file to see the details. |
| 216 |
|
| 217 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 218 |
), |
| 219 |
False, |
| 220 |
), |
| 221 |
) |
| 222 |
|
| 223 |
def test_title_only_failure_ninja_log(self): |
| 224 |
self.assertEqual( |
| 225 |
generate_test_report_lib.generate_report( |
| 226 |
"Foo", |
| 227 |
1, |
| 228 |
[], |
| 229 |
[ |
| 230 |
[ |
| 231 |
"[1/5] test/1.stamp", |
| 232 |
"[2/5] test/2.stamp", |
| 233 |
"[3/5] test/3.stamp", |
| 234 |
"[4/5] test/4.stamp", |
| 235 |
"FAILED: test/4.stamp", |
| 236 |
"touch test/4.stamp", |
| 237 |
"Wow! Risk!", |
| 238 |
"[5/5] test/5.stamp", |
| 239 |
] |
| 240 |
], |
| 241 |
), |
| 242 |
( |
| 243 |
dedent( |
| 244 |
"""\ |
| 245 |
# Foo |
| 246 |
|
| 247 |
The build failed before running any tests. Click on a failure below to see the details. |
| 248 |
|
| 249 |
<details> |
| 250 |
<summary>test/4.stamp</summary> |
| 251 |
|
| 252 |
``` |
| 253 |
FAILED: test/4.stamp |
| 254 |
touch test/4.stamp |
| 255 |
Wow! Risk! |
| 256 |
``` |
| 257 |
</details> |
| 258 |
|
| 259 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 260 |
), |
| 261 |
False, |
| 262 |
), |
| 263 |
) |
| 264 |
|
| 265 |
def test_no_tests_in_testsuite(self): |
| 266 |
self.assertEqual( |
| 267 |
generate_test_report_lib.generate_report( |
| 268 |
"Foo", |
| 269 |
1, |
| 270 |
[ |
| 271 |
junit_from_xml( |
| 272 |
dedent( |
| 273 |
"""\ |
| 274 |
<?xml version="1.0" encoding="UTF-8"?> |
| 275 |
<testsuites time="0.00"> |
| 276 |
<testsuite name="Empty" tests="0" failures="0" skipped="0" time="0.00"> |
| 277 |
</testsuite> |
| 278 |
</testsuites>""" |
| 279 |
) |
| 280 |
) |
| 281 |
], |
| 282 |
[], |
| 283 |
), |
| 284 |
( |
| 285 |
dedent( |
| 286 |
"""\ |
| 287 |
# Foo |
| 288 |
|
| 289 |
The build failed before running any tests. Detailed information about the build failure could not be automatically obtained. |
| 290 |
|
| 291 |
Download the build's log file to see the details. |
| 292 |
|
| 293 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 294 |
), |
| 295 |
False, |
| 296 |
), |
| 297 |
) |
| 298 |
|
| 299 |
def test_no_failures(self): |
| 300 |
self.assertEqual( |
| 301 |
generate_test_report_lib.generate_report( |
| 302 |
"Foo", |
| 303 |
0, |
| 304 |
[ |
| 305 |
junit_from_xml( |
| 306 |
dedent( |
| 307 |
"""\ |
| 308 |
<?xml version="1.0" encoding="UTF-8"?> |
| 309 |
<testsuites time="0.00"> |
| 310 |
<testsuite name="Passed" tests="1" failures="0" skipped="0" time="0.00"> |
| 311 |
<testcase classname="Bar/test_1" name="test_1" time="0.00"/> |
| 312 |
</testsuite> |
| 313 |
</testsuites>""" |
| 314 |
) |
| 315 |
) |
| 316 |
], |
| 317 |
[], |
| 318 |
), |
| 319 |
( |
| 320 |
dedent( |
| 321 |
"""\ |
| 322 |
# Foo |
| 323 |
|
| 324 |
* 1 test passed |
| 325 |
|
| 326 |
:white_check_mark: The build succeeded and all tests passed.""" |
| 327 |
), |
| 328 |
True, |
| 329 |
), |
| 330 |
) |
| 331 |
|
| 332 |
def test_no_failures_build_failed(self): |
| 333 |
self.assertEqual( |
| 334 |
generate_test_report_lib.generate_report( |
| 335 |
"Foo", |
| 336 |
1, |
| 337 |
[ |
| 338 |
junit_from_xml( |
| 339 |
dedent( |
| 340 |
"""\ |
| 341 |
<?xml version="1.0" encoding="UTF-8"?> |
| 342 |
<testsuites time="0.00"> |
| 343 |
<testsuite name="Passed" tests="1" failures="0" skipped="0" time="0.00"> |
| 344 |
<testcase classname="Bar/test_1" name="test_1" time="0.00"/> |
| 345 |
</testsuite> |
| 346 |
</testsuites>""" |
| 347 |
) |
| 348 |
) |
| 349 |
], |
| 350 |
[], |
| 351 |
), |
| 352 |
( |
| 353 |
dedent( |
| 354 |
"""\ |
| 355 |
# Foo |
| 356 |
|
| 357 |
* 1 test passed |
| 358 |
|
| 359 |
All executed tests passed, but another part of the build **failed**. Information about the build failure could not be automatically obtained. |
| 360 |
|
| 361 |
Download the build's log file to see the details. |
| 362 |
|
| 363 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 364 |
), |
| 365 |
False, |
| 366 |
), |
| 367 |
) |
| 368 |
|
| 369 |
def test_no_failures_build_failed_ninja_log(self): |
| 370 |
self.assertEqual( |
| 371 |
generate_test_report_lib.generate_report( |
| 372 |
"Foo", |
| 373 |
1, |
| 374 |
[ |
| 375 |
junit_from_xml( |
| 376 |
dedent( |
| 377 |
"""\ |
| 378 |
<?xml version="1.0" encoding="UTF-8"?> |
| 379 |
<testsuites time="0.00"> |
| 380 |
<testsuite name="Passed" tests="1" failures="0" skipped="0" time="0.00"> |
| 381 |
<testcase classname="Bar/test_1" name="test_1" time="0.00"/> |
| 382 |
</testsuite> |
| 383 |
</testsuites>""" |
| 384 |
) |
| 385 |
) |
| 386 |
], |
| 387 |
[ |
| 388 |
[ |
| 389 |
"[1/5] test/1.stamp", |
| 390 |
"[2/5] test/2.stamp", |
| 391 |
"[3/5] test/3.stamp", |
| 392 |
"[4/5] test/4.stamp", |
| 393 |
"FAILED: test/4.stamp", |
| 394 |
"touch test/4.stamp", |
| 395 |
"Wow! Close To You!", |
| 396 |
"[5/5] test/5.stamp", |
| 397 |
] |
| 398 |
], |
| 399 |
), |
| 400 |
( |
| 401 |
dedent( |
| 402 |
"""\ |
| 403 |
# Foo |
| 404 |
|
| 405 |
* 1 test passed |
| 406 |
|
| 407 |
All executed tests passed, but another part of the build **failed**. Click on a failure below to see the details. |
| 408 |
|
| 409 |
<details> |
| 410 |
<summary>test/4.stamp</summary> |
| 411 |
|
| 412 |
``` |
| 413 |
FAILED: test/4.stamp |
| 414 |
touch test/4.stamp |
| 415 |
Wow! Close To You! |
| 416 |
``` |
| 417 |
</details> |
| 418 |
|
| 419 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 420 |
), |
| 421 |
False, |
| 422 |
), |
| 423 |
) |
| 424 |
|
| 425 |
def test_no_failures_multiple_build_failed_ninja_log(self): |
| 426 |
self.assertEqual( |
| 427 |
generate_test_report_lib.generate_report( |
| 428 |
"Foo", |
| 429 |
1, |
| 430 |
[ |
| 431 |
junit_from_xml( |
| 432 |
dedent( |
| 433 |
"""\ |
| 434 |
<?xml version="1.0" encoding="UTF-8"?> |
| 435 |
<testsuites time="0.00"> |
| 436 |
<testsuite name="Passed" tests="1" failures="0" skipped="0" time="0.00"> |
| 437 |
<testcase classname="Bar/test_1" name="test_1" time="0.00"/> |
| 438 |
</testsuite> |
| 439 |
</testsuites>""" |
| 440 |
) |
| 441 |
) |
| 442 |
], |
| 443 |
[ |
| 444 |
[ |
| 445 |
"[1/5] test/1.stamp", |
| 446 |
"[2/5] test/2.stamp", |
| 447 |
"FAILED: touch test/2.stamp", |
| 448 |
"Wow! Be Kind!", |
| 449 |
"[3/5] test/3.stamp", |
| 450 |
"[4/5] test/4.stamp", |
| 451 |
"FAILED: touch test/4.stamp", |
| 452 |
"Wow! I Dare You!", |
| 453 |
"[5/5] test/5.stamp", |
| 454 |
] |
| 455 |
], |
| 456 |
), |
| 457 |
( |
| 458 |
dedent( |
| 459 |
"""\ |
| 460 |
# Foo |
| 461 |
|
| 462 |
* 1 test passed |
| 463 |
|
| 464 |
All executed tests passed, but another part of the build **failed**. Click on a failure below to see the details. |
| 465 |
|
| 466 |
<details> |
| 467 |
<summary>touch test/2.stamp</summary> |
| 468 |
|
| 469 |
``` |
| 470 |
FAILED: touch test/2.stamp |
| 471 |
Wow! Be Kind! |
| 472 |
``` |
| 473 |
</details> |
| 474 |
<details> |
| 475 |
<summary>touch test/4.stamp</summary> |
| 476 |
|
| 477 |
``` |
| 478 |
FAILED: touch test/4.stamp |
| 479 |
Wow! I Dare You! |
| 480 |
``` |
| 481 |
</details> |
| 482 |
|
| 483 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 484 |
), |
| 485 |
False, |
| 486 |
), |
| 487 |
) |
| 488 |
|
| 489 |
def test_report_single_file_single_testsuite(self): |
| 490 |
self.assertEqual( |
| 491 |
generate_test_report_lib.generate_report( |
| 492 |
"Foo", |
| 493 |
1, |
| 494 |
[ |
| 495 |
junit_from_xml( |
| 496 |
dedent( |
| 497 |
"""\ |
| 498 |
<?xml version="1.0" encoding="UTF-8"?> |
| 499 |
<testsuites time="8.89"> |
| 500 |
<testsuite name="Bar" tests="4" failures="2" skipped="1" time="410.63"> |
| 501 |
<testcase classname="Bar/test_1" name="test_1" time="0.02"/> |
| 502 |
<testcase classname="Bar/test_2" name="test_2" time="0.02"> |
| 503 |
<skipped message="Reason"/> |
| 504 |
</testcase> |
| 505 |
<testcase classname="Bar/test_3" name="test_3" time="0.02"> |
| 506 |
<failure><![CDATA[Output goes here]]></failure> |
| 507 |
</testcase> |
| 508 |
<testcase classname="Bar/test_4" name="test_4" time="0.02"> |
| 509 |
<failure><![CDATA[Other output goes here]]></failure> |
| 510 |
</testcase> |
| 511 |
</testsuite> |
| 512 |
</testsuites>""" |
| 513 |
) |
| 514 |
) |
| 515 |
], |
| 516 |
[], |
| 517 |
), |
| 518 |
( |
| 519 |
dedent( |
| 520 |
"""\ |
| 521 |
# Foo |
| 522 |
|
| 523 |
* 1 test passed |
| 524 |
* 1 test skipped |
| 525 |
* 2 tests failed |
| 526 |
|
| 527 |
## Failed Tests |
| 528 |
(click on a test name to see its output) |
| 529 |
|
| 530 |
### Bar |
| 531 |
<details> |
| 532 |
<summary>Bar/test_3/test_3</summary> |
| 533 |
|
| 534 |
``` |
| 535 |
Output goes here |
| 536 |
``` |
| 537 |
</details> |
| 538 |
<details> |
| 539 |
<summary>Bar/test_4/test_4</summary> |
| 540 |
|
| 541 |
``` |
| 542 |
Other output goes here |
| 543 |
``` |
| 544 |
</details> |
| 545 |
|
| 546 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 547 |
), |
| 548 |
False, |
| 549 |
), |
| 550 |
) |
| 551 |
|
| 552 |
MULTI_SUITE_OUTPUT = dedent( |
| 553 |
"""\ |
| 554 |
# ABC and DEF |
| 555 |
|
| 556 |
* 1 test passed |
| 557 |
* 1 test skipped |
| 558 |
* 2 tests failed |
| 559 |
|
| 560 |
## Failed Tests |
| 561 |
(click on a test name to see its output) |
| 562 |
|
| 563 |
### ABC |
| 564 |
<details> |
| 565 |
<summary>ABC/test_2/test_2</summary> |
| 566 |
|
| 567 |
``` |
| 568 |
ABC/test_2 output goes here |
| 569 |
``` |
| 570 |
</details> |
| 571 |
|
| 572 |
### DEF |
| 573 |
<details> |
| 574 |
<summary>DEF/test_2/test_2</summary> |
| 575 |
|
| 576 |
``` |
| 577 |
DEF/test_2 output goes here |
| 578 |
``` |
| 579 |
</details> |
| 580 |
|
| 581 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 582 |
) |
| 583 |
|
| 584 |
def test_report_single_file_multiple_testsuites(self): |
| 585 |
self.assertEqual( |
| 586 |
generate_test_report_lib.generate_report( |
| 587 |
"ABC and DEF", |
| 588 |
1, |
| 589 |
[ |
| 590 |
junit_from_xml( |
| 591 |
dedent( |
| 592 |
"""\ |
| 593 |
<?xml version="1.0" encoding="UTF-8"?> |
| 594 |
<testsuites time="8.89"> |
| 595 |
<testsuite name="ABC" tests="2" failures="1" skipped="0" time="410.63"> |
| 596 |
<testcase classname="ABC/test_1" name="test_1" time="0.02"/> |
| 597 |
<testcase classname="ABC/test_2" name="test_2" time="0.02"> |
| 598 |
<failure><![CDATA[ABC/test_2 output goes here]]></failure> |
| 599 |
</testcase> |
| 600 |
</testsuite> |
| 601 |
<testsuite name="DEF" tests="2" failures="1" skipped="1" time="410.63"> |
| 602 |
<testcase classname="DEF/test_1" name="test_1" time="0.02"> |
| 603 |
<skipped message="reason"/> |
| 604 |
</testcase> |
| 605 |
<testcase classname="DEF/test_2" name="test_2" time="0.02"> |
| 606 |
<failure><![CDATA[DEF/test_2 output goes here]]></failure> |
| 607 |
</testcase> |
| 608 |
</testsuite> |
| 609 |
</testsuites>""" |
| 610 |
) |
| 611 |
) |
| 612 |
], |
| 613 |
[], |
| 614 |
), |
| 615 |
(self.MULTI_SUITE_OUTPUT, False), |
| 616 |
) |
| 617 |
|
| 618 |
def test_report_multiple_files_multiple_testsuites(self): |
| 619 |
self.assertEqual( |
| 620 |
generate_test_report_lib.generate_report( |
| 621 |
"ABC and DEF", |
| 622 |
1, |
| 623 |
[ |
| 624 |
junit_from_xml( |
| 625 |
dedent( |
| 626 |
"""\ |
| 627 |
<?xml version="1.0" encoding="UTF-8"?> |
| 628 |
<testsuites time="8.89"> |
| 629 |
<testsuite name="ABC" tests="2" failures="1" skipped="0" time="410.63"> |
| 630 |
<testcase classname="ABC/test_1" name="test_1" time="0.02"/> |
| 631 |
<testcase classname="ABC/test_2" name="test_2" time="0.02"> |
| 632 |
<failure><![CDATA[ABC/test_2 output goes here]]></failure> |
| 633 |
</testcase> |
| 634 |
</testsuite> |
| 635 |
</testsuites>""" |
| 636 |
) |
| 637 |
), |
| 638 |
junit_from_xml( |
| 639 |
dedent( |
| 640 |
"""\ |
| 641 |
<?xml version="1.0" encoding="UTF-8"?> |
| 642 |
<testsuites time="8.89"> |
| 643 |
<testsuite name="DEF" tests="2" failures="1" skipped="1" time="410.63"> |
| 644 |
<testcase classname="DEF/test_1" name="test_1" time="0.02"> |
| 645 |
<skipped message="reason"/> |
| 646 |
</testcase> |
| 647 |
<testcase classname="DEF/test_2" name="test_2" time="0.02"> |
| 648 |
<failure><![CDATA[DEF/test_2 output goes here]]></failure> |
| 649 |
</testcase> |
| 650 |
</testsuite> |
| 651 |
</testsuites>""" |
| 652 |
) |
| 653 |
), |
| 654 |
], |
| 655 |
[], |
| 656 |
), |
| 657 |
(self.MULTI_SUITE_OUTPUT, False), |
| 658 |
) |
| 659 |
|
| 660 |
def test_report_dont_list_failures(self): |
| 661 |
self.assertEqual( |
| 662 |
generate_test_report_lib.generate_report( |
| 663 |
"Foo", |
| 664 |
1, |
| 665 |
[ |
| 666 |
junit_from_xml( |
| 667 |
dedent( |
| 668 |
"""\ |
| 669 |
<?xml version="1.0" encoding="UTF-8"?> |
| 670 |
<testsuites time="0.02"> |
| 671 |
<testsuite name="Bar" tests="1" failures="1" skipped="0" time="0.02"> |
| 672 |
<testcase classname="Bar/test_1" name="test_1" time="0.02"> |
| 673 |
<failure><![CDATA[Output goes here]]></failure> |
| 674 |
</testcase> |
| 675 |
</testsuite> |
| 676 |
</testsuites>""" |
| 677 |
) |
| 678 |
) |
| 679 |
], |
| 680 |
[], |
| 681 |
list_failures=False, |
| 682 |
), |
| 683 |
( |
| 684 |
dedent( |
| 685 |
"""\ |
| 686 |
# Foo |
| 687 |
|
| 688 |
* 1 test failed |
| 689 |
|
| 690 |
Failed tests and their output was too large to report. Download the build's log file to see the details. |
| 691 |
|
| 692 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 693 |
), |
| 694 |
False, |
| 695 |
), |
| 696 |
) |
| 697 |
|
| 698 |
def test_report_dont_list_failures_link_to_log(self): |
| 699 |
self.assertEqual( |
| 700 |
generate_test_report_lib.generate_report( |
| 701 |
"Foo", |
| 702 |
1, |
| 703 |
[ |
| 704 |
junit_from_xml( |
| 705 |
dedent( |
| 706 |
"""\ |
| 707 |
<?xml version="1.0" encoding="UTF-8"?> |
| 708 |
<testsuites time="0.02"> |
| 709 |
<testsuite name="Bar" tests="1" failures="1" skipped="0" time="0.02"> |
| 710 |
<testcase classname="Bar/test_1" name="test_1" time="0.02"> |
| 711 |
<failure><![CDATA[Output goes here]]></failure> |
| 712 |
</testcase> |
| 713 |
</testsuite> |
| 714 |
</testsuites>""" |
| 715 |
) |
| 716 |
) |
| 717 |
], |
| 718 |
[], |
| 719 |
list_failures=False, |
| 720 |
), |
| 721 |
( |
| 722 |
dedent( |
| 723 |
"""\ |
| 724 |
# Foo |
| 725 |
|
| 726 |
* 1 test failed |
| 727 |
|
| 728 |
Failed tests and their output was too large to report. Download the build's log file to see the details. |
| 729 |
|
| 730 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 731 |
), |
| 732 |
False, |
| 733 |
), |
| 734 |
) |
| 735 |
|
| 736 |
def test_report_size_limit(self): |
| 737 |
test_output = "f" * 1000 |
| 738 |
self.assertEqual( |
| 739 |
generate_test_report_lib.generate_report( |
| 740 |
"Foo", |
| 741 |
1, |
| 742 |
[ |
| 743 |
junit_from_xml( |
| 744 |
dedent( |
| 745 |
"""\ |
| 746 |
<?xml version="1.0" encoding="UTF-8"?> |
| 747 |
<testsuites time="0.02"> |
| 748 |
<testsuite name="Bar" tests="1" failures="1" skipped="0" time="0.02"> |
| 749 |
<testcase classname="Bar/test_1" name="test_1" time="0.02"> |
| 750 |
<failure><![CDATA[{output}]]></failure> |
| 751 |
</testcase> |
| 752 |
</testsuite> |
| 753 |
</testsuites>""".format( |
| 754 |
output=test_output |
| 755 |
) |
| 756 |
) |
| 757 |
) |
| 758 |
], |
| 759 |
[], |
| 760 |
size_limit=512, |
| 761 |
), |
| 762 |
( |
| 763 |
dedent( |
| 764 |
"""\ |
| 765 |
# Foo |
| 766 |
|
| 767 |
* 1 test failed |
| 768 |
|
| 769 |
Failed tests and their output was too large to report. Download the build's log file to see the details. |
| 770 |
|
| 771 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 772 |
), |
| 773 |
False, |
| 774 |
), |
| 775 |
) |
| 776 |
|
| 777 |
def test_report_ninja_explanation(self): |
| 778 |
self.assertEqual( |
| 779 |
generate_test_report_lib.generate_report( |
| 780 |
"Foo", |
| 781 |
1, |
| 782 |
[], |
| 783 |
[ |
| 784 |
[ |
| 785 |
"[1/5] test/1.stamp", |
| 786 |
"[2/5] test/2.stamp", |
| 787 |
"[3/5] test/3.stamp", |
| 788 |
"[4/5] test/4.stamp", |
| 789 |
"FAILED: test/4.stamp", |
| 790 |
"touch test/4.stamp", |
| 791 |
"Half Moon Bay.", |
| 792 |
"[5/5] test/5.stamp", |
| 793 |
] |
| 794 |
], |
| 795 |
failure_explanations_list=[ |
| 796 |
{ |
| 797 |
"name": "test/4.stamp", |
| 798 |
"explained": True, |
| 799 |
"reason": "Failing at head", |
| 800 |
} |
| 801 |
], |
| 802 |
), |
| 803 |
( |
| 804 |
dedent( |
| 805 |
"""\ |
| 806 |
# Foo |
| 807 |
|
| 808 |
The build failed before running any tests. Click on a failure below to see the details. |
| 809 |
|
| 810 |
<details> |
| 811 |
<summary>test/4.stamp (Likely Already Failing)</summary> |
| 812 |
Failing at head |
| 813 |
|
| 814 |
``` |
| 815 |
FAILED: test/4.stamp |
| 816 |
touch test/4.stamp |
| 817 |
Half Moon Bay. |
| 818 |
``` |
| 819 |
</details> |
| 820 |
|
| 821 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 822 |
), |
| 823 |
True, |
| 824 |
), |
| 825 |
) |
| 826 |
|
| 827 |
def test_report_test_failure_explanation(self): |
| 828 |
self.assertEqual( |
| 829 |
generate_test_report_lib.generate_report( |
| 830 |
"Foo", |
| 831 |
1, |
| 832 |
[ |
| 833 |
junit_from_xml( |
| 834 |
dedent( |
| 835 |
"""\ |
| 836 |
<?xml version="1.0" encoding="UTF-8"?> |
| 837 |
<testsuites time="8.89"> |
| 838 |
<testsuite name="Bar" tests="1" failures="1" skipped="0" time="410.63"> |
| 839 |
<testcase classname="Bar/test_3" name="test_3" time="0.02"> |
| 840 |
<failure><![CDATA[Error! Expected Big Sur to be next to the ocean.]]></failure> |
| 841 |
</testcase> |
| 842 |
</testsuite> |
| 843 |
</testsuites>""" |
| 844 |
) |
| 845 |
) |
| 846 |
], |
| 847 |
[], |
| 848 |
failure_explanations_list=[ |
| 849 |
{ |
| 850 |
"name": "Bar/test_3/test_3", |
| 851 |
"explained": True, |
| 852 |
"reason": "Big Sur is next to the Pacific.", |
| 853 |
} |
| 854 |
], |
| 855 |
), |
| 856 |
( |
| 857 |
dedent( |
| 858 |
"""\ |
| 859 |
# Foo |
| 860 |
|
| 861 |
* 1 test failed |
| 862 |
|
| 863 |
## Failed Tests |
| 864 |
(click on a test name to see its output) |
| 865 |
|
| 866 |
### Bar |
| 867 |
<details> |
| 868 |
<summary>Bar/test_3/test_3 (Likely Already Failing)</summary> |
| 869 |
Big Sur is next to the Pacific. |
| 870 |
|
| 871 |
``` |
| 872 |
Error! Expected Big Sur to be next to the ocean. |
| 873 |
``` |
| 874 |
</details> |
| 875 |
|
| 876 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 877 |
), |
| 878 |
True, |
| 879 |
), |
| 880 |
) |
| 881 |
|
| 882 |
def test_report_test_failure_have_explanation_explained_false(self): |
| 883 |
self.assertEqual( |
| 884 |
generate_test_report_lib.generate_report( |
| 885 |
"Foo", |
| 886 |
1, |
| 887 |
[ |
| 888 |
junit_from_xml( |
| 889 |
dedent( |
| 890 |
"""\ |
| 891 |
<?xml version="1.0" encoding="UTF-8"?> |
| 892 |
<testsuites time="8.89"> |
| 893 |
<testsuite name="Bar" tests="1" failures="1" skipped="0" time="410.63"> |
| 894 |
<testcase classname="Bar/test_3" name="test_3" time="0.02"> |
| 895 |
<failure><![CDATA[Error! Expected Mt. Shasta to be next in the Eastern Sierras.]]></failure> |
| 896 |
</testcase> |
| 897 |
</testsuite> |
| 898 |
</testsuites>""" |
| 899 |
) |
| 900 |
) |
| 901 |
], |
| 902 |
[], |
| 903 |
failure_explanations_list=[ |
| 904 |
{ |
| 905 |
"name": "Bar/test_3/test_3", |
| 906 |
"explained": False, |
| 907 |
"reason": "Mt. Shasta is in the Cascades", |
| 908 |
} |
| 909 |
], |
| 910 |
), |
| 911 |
( |
| 912 |
dedent( |
| 913 |
"""\ |
| 914 |
# Foo |
| 915 |
|
| 916 |
* 1 test failed |
| 917 |
|
| 918 |
## Failed Tests |
| 919 |
(click on a test name to see its output) |
| 920 |
|
| 921 |
### Bar |
| 922 |
<details> |
| 923 |
<summary>Bar/test_3/test_3</summary> |
| 924 |
|
| 925 |
``` |
| 926 |
Error! Expected Mt. Shasta to be next in the Eastern Sierras. |
| 927 |
``` |
| 928 |
</details> |
| 929 |
|
| 930 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 931 |
), |
| 932 |
False, |
| 933 |
), |
| 934 |
) |
| 935 |
|
| 936 |
def test_generate_report_end_to_end(self): |
| 937 |
with tempfile.TemporaryDirectory() as temp_dir: |
| 938 |
junit_xml_file = os.path.join(temp_dir, "junit.xml") |
| 939 |
with open(junit_xml_file, "w") as junit_xml_handle: |
| 940 |
junit_xml_handle.write( |
| 941 |
dedent( |
| 942 |
"""\ |
| 943 |
<?xml version="1.0" encoding="UTF-8"?> |
| 944 |
<testsuites time="0.00"> |
| 945 |
<testsuite name="Passed" tests="1" failures="0" skipped="0" time="0.00"> |
| 946 |
<testcase classname="Bar/test_1" name="test_1" time="0.00"/> |
| 947 |
</testsuite> |
| 948 |
</testsuites>""" |
| 949 |
) |
| 950 |
) |
| 951 |
ninja_log_file = os.path.join(temp_dir, "ninja.log") |
| 952 |
with open(ninja_log_file, "w") as ninja_log_handle: |
| 953 |
ninja_log_handle.write( |
| 954 |
dedent( |
| 955 |
"""\ |
| 956 |
[1/5] test/1.stamp |
| 957 |
[2/5] test/2.stamp |
| 958 |
[3/5] test/3.stamp |
| 959 |
[4/5] test/4.stamp |
| 960 |
FAILED: test/4.stamp |
| 961 |
touch test/4.stamp |
| 962 |
Wow! That's so True! |
| 963 |
[5/5] test/5.stamp""" |
| 964 |
) |
| 965 |
) |
| 966 |
self.assertEqual( |
| 967 |
generate_test_report_lib.generate_report_from_files( |
| 968 |
"Foo", 1, [junit_xml_file, ninja_log_file] |
| 969 |
), |
| 970 |
( |
| 971 |
dedent( |
| 972 |
"""\ |
| 973 |
# Foo |
| 974 |
|
| 975 |
* 1 test passed |
| 976 |
|
| 977 |
All executed tests passed, but another part of the build **failed**. Click on a failure below to see the details. |
| 978 |
|
| 979 |
<details> |
| 980 |
<summary>test/4.stamp</summary> |
| 981 |
|
| 982 |
``` |
| 983 |
FAILED: test/4.stamp |
| 984 |
touch test/4.stamp |
| 985 |
Wow! That's so True! |
| 986 |
``` |
| 987 |
</details> |
| 988 |
|
| 989 |
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.""" |
| 990 |
), |
| 991 |
False, |
| 992 |
), |
| 993 |
) |