2
0
mirror of https://github.com/boostorg/wave.git synced 2026-02-21 03:22:16 +00:00

Wave test application now properly supports config files. Fixed minor issues.

[SVN r27944]
This commit is contained in:
Hartmut Kaiser
2005-04-03 15:22:13 +00:00
parent 71ab18563c
commit bbf85da3ea
11 changed files with 133 additions and 105 deletions

View File

@@ -25,34 +25,12 @@ SOURCES = testwave testwave_app
#
# This are the arguments for the testwave executable
#
TESTWAVE_ARGUMENTS = -d2 -S../testwave/testfiles/ ;
TESTWAVE_ARGUMENTS = -d2 -S../testwave/testfiles ;
#
# These are the names of the different unit tests to run
#
TESTWAVE_FILES_001 =
001_001.cpp 001_002.cpp 001_003.cpp 001_004.cpp 001_005.cpp
001_006.cpp 001_007.cpp 001_008.cpp 001_009.cpp 001_010.cpp
001_011.cpp 001_012.cpp 001_013.cpp 001_014.cpp 001_015.cpp
001_016.cpp 001_017.cpp 001_018.cpp 001_019.cpp 001_020.cpp
001_021.cpp 001_022.cpp 001_023.cpp 001_024.cpp 001_025.cpp
001_026.cpp 001_027.cpp 001_028.cpp 001_029.cpp 001_030.cpp
001_031.cpp 001_032.cpp 001_033.cpp
;
TESTWAVE_FILES_002 =
002_001.cpp 002_002.cpp 002_003.cpp 002_004.cpp 002_005.cpp
002_006.cpp 002_007.cpp 002_008.cpp 002_009.cpp 002_010.cpp
002_011.cpp 002_012.cpp 002_013.cpp
;
TESTWAVE_FILES_003 =
003_001.cpp 003_002.cpp 003_003.cpp 003_004.cpp
;
TESTWAVE_FILES_999 =
999_001.cpp 999_002.cpp 999_003.cpp 999_004.cpp 999_005.cpp
999_006.cpp 999_007.cpp 999_008.cpp 999_009.cpp
TESTWAVE_FILES = test.cfg
;
#
@@ -80,37 +58,11 @@ test-suite wave
:
[
run
<template>wave-test # sources
../testwave/$(SOURCES).cpp
: $(TESTWAVE_ARGUMENTS) # arguments
: ../testwave/testfiles/$(TESTWAVE_FILES_001) # input files
: # requirements
: testwave # name
]
[
run
<template>wave-test # sources
../testwave/$(SOURCES).cpp
: $(TESTWAVE_ARGUMENTS) # arguments
: ../testwave/testfiles/$(TESTWAVE_FILES_002) # input files
: # requirements
: testwave # name
]
[
run
<template>wave-test # sources
../testwave/$(SOURCES).cpp
: $(TESTWAVE_ARGUMENTS) # arguments
: ../testwave/testfiles/$(TESTWAVE_FILES_003) # input files
: # requirements
: testwave # name
]
[
run
<template>wave-test # sources
../testwave/$(SOURCES).cpp
: $(TESTWAVE_ARGUMENTS) # arguments
: ../testwave/testfiles/$(TESTWAVE_FILES_999) # input files
<template>wave-test
../testwave/$(SOURCES).cpp # sources
: $(TESTWAVE_ARGUMENTS)
@../testwave/testfiles/$(TESTWAVE_FILES) # arguments
: # input files
: # requirements
: testwave # name
]

View File

@@ -56,7 +56,7 @@ namespace cmd_line_utils {
BOOST_ASSERT(p);
// Assume only one path per '-I' occurrence.
std::string t = tokens[0];
std::string const& t = po::validators::get_single_string(tokens);
if (t == "-") {
// found -I- option, so switch behaviour
p->seen_separator = true;
@@ -117,7 +117,8 @@ namespace cmd_line_utils {
<< std::endl;
return false;
}
// parse the file and extract all given arguments and options
std::vector<std::string> options;
std::string line;

View File

@@ -15,19 +15,19 @@ __STDC_VERSION__ //R __STDC_VERSION__
__cplusplus //R 199711L
__STDC_HOSTED__ //R __STDC_HOSTED__
__LINE__ //R 17
__FILE__ //R "003_002.cpp"
__BASE_FILE__ //R "003_002.cpp"
__FILE__ //R "$F"
__BASE_FILE__ //R "$F"
__WAVE_HAS_VARIADICS__ //R __WAVE_HAS_VARIADICS__
__INCLUDE_LEVEL__ //R 0
//R #line 50 "test.cpp"
#line 50 "test.cpp"
__LINE__ //R 50
__FILE__ //R "test.cpp"
__BASE_FILE__ //R "003_002.cpp"
__BASE_FILE__ //R "$F"
//R #line 56 "test.cpp"
__LINE__ //R 56
__FILE__ //R "test.cpp"
__BASE_FILE__ //R "003_002.cpp"
__BASE_FILE__ //R "$F"

View File

@@ -17,19 +17,19 @@ __STDC_VERSION__ //R __STDC_VERSION__
__cplusplus //R 199711L
__STDC_HOSTED__ //R __STDC_HOSTED__
__LINE__ //R 19
__FILE__ //R "003_003.cpp"
__BASE_FILE__ //R "003_003.cpp"
__FILE__ //R "$F"
__BASE_FILE__ //R "$F"
__WAVE_HAS_VARIADICS__ //R 1
__INCLUDE_LEVEL__ //R 0
//R #line 50 "test.cpp"
#line 50 "test.cpp"
__LINE__ //R 50
__FILE__ //R "test.cpp"
__BASE_FILE__ //R "003_003.cpp"
__BASE_FILE__ //R "$F"
//R #line 56 "test.cpp"
__LINE__ //R 56
__FILE__ //R "test.cpp"
__BASE_FILE__ //R "003_003.cpp"
__BASE_FILE__ //R "$F"

View File

@@ -17,19 +17,19 @@ __STDC_VERSION__ //R 199901L
__cplusplus //R __cplusplus
__STDC_HOSTED__ //R 0
__LINE__ //R 19
__FILE__ //R "003_004.cpp"
__BASE_FILE__ //R "003_004.cpp"
__FILE__ //R "$F"
__BASE_FILE__ //R "$F"
__WAVE_HAS_VARIADICS__ //R 1
__INCLUDE_LEVEL__ //R 0
//R #line 50 "test.cpp"
#line 50 "test.cpp"
__LINE__ //R 50
__FILE__ //R "test.cpp"
__BASE_FILE__ //R "003_004.cpp"
__BASE_FILE__ //R "$F"
//R #line 56 "test.cpp"
__LINE__ //R 56
__FILE__ //R "test.cpp"
__BASE_FILE__ //R "003_004.cpp"
__BASE_FILE__ //R "$F"

View File

@@ -15,12 +15,15 @@
// include boost
#include <boost/config.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
// test application related headers
#include "cmd_line_utils.hpp"
#include "testwave_app.hpp"
namespace po = boost::program_options;
namespace fs = boost::filesystem;
///////////////////////////////////////////////////////////////////////////////
//
@@ -73,9 +76,6 @@ main(int argc, char *argv[])
po::options_description cmdline_options;
cmdline_options.add(desc_cmdline).add(app.common_options());
po::options_description cfgfile_options;
cfgfile_options.add(desc_cmdline).add(desc_hidden);
// parse command line
po::parsed_options opts(po::parse_command_line(argc, argv,
cmdline_options, 0, cmd_line_utils::at_option_parser));
@@ -83,20 +83,6 @@ main(int argc, char *argv[])
po::store(opts, vm);
po::notify(vm);
// if there is specified at least one config file, parse it and add the
// options to the main variables_map
if (vm.count("config-file")) {
std::vector<std::string> const &cfg_files =
vm["config-file"].as<std::vector<std::string> >();
std::vector<std::string>::const_iterator end = cfg_files.end();
for (std::vector<std::string>::const_iterator cit = cfg_files.begin();
cit != end; ++cit)
{
// parse a single config file and store the results
cmd_line_utils::read_config_file(*cit, cfgfile_options, vm);
}
}
// ... act as required
if (vm.count("help")) {
po::options_description desc_help (
@@ -128,18 +114,45 @@ main(int argc, char *argv[])
return app.print_copyright();
}
// iterate over all given input files
// If there is specified at least one config file, parse it and add the
// options to the main variables_map
// Each of the config files is parsed into a separate variables_map to
// allow correct paths handling.
int input_count = 0;
if (vm.count("input")) {
std::vector<std::string> const &inputs =
vm["input"].as<std::vector<std::string> >();
std::vector<std::string>::const_iterator end = inputs.end();
for (std::vector<std::string>::const_iterator cit = inputs.begin();
if (vm.count("config-file")) {
std::vector<std::string> const &cfg_files =
vm["config-file"].as<std::vector<std::string> >();
std::vector<std::string>::const_iterator end = cfg_files.end();
for (std::vector<std::string>::const_iterator cit = cfg_files.begin();
cit != end; ++cit)
{
if (!app.test_a_file((*cit)))
++error_count;
++input_count;
// parse a single config file and store the results, config files
// may only contain --input and positional arguments
po::variables_map cvm;
cmd_line_utils::read_config_file(*cit, desc_hidden, cvm);
// correct the paths parsed into this variables_map
if (cvm.count("input")) {
std::vector<std::string> const &infiles =
cvm["input"].as<std::vector<std::string> >();
std::vector<std::string>::const_iterator iend = infiles.end();
for (std::vector<std::string>::const_iterator iit = infiles.begin();
iit != iend; ++iit)
{
// correct the file name (prepend the cfg file path)
fs::path cfgpath = fs::complete(
fs::path(*cit, fs::native), fs::current_path());
fs::path filepath =
cfgpath.branch_path() / fs::path(*iit, fs::native);
// execute this unit test case
if (!app.test_a_file(filepath.native_file_string()))
++error_count;
++input_count;
}
}
}
}
@@ -153,7 +166,8 @@ main(int argc, char *argv[])
for (std::vector<po::option>::const_iterator arg = arguments.begin();
arg != arg_end; ++arg)
{
if (!app.test_a_file((*arg).value[0]))
fs::path filepath((*arg).value[0], fs::native);
if (!app.test_a_file(filepath.native_file_string()))
++error_count;
++input_count;
}

View File

@@ -38,7 +38,7 @@ namespace fs = boost::filesystem;
///////////////////////////////////////////////////////////////////////////////
// testwave version definitions
#define TESTWAVE_VERSION_MAJOR 0
#define TESTWAVE_VERSION_MINOR 2
#define TESTWAVE_VERSION_MINOR 3
#define TESTWAVE_VERSION_SUBMINOR 0
///////////////////////////////////////////////////////////////////////////////
@@ -126,6 +126,49 @@ namespace {
return true;
}
///////////////////////////////////////////////////////////////////////////
//
// This function compares the real result and the expected one but first
// replaces all occurences of $F in the expected result to the passed
// full filepath.
//
///////////////////////////////////////////////////////////////////////////
inline bool
got_expected_result(std::string const& filename,
std::string const& result, std::string& expected)
{
using boost::wave::util::impl::escape_lit;
std::string full_result;
std::string::size_type pos = 0;
std::string::size_type pos1 = expected.find_first_of("$");
if (pos1 != std::string::npos) {
do {
switch(expected[pos1+1]) {
case 'F':
full_result = full_result +
expected.substr(pos, pos1-pos) + escape_lit(filename);
pos1 = expected.find_first_of ("$", pos = pos1 + 2);
break;
default:
full_result = full_result +
expected.substr(pos, pos1-pos);
pos1 = expected.find_first_of ("$", (pos = pos1) + 1);
break;
}
} while(pos1 != std::string::npos);
full_result += expected.substr(pos);
}
else {
full_result = expected;
}
expected = full_result;
return full_result == result;
}
}
///////////////////////////////////////////////////////////////////////////////
@@ -176,7 +219,7 @@ testwave_app::test_a_file(std::string filename)
bool pp_result = preprocess_file(filename, instr, result, error);
if (pp_result || !result.empty()) {
// no preprocessing error encountered
if (result != expected) {
if (!got_expected_result(filename, result, expected)) {
if (debuglevel > 3) {
std::cerr
<< filename << ": failed" << std::endl
@@ -204,7 +247,7 @@ testwave_app::test_a_file(std::string filename)
if (!extract_special_information(filename, instr, 'E', expected_error))
return false;
if (error != expected_error) {
if (!got_expected_result(filename, error, expected_error)) {
// the error was unexpected
if (debuglevel > 3) {
std::cerr