From 3f8fa64c9a78f7261251f1019afe280cceba6ff1 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 22 Jul 2015 13:49:02 -0300 Subject: [PATCH] regression: Allows to specify a single file or directory Tests were directory driven. Now it is possible to specify a single test case file. --- test/common/modsecurity_test.cc | 21 ++++++++++++++------- test/common/modsecurity_test.h | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/common/modsecurity_test.cc b/test/common/modsecurity_test.cc index 74bdb021..ff7b1b84 100644 --- a/test/common/modsecurity_test.cc +++ b/test/common/modsecurity_test.cc @@ -18,11 +18,13 @@ #include #include #include +#include #include #include #include #include +#include #include "modsecurity/modsecurity.h" @@ -92,10 +94,16 @@ template std::pair>* ModSecurityTest::load_tests() { DIR *dir; struct dirent *ent; + struct stat buffer; - if ((dir = opendir(this->target_folder.c_str())) == NULL) { - std::cout << "Problems opening directory: " << this->target_folder; - std::cout << std::endl; + if ((dir = opendir(this->target.c_str())) == NULL) { + /* if target is a file, use it as a single test. */ + if (stat(this->target.c_str(), &buffer) == 0) { + if (load_test_json(this->target) == false) { + std::cout << "Problems loading from: " << this->target; + std::cout << std::endl; + } + } return NULL; } @@ -106,12 +114,11 @@ std::pair>* ModSecurityTest::load_tests() { || !std::equal(json.rbegin(), json.rend(), filename.rbegin())) { continue; } - if (load_test_json(this->target_folder + "/" + filename) == false) { + if (load_test_json(this->target + "/" + filename) == false) { std::cout << "Problems loading tests from: " << filename; std::cout << std::endl; } } - closedir(dir); return NULL; @@ -143,9 +150,9 @@ void ModSecurityTest::cmd_options(int argc, char **argv) { } #else if (argv[1]) { - this->target_folder = argv[1]; + this->target = argv[1]; } else { - this->target_folder = default_test_path; + this->target = default_test_path; } #endif } diff --git a/test/common/modsecurity_test.h b/test/common/modsecurity_test.h index 1f76a230..2ae3e9e0 100644 --- a/test/common/modsecurity_test.h +++ b/test/common/modsecurity_test.h @@ -36,7 +36,7 @@ template class ModSecurityTest : std::pair>* load_tests(); bool load_test_json(std::string); - std::string target_folder; + std::string target; bool verbose = false; bool color = false; };