Lumiera  0.pre.03
»edit your freedom«
test-option-test.cpp
Go to the documentation of this file.
1 /*
2  TestOption(Test) - parsing of cmd line options for running Testcases
3 
4  Copyright (C)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/test/test-helper.hpp"
21 #include "lib/test/testoption.hpp"
22 #include "lib/format-cout.hpp"
23 #include "lib/util.hpp"
24 
25 #include <memory>
26 
27 using std::make_unique;
28 using lib::Cmdline;
29 using util::isnil;
30 
31 namespace test {
32 
33  /************************************************************/
39  class TestOption_test : public Test
40  {
41  void
42  run (Arg)
43  {
44  noOptions();
45  help();
46  groupID();
47  singleTest();
48  groupFilter1();
49  groupFilter2();
50  additionalCmd();
51  additionalCmd2();
52  verify_seed();
53  }
54 
55 
57  auto
58  doIt (const string cmdline)
59  {
60  cout << "Testing invocation with cmdline: " << cmdline << "..." << endl;
61 
62  Cmdline args(cmdline);
63  auto optparser = make_unique<TestOption>(args);
64  const string testID = optparser->getTestID();
65  cout << "--> Testgroup=" << optparser->getTestgroup() << endl;
66  cout << "--> Test-ID =" << (isnil(testID)? "--missing--" : testID ) << endl;
67  cout << "--> remaining=" << args << endl;
68  return std::move (optparser);
69  }
70 
71  void noOptions() { doIt (""); }
72  void help() { doIt ("--help"); }
73  void groupID() { doIt ("--group TestGroupID"); }
74  void singleTest() { doIt (" SingleTestID"); }
75  void groupFilter1() { doIt (" SingleTestID --group TestGroupID"); }
76  void groupFilter2() { doIt (" --group TestGroupID SingleTestID "); }
77  void additionalCmd() { doIt (" --group TestGroupID SingleTestID spam eggs"); }
78  void additionalCmd2() { doIt ("\t\tSingleTestID spam --group TestGroupID \t --eggs"); }
79 
80  void
81  verify_seed()
82  {
83  CHECK ( not doIt("ham --group spam")->optSeed());
84  CHECK (7 == * doIt("ham --seed 7 spam")->optSeed());
85  CHECK (0 == * doIt("ham --seed 0 spam")->optSeed());
86 
87  VERIFY_FAIL("argument (\'spam\') for option \'--seed\' is invalid"
88  , doIt("ham --seed spam"));
89 
90  // yet negative numbers are parsed and force-converted
91  CHECK (std::numeric_limits<uint64_t>::max()
92  == * doIt("--seed=-1")->optSeed());
93  }
94  };
95 
96  LAUNCHER (TestOption_test, "function common");
97 
98 
99 } // namespace test
invokes the TestOption parser for various example commandlines
Commandline options for our unittest test-suite executable.
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
Abstract Base Class for all testcases.
Definition: run.hpp:53
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Abstraction of the usual int argc, int** argv-Commandline, to be able to treat it as a vector of stri...
Definition: cmdline.hpp:48
auto doIt(const string cmdline)
#define VERIFY_FAIL(FAILURE_MSG, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises a std::exception, which additionally contains some FAI...