diff --git a/test/unit/unit.cc b/test/unit/unit.cc index 70cbea2a..96df4cd4 100644 --- a/test/unit/unit.cc +++ b/test/unit/unit.cc @@ -82,6 +82,7 @@ using modsecurity::operators::Operator; using namespace modsecurity::actions::transformations; std::string default_test_path = "test-cases/secrules-language-tests/operators"; +std::list resources; void print_help() { std::cout << "Use ./unit /path/to/file" << std::endl; @@ -138,11 +139,25 @@ Transformation* t_instantiate(std::string a) { void perform_unit_test(ModSecurityTest *test, UnitTest *t, ModSecurityTestResults* res) { std::string error; + bool found = true; if (test->m_automake_output) { std::cout << ":test-result: "; } + if (t->resource.empty() == false) { + found = (std::find(resources.begin(), resources.end(), t->resource) + != resources.end()); + } + + if (!found) { + t->skipped = true; + res->push_back(t); + if (test->m_automake_output) { + std::cout << "SKIP "; + } + } + if (t->type == "op") { Operator *op = Operator::instantiate(t->name, t->param); op->init(t->filename, &error); @@ -189,6 +204,13 @@ int main(int argc, char **argv) { ModSecurityTest test; ModSecurityTestResults results; +#ifdef WITH_GEOIP + resources.push_back("geoip"); +#endif +#ifdef WITH_CURL + resources.push_back("curl"); +#endif + test.cmd_options(argc, argv); if (!test.m_automake_output) { std::cout << test.header(); @@ -212,12 +234,23 @@ int main(int argc, char **argv) { perform_unit_test(&test, t, &r); if (!test.m_automake_output) { + int skp = 0; if (r.size() == 0) { - std::cout << KGRN << r.size() << " tests failed."; + std::cout << KGRN << "0 tests failed."; } else { - std::cout << KRED << r.size() << " tests failed."; + for (auto &i : r) { + if (i->skipped == true) { + skp++; + } + } + std::cout << KRED << r.size()-skp << " tests failed."; } - std::cout << RESET << std::endl; + std::cout << RESET; + if (skp > 0) { + std::cout << " " << std::to_string(skp) << " "; + std::cout << "skipped."; + } + std::cout << std::endl; } results.insert(results.end(), r.begin(), r.end()); @@ -239,8 +272,18 @@ int main(int argc, char **argv) { if (results.size() == 0) { std::cout << KGRN << "All tests passed" << RESET << std::endl; } else { - std::cout << KRED << results.size() << " failed."; + int skp = 0; + for (auto &i : results) { + if (i->skipped == true) { + skp++; + } + } + std::cout << KRED << results.size()-skp << " failed."; std::cout << RESET << std::endl; + if (skp > 0) { + std::cout << " " << std::to_string(skp) << " "; + std::cout << "skipped."; + } } } diff --git a/test/unit/unit_test.cc b/test/unit/unit_test.cc index 7924cb02..a57cb84e 100644 --- a/test/unit/unit_test.cc +++ b/test/unit/unit_test.cc @@ -129,12 +129,14 @@ UnitTest *UnitTest::from_yajl_node(yajl_val &node) { const char *key = node->u.object.keys[ i ]; yajl_val val = node->u.object.values[ i ]; - + u->skipped = false; if (strcmp(key, "param") == 0) { u->param = YAJL_GET_STRING(val); } else if (strcmp(key, "input") == 0) { u->input = YAJL_GET_STRING(val); json2bin(&u->input); + } else if (strcmp(key, "resource") == 0) { + u->resource = YAJL_GET_STRING(val); } else if (strcmp(key, "name") == 0) { u->name = YAJL_GET_STRING(val); } else if (strcmp(key, "type") == 0) { diff --git a/test/unit/unit_test.h b/test/unit/unit_test.h index 9fa2338d..34aa5914 100644 --- a/test/unit/unit_test.h +++ b/test/unit/unit_test.h @@ -33,12 +33,14 @@ class UnitTest { std::string param; std::string input; + std::string resource; std::string name; std::string type; std::string filename; std::string output; int ret; int obtained; + int skipped; std::string obtainedOutput; };