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) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/test/testoption.hpp"
30 #include "lib/format-cout.hpp"
31 #include "lib/util.hpp"
32 
33 
34 using lib::Cmdline;
35 using util::isnil;
36 
37 namespace test {
38 
39  /************************************************************/
45  class TestOption_test : public Test
46  {
47  void
48  run (Arg)
49  {
50  noOptions();
51  help();
52  groupID();
53  singleTest();
54  groupFilter1();
55  groupFilter2();
56  additionalCmd();
57  additionalCmd2();
58  }
59 
60 
62  void doIt (const string cmdline)
63  {
64  cout << "Testing invocation with cmdline: " << cmdline << "..." << endl;
65 
66  Cmdline args(cmdline);
67  TestOption optparser (args);
68  const string testID = optparser.getTestID();
69  cout << "--> Testgroup=" << optparser.getTestgroup() << endl;
70  cout << "--> Test-ID =" << (isnil(testID)? "--missing--" : testID ) << endl;
71  cout << "--> remaining=" << args << endl;
72  }
73 
74  void noOptions() { doIt (""); }
75  void help() { doIt ("--help"); }
76  void groupID() { doIt ("--group TestGroupID"); }
77  void singleTest() { doIt (" SingleTestID"); }
78  void groupFilter1() { doIt (" SingleTestID --group TestGroupID"); }
79  void groupFilter2() { doIt (" --group TestGroupID SingleTestID "); }
80  void additionalCmd() { doIt (" --group TestGroupID SingleTestID spam eggs"); }
81  void additionalCmd2() { doIt ("\t\tSingleTestID spam --group TestGroupID \t --eggs"); }
82 
83  };
84 
85  LAUNCHER (TestOption_test, "function common");
86 
87 
88 } // 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:49
void doIt(const string cmdline)
const string getTestID()
Definition: testoption.cpp:101
Abstract Base Class for all testcases.
Definition: run.hpp:62
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
const string getTestgroup()
Definition: testoption.cpp:92
Support for selecting and configuring testcases via commandline arguments.
Definition: testoption.hpp:59
Abstraction of the usual int argc, int** argv-Commandline, to be able to treat it as a vector of stri...
Definition: cmdline.hpp:57