Ticket #156: patch
File patch, 10.6 KB (added by , 17 years ago) |
---|
-
tests/harness/testsuite.h
74 74 // needless generation of diagnostic output in cases when it's expensive. 75 75 extern bool verbose; 76 76 77 /// A global flag which a test should set if it knows that it's going to fail 78 /// in a particular situation. Known failures will not cause the test suite to 79 /// fail, but will be listed at the end of the test run. 80 extern bool global_known_failure; 81 77 82 /// The exception type we were expecting in TEST_EXCEPTION. 78 83 // Used to detect if such an exception was mishandled by a the 79 84 // compiler/runtime. … … 97 102 /// The number of tests which failed. 98 103 unsigned int failed; 99 104 100 /// The number of tests which were skipped 105 /// The number of tests which were skipped. 101 106 unsigned int skipped; 107 108 /// The number of known failures which occurred. 109 unsigned int known_failures; 110 111 /// The number of tests marked as known failures which failed to fail. 112 unsigned int known_failures_passed; 102 113 }; 103 114 104 115 /** Add a test-specific command line option. … … 154 165 test_driver(const test_driver &); 155 166 test_driver & operator = (const test_driver &); 156 167 157 typedef enum { PASS = 1, FAIL = 0, SKIP = -1 } test_result;168 typedef enum { KNOWN_FAIL_PASSED=3, KNOWN_FAIL=2, PASS = 1, FAIL = 0, SKIP = -1 } test_result; 158 169 159 170 static std::map<int, std::string *> short_opts; 160 171 … … 250 261 "Expected `"STRINGIZE(a)"' and `"STRINGIZE(b)"' not to be equal:" \ 251 262 " were " << (a) << " and " << (b)) 252 263 264 /// Mark a test as known-to-fail. This is intended to be used temporarily to / 265 /// mark tests for known bugs before the bugs are fixed. The test failure will 266 /// be displayed as a known failure, and not cause the test suite to return a 267 /// failure code. It should be called from inside the testcase. If the case 268 /// is only known to fail in certain situations (for example, only for some 269 /// backends), the macro can be called only in those situations. 270 #define KNOWN_FAILURE do { global_known_failure = 1; } while (0) 271 253 272 #endif // OM_HGUARD_TESTSUITE_H -
tests/harness/testsuite.cc
64 64 /// The global verbose flag. 65 65 bool verbose; 66 66 67 /// A global flag which a test should set if it knows that it's going to fail 68 /// in a particular situation. Known failures will not cause the test suite to 69 /// fail, but will be listed at the end of the test run. 70 bool global_known_failure; 71 67 72 #ifdef HAVE_VALGRIND 68 73 static int vg_log_fd = -1; 69 74 #endif … … 78 83 om_ostringstream tout; 79 84 80 85 int test_driver::runs = 0; 81 test_driver::result test_driver::total = {0, 0, 0 };86 test_driver::result test_driver::total = {0, 0, 0, 0, 0}; 82 87 string test_driver::argv0; 83 88 string test_driver::opt_help; 84 89 map<int, string *> test_driver::short_opts; … … 198 203 // If this test driver is used for anything other than 199 204 // Xapian tests, then this ought to be provided by 200 205 // the client, really. 201 // return: test_driver::PASS, test_driver::FAIL, or test_driver::SKIP 206 // return: test_driver::PASS, test_driver::FAIL, test_driver::SKIP, 207 // test_driver::KNOWN_FAIL or test_driver::KNOWN_FAIL_PASSED 202 208 test_driver::test_result 203 209 test_driver::runtest(const test_desc *test) 204 210 { … … 339 345 if (s[s.size() - 1] != '\n') out << endl; 340 346 tout.str(""); 341 347 } 342 out << " " << col_red << "FAILED" << col_reset; 343 return FAIL; 348 if (global_known_failure) { 349 out << " " << col_yellow << "KNOWN FAILURE" << col_reset; 350 return KNOWN_FAIL; 351 } else { 352 out << " " << col_red << "FAILED" << col_reset; 353 return FAIL; 354 } 344 355 } catch (const TestSkip &) { 345 356 string s = tout.str(); 346 357 if (!s.empty()) { … … 362 373 if (s[s.size() - 1] != '\n') out << endl; 363 374 tout.str(""); 364 375 } 365 out << " " << col_red << errclass << col_reset; 376 if (global_known_failure) { 377 out << " " << col_yellow << "KNOWN FAILURE: " << errclass << col_reset << endl; 378 } else { 379 out << " " << col_red << errclass << col_reset; 380 } 366 381 if (verbose) { 367 382 out << err.get_type() << " exception: " << err.get_msg(); 368 383 if (!err.get_context().empty()) … … 371 386 out << " (" << err.get_error_string() << ")"; 372 387 out << endl; 373 388 } 389 if (global_known_failure) { 390 return KNOWN_FAIL; 391 } 374 392 return FAIL; 375 393 } catch (const string & msg) { 376 394 string s = tout.str(); … … 379 397 if (s[s.size() - 1] != '\n') out << endl; 380 398 tout.str(""); 381 399 } 382 out << " " << col_red << "EXCEPTION: "; 400 if (global_known_failure) { 401 out << " " << col_yellow << "KNOWN FAILURE: EXCEPTION: " << col_reset; 402 } else { 403 out << " " << col_red << "EXCEPTION: "; 404 } 383 405 size_t cutoff = min(size_t(40), msg.size()); 384 406 cutoff = find(msg.begin(), msg.begin() + cutoff, '\n') - msg.begin(); 385 407 if (cutoff == msg.size()) out << msg; else out << msg.substr(0, cutoff) << "..."; … … 387 409 if (verbose && cutoff != msg.size()) { 388 410 out << msg << endl; 389 411 } 412 if (global_known_failure) { 413 return KNOWN_FAIL; 414 } 390 415 return FAIL; 391 416 } catch (...) { 392 417 string s = tout.str(); … … 395 420 if (s[s.size() - 1] != '\n') out << endl; 396 421 tout.str(""); 397 422 } 398 out << " " << col_red << "UNKNOWN EXCEPTION" << col_reset; 399 return FAIL; 423 if (global_known_failure) { 424 out << " " << col_yellow << "KNOWN FAILURE: UNKNOWN EXCEPTION" << col_reset; 425 return KNOWN_FAIL; 426 } else { 427 out << " " << col_red << "UNKNOWN EXCEPTION" << col_reset; 428 return FAIL; 429 } 400 430 } 401 431 } else { 402 432 // caught signal … … 418 448 case SIGSTKFLT: signame = "SIGSTKFLT"; break; 419 449 #endif 420 450 } 421 out << " " << col_red << signame << col_reset; 422 return FAIL; 451 if (global_known_failure) { 452 out << " " << col_yellow << "KNOWN FAILURE: " << signame << col_reset; 453 return KNOWN_FAIL; 454 } else { 455 out << " " << col_red << signame << col_reset; 456 return FAIL; 457 } 423 458 } 459 if (global_known_failure) { 460 out << col_red << " KNOWN FAILURE PASSED" << col_reset; 461 return KNOWN_FAIL_PASSED; 462 } 424 463 return PASS; 425 464 } 426 465 } … … 446 485 set<string> m(b, e); 447 486 bool check_name = !m.empty(); 448 487 449 test_driver::result res = {0, 0, 0 };488 test_driver::result res = {0, 0, 0, 0, 0}; 450 489 451 490 for (const test_desc *test = tests; test->name; test++) { 452 491 bool do_this_test = !check_name; … … 466 505 if (do_this_test) { 467 506 out << "Running test: " << test->name << "..."; 468 507 out.flush(); 508 global_known_failure = 0; 469 509 switch (runtest(test)) { 470 510 case PASS: 471 511 ++res.succeeded; … … 475 515 out << "\r \r"; 476 516 } 477 517 break; 518 case KNOWN_FAIL: 519 ++res.known_failures; 520 out << endl; 521 break; 478 522 case FAIL: 479 523 ++res.failed; 480 524 out << endl; … … 483 527 return res; 484 528 } 485 529 break; 530 case KNOWN_FAIL_PASSED: 531 ++res.known_failures_passed; 532 out << endl; 533 if (abort_on_error) { 534 out << "Test passed, but marked as a known failure - aborting further tests." << endl; 535 return res; 536 } 537 break; 486 538 case SKIP: 487 539 ++res.skipped; 488 540 out << endl; … … 509 561 if (r.succeeded != 0 || r.failed != 0) { 510 562 cout << argv0 << " " << desc << ": "; 511 563 512 if (r.failed == 0 )564 if (r.failed == 0 && r.known_failures_passed == 0) 513 565 cout << "All "; 514 566 515 567 cout << col_green << r.succeeded << col_reset << " tests passed"; … … 517 569 if (r.failed != 0) 518 570 cout << ", " << col_red << r.failed << col_reset << " failed"; 519 571 572 if (r.known_failures_passed != 0) 573 cout << ", " << col_red << r.known_failures_passed << col_reset << " known failures passed"; 574 575 if (r.known_failures != 0) 576 cout << ", " << col_yellow << r.known_failures << col_reset << " known failures"; 577 520 578 if (r.skipped) { 521 579 cout << ", " << col_yellow << r.skipped << col_reset 522 580 << " skipped." << endl; … … 655 713 total.succeeded += myresult.succeeded; 656 714 total.failed += myresult.failed; 657 715 total.skipped += myresult.skipped; 716 total.known_failures += myresult.known_failures; 717 total.known_failures_passed += myresult.known_failures_passed; 658 718 659 return bool(myresult.failed ); // if 0, then everything passed719 return bool(myresult.failed || myresult.known_failures_passed); // if 0, then everything passed 660 720 } 661 721 662 722 bool -
tests/queryparsertest.cc
1062 1062 // Test NumberValueRangeProcessors with actual data.. 1063 1063 static bool test_qp_value_range3() 1064 1064 { 1065 // This test currently fails because the numeric range stuff doesn't yet 1066 // marshall the numbers into a representation which sorts in string order 1067 // corrently. 1068 KNOWN_FAILURE; 1069 1065 1070 Xapian::WritableDatabase db(Xapian::InMemory::open()); 1066 1071 int low = 0; // FIXME - should it work with negative numbers? 1067 1072 // If so, test it with some by setting low to -10 1068 int high = 9; // Currently the test passes if high is 9, but not if it is 10.1073 int high = 10; 1069 1074 1070 1075 for (int i = low; i <= high; ++i) { 1071 1076 Xapian::Document doc; -
HACKING
856 856 changes stop it working as intended. 857 857 * If you've fixed a bug, make sure there's a regression test which 858 858 fails on the existing code and succeeds after your changes. 859 * If you're adding a new testcase to exhibit an existing bug, and not checking 860 a fix in at the same time, mark the testcase as a known failure (by calling 861 the macro "KNOWN_FAILURE" somewhere in your testcase), so that the build 862 continues to succeed. This allows the automated build systems to continue 863 to work, whilst displaying the error to developers. Fixing the bug is then 864 a priority - we can't generally make a release while there are known 865 failures. Note that failures which are due to valgrind finding memory 866 errors are not affected by this macro, because this would cause the 867 testsuite to fail for users without valgrind. Also, test failures which are 868 only shown by valgrind won't cause problems for the automated builds, which 869 don't currently use valgrind. 859 870 * Make sure all existing tests continue to pass. 860 871 861 872 If you don't know how to write tests using the Xapian test rig, then