Changeset 1162


Ignore:
Timestamp:
Aug 13, 2010, 7:30:03 PM (9 years ago)
Author:
Peter Johansson
Message:

new function exit_status in Suite and use it in all C++ tests

Location:
trunk/test
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Suite.cc

    r1119 r1162  
    5656      if (!have_test_repo) {
    5757        out() << "Skipping test because test repository is not available\n";
    58         exit (77);
     58        ::exit (77);
    5959      }
    6060      update_test_wc();
     
    7373    ok_ = ok_ && b;
    7474    return b;
     75  }
     76
     77
     78  int Suite::exit_status(void) const
     79  {
     80    int value = EXIT_FAILURE;
     81    if (ok()) {
     82      value = EXIT_SUCCESS;
     83    }
     84    out() << "exit status: " << value << "\n";
     85    return value;
    7586  }
    7687
  • trunk/test/Suite.h

    r1044 r1162  
    4949
    5050    /**
     51       \return EXIT_FAILURE or EXIT_SUCCESS depending on ok()
     52     */
     53    int exit_status(void) const;
     54
     55    /**
    5156       \return true if all tests are OK
    5257     */
  • trunk/test/cache_partial_test.cc

    r1124 r1162  
    8383  is.close();
    8484
    85   if (suite.ok()) {
    86     suite.out() << "Test is OK\n";
    87     return 0;
    88   }
    89   suite.out() << "Test failed\n";
    90   return 1;
     85  return suite.exit_status();
    9186}
    9287
  • trunk/test/color_test.cc

    r1127 r1162  
    2121*/
    2222
     23#include "Suite.h"
     24
    2325#include "lib/Colors.h"
    2426
     
    2931{
    3032  using namespace theplu::svndigest;
    31   bool ok=true;
     33  test::Suite suite(argc, argv);
    3234
    3335  // The loop adds new authors to the author color map until all
     
    4850  // Test first and last color, expected to be the same.
    4951  if (r!=r_first || g!=g_first || b!=b_first) {
    50     ok=false;
     52    suite.add(false);
    5153    std::cerr << "Expected r,g,b "
    5254              << static_cast<int>(r_first) << ','
     
    5961  }
    6062
    61   if (ok)
    62     return 0;
    63   return -1;
     63 
     64  return suite.exit_status();
    6465}
  • trunk/test/config_test.cc

    r1152 r1162  
    4242  test_props(suite);
    4343                                                                               
    44   if (suite.ok()) {
    45     suite.out() << "Test is Ok!" << std::endl;
    46     return 0;
    47   }
    48   suite.out() << "Test failed." << std::endl;
    49   return 1;
     44  return suite.exit_status();
    5045}
    5146
  • trunk/test/copyright_test.cc

    r1119 r1162  
    126126  os.close();
    127127
    128   if (suite.ok()) {
    129     suite.out() << "Test is Ok!" << std::endl;
    130     return 0;
    131   }
    132   suite.out() << "Test failed." << std::endl;
    133   return 1;
     128  return suite.exit_status();
    134129}
    135130
  • trunk/test/date_test.cc

    r1127 r1162  
    2121*/
    2222
     23#include "Suite.h"
     24
    2325#include "lib/Date.h"
    2426
     
    2628#include <string>
    2729
    28 int main(const int argc,const char* argv[])
     30int main(int argc, char* argv[])
    2931{
    3032  using namespace theplu::svndigest;
    31   bool ok=true;
     33  test::Suite suite(argc, argv);
    3234
    3335  Date date("2007-06-27T15:40:52.123456Z");
    3436  if (date("%H:%M")!="15:40"){
    35     ok = false;
     37    suite.add(false);
    3638    std::cerr << "date(\"%H:%M\") returns: " << date("%H:%M")
    3739              << "\nexpected '15:40'" << std::endl;
    3840  }
    3941     
    40   if (ok)
    41     return 0;
    42   return -1;
     42  return suite.exit_status();
    4343}
    4444
  • trunk/test/htmlstream_test.cc

    r1127 r1162  
    3939  test_stream("&", "&amp;", suite);
    4040
    41   if (suite.ok())
    42     return 0;
    43   return 1;
     41  return suite.exit_status();
    4442}
    4543
  • trunk/test/parser_test.cc

    r1127 r1162  
    2222*/
    2323
     24#include "Suite.h"
     25
    2426#include "lib/LineTypeParser.h"
    2527
     
    2931bool test(const std::string&, std::ostream&);
    3032
    31 int main(const int argc,const char* argv[])
     33
     34int main(int argc, char* argv[])
    3235{
     36  theplu::svndigest::test::Suite suite(argc, argv);
    3337  bool ok=true;
    3438  std::ofstream os("parser.tmp");
    35   ok = ok && test("parser.cc",os);
    36   ok = ok && test("Makefile.am",os);
    37   ok = ok && test("../INSTALL",os);
    38   return 0;
     39  suite.add(test("parser.cc",os));
     40  suite.add(test("Makefile.am",os));
     41  suite.add(test("../INSTALL",os));
     42  return suite.exit_status();
    3943}
    4044
  • trunk/test/stats_test.cc

    r1124 r1162  
    6262
    6363  bool verbose=suite.verbose();
    64   bool ok=true;
    6564
    6665  SVN* svn=SVN::instance("toy_project");
     
    7069  }
    7170
    72   ok &= test_add(suite);
    73   ok &= test_blame(suite);
    74   ok &= test_classic(suite);
     71  suite.add(test_add(suite));
     72  suite.add(test_blame(suite));
     73  suite.add(test_classic(suite));
    7574                                                                               
    76   if (verbose) {
    77     if (ok)
    78       std::cout << "Test is ok.\n";
    79     else
    80       std::cout << "Test failed.\n";
    81   }
    82   if (ok)
    83     return 0;
    84   return 1;
     75  return suite.exit_status();
    8576}
    8677
  • trunk/test/trac_test.cc

    r1127 r1162  
    3737{
    3838  using namespace theplu::svndigest;
     39  test::Suite suite(argc, argv);
    3940  bool ok=true;
    4041  std::ostream& my_out(std::cout);
     
    8889  ok &= test_no_anchor("r2:3a", my_out);
    8990
    90   if (ok)
    91     return 0;
    92   return -1;
     91  suite.add(ok);
     92  return suite.exit_status();
    9393}
    9494
  • trunk/test/utility_test.cc

    r1098 r1162  
    2121*/
    2222
    23 #include "../lib/utility.h"
     23#include "Suite.h"
     24
     25#include "lib/utility.h"
    2426
    2527#include <algorithm>
     
    3335                 const std::vector<std::string>&);
    3436
    35 int main(const int argc,const char* argv[])
     37int main(int argc, char* argv[])
    3638{
     39  theplu::svndigest::test::Suite suite(argc, argv);
    3740  bool ok=true;
    3841 
     
    9497  ok &= test_regexp(true, "[fa]il?name", "filename", vec);
    9598
    96   if (ok)
    97     return 0;
    98   return 1;
     99  suite.add(ok);
     100  return suite.exit_status();
    99101}
    100102
Note: See TracChangeset for help on using the changeset viewer.