Added tests for various Arg properties such as invalid flag/names and

DocBookOutput
This commit is contained in:
Daniel Aarno 2012-05-17 22:12:08 +02:00
parent a5e1c09cef
commit b60f3c14d1
9 changed files with 264 additions and 4 deletions

View File

@ -1,7 +1,7 @@
noinst_PROGRAMS = test1 test2 test3 test4 test5 test6 test7 test8 test9 \ noinst_PROGRAMS = test1 test2 test3 test4 test5 test6 test7 test8 test9 \
test10 test11 test12 test13 test14 test15 test16 \ test10 test11 test12 test13 test14 test15 test16 \
test17 test18 test19 test20 test21 test22 test23 test17 test18 test19 test20 test21 test22 test23 test24 test25
test1_SOURCES = test1.cpp test1_SOURCES = test1.cpp
test2_SOURCES = test2.cpp test2_SOURCES = test2.cpp
@ -26,6 +26,8 @@ test20_SOURCES = test20.cpp
test21_SOURCES = test21.cpp test21_SOURCES = test21.cpp
test22_SOURCES = test22.cpp test22_SOURCES = test22.cpp
test23_SOURCES = test23.cpp test23_SOURCES = test23.cpp
test24_SOURCES = test24.cpp
test25_SOURCES = test25.cpp
AM_CPPFLAGS = -I$(top_srcdir)/include AM_CPPFLAGS = -I$(top_srcdir)/include

67
examples/test24.cpp Normal file
View File

@ -0,0 +1,67 @@
// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
// Test various Arg properties such as invalid flag/names
#include "tclap/CmdLine.h"
using namespace TCLAP;
using namespace std;
int main() {
CmdLine cmd("Command description message", ' ', "0.9");
try { // Argument with two character 'flag'
ValueArg<string> nameArg("nx","name","Name to print",true,
"homer","string");
return EXIT_FAILURE;
} catch(SpecificationException e) {
cout << e.what() << std::endl; // Expected
}
try { // space as flag
ValueArg<string> nameArg(" ","name","Name to print",true,
"homer","string");
return EXIT_FAILURE;
} catch(SpecificationException e) {
cout << e.what() << std::endl; // Expected
}
try { // - as flag
ValueArg<string> nameArg("-","name","Name to print",true,
"homer","string");
return EXIT_FAILURE;
} catch(SpecificationException e) {
cout << e.what() << std::endl; // Expected
}
try { // -- as flag
ValueArg<string> nameArg("--","name","Name to print",true,
"homer","string");
return EXIT_FAILURE;
} catch(SpecificationException e) {
cout << e.what() << std::endl; // Expected
}
try { // space as name
ValueArg<string> nameArg("n"," ","Name to print",true,
"homer","string");
return EXIT_FAILURE;
} catch(SpecificationException e) {
cout << e.what() << std::endl; // Expected
}
try { // - as flag
ValueArg<string> nameArg("n","-","Name to print",true,
"homer","string");
return EXIT_FAILURE;
} catch(SpecificationException e) {
cout << e.what() << std::endl; // Expected
}
try { // -- as flag
ValueArg<string> nameArg("n","--","Name to print",true,
"homer","string");
return EXIT_FAILURE;
} catch(SpecificationException e) {
cout << e.what() << std::endl; // Expected
}
}

37
examples/test25.cpp Normal file
View File

@ -0,0 +1,37 @@
// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
#include "tclap/CmdLine.h"
#include "tclap/DocBookOutput.h"
#include "tclap/ZshCompletionOutput.h"
#include <iostream>
#include <string>
using namespace TCLAP;
using namespace std;
int main(int argc, char** argv)
{
CmdLine cmd("this is a message", ' ', "0.99" );
DocBookOutput docoutput;
ZshCompletionOutput zshoutput;
CmdLineOutput *output = &zshoutput;
if (argc > 2)
output = &docoutput;
cmd.setOutput(output);
SwitchArg btest("B","sB", "exist Test B", false);
MultiArg<int> atest("A","sA", "exist Test A", false, "integer");
ValueArg<string> stest("s", "Bs", "string test", true, "homer",
"string");
cmd.xorAdd(stest, btest);
cmd.add( atest );
cmd.parse(argc,argv);
}

View File

@ -81,7 +81,9 @@ TESTS = test1.sh \
test79.sh \ test79.sh \
test80.sh \ test80.sh \
test81.sh \ test81.sh \
test82.sh test82.sh \
test83.sh \
test84.sh
EXTRA_DIST = $(TESTS) \ EXTRA_DIST = $(TESTS) \
test1.out \ test1.out \
@ -165,6 +167,8 @@ EXTRA_DIST = $(TESTS) \
test79.out \ test79.out \
test80.out \ test80.out \
test81.out \ test81.out \
test82.out test82.out \
test83.out \
test84.out
CLEANFILES = tmp.out CLEANFILES = tmp.out

View File

@ -6,7 +6,7 @@ cd $DIR
let "suc = 0" let "suc = 0"
let "fail = 0" let "fail = 0"
NUMTEST=82 NUMTEST=84
for (( tno = 1 ; $tno <= $NUMTEST ; tno = $tno + 1 )); do for (( tno = 1 ; $tno <= $NUMTEST ; tno = $tno + 1 )); do
./testCheck.sh $tno ./testCheck.sh $tno

7
tests/test83.out Normal file
View File

@ -0,0 +1,7 @@
-nx (--name) -- Argument flag can only be one character long
- (--name) -- Argument flag cannot be either '-' or '--' or a space.
-- (--name) -- Argument flag cannot be either '-' or '--' or a space.
--- (--name) -- Argument flag can only be one character long
-n (-- ) -- Argument name begin with either '-' or '--' or space.
-n (---) -- Argument name begin with either '-' or '--' or space.
-n (----) -- Argument name begin with either '-' or '--' or space.

11
tests/test83.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
# success
../examples/test24 > tmp.out 2>&1
if cmp -s tmp.out $srcdir/test83.out; then
exit 0
else
exit 1
fi

119
tests/test84.out Normal file
View File

@ -0,0 +1,119 @@
<?xml version='1.0'?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<refentry>
<refmeta>
<refentrytitle>test25</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>
<refnamediv>
<refname>test25</refname>
<refpurpose>this is a message</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>test25</command>
<group choice='req'>
<arg choice='plain'>-s <replaceable>string</replaceable></arg>
<arg choice='plain'>-B</arg>
</group>
<arg choice='opt' rep='repeat'>-A <replaceable></replaceable></arg>
<arg choice='opt'>--</arg>
<arg choice='opt'>--version</arg>
<arg choice='opt'>-h</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
this is a message
</para>
</refsect1>
<refsect1>
<title>Options</title>
<variablelist>
<varlistentry>
<term>
<option>-A</option>
</term>
<term>
<option>--sA <replaceable></replaceable></option>
</term>
<listitem>
<para>
exist Test A
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-B</option>
</term>
<term>
<option>--sB</option>
</term>
<listitem>
<para>
(OR required) exist Test B
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-s</option>
</term>
<term>
<option>--Bs <replaceable>string</replaceable></option>
</term>
<listitem>
<para>
(OR required) string test
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--</option>
</term>
<term>
<option>--ignore_rest</option>
</term>
<listitem>
<para>
Ignores the rest of the labeled arguments following this flag.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--version</option>
</term>
<listitem>
<para>
Displays version information and exits.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-h</option>
</term>
<term>
<option>--help</option>
</term>
<listitem>
<para>
Displays usage information and exits.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Version</title>
<para>
0.99
</para>
</refsect1>
</refentry>

13
tests/test84.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
# docbookoutput. The when this test fails due to e.g. formatting
# changes the results needs to be manually reviewed and the test81.out
# updated
../examples/test25 -h x > tmp.out 2>&1
if cmp -s tmp.out $srcdir/test84.out; then
exit 0
else
exit 1
fi