@@ -41,6 +41,7 @@ using modsecurity_test::CustomDebugLog;
4141using modsecurity_test::ModSecurityTest;
4242using modsecurity_test::ModSecurityTestResults;
4343using modsecurity_test::RegressionTest;
44+ using modsecurity_test::RegressionTests;
4445using modsecurity_test::RegressionTestResult;
4546
4647using modsecurity::Utils::regex_search;
@@ -436,6 +437,35 @@ int main(int argc, char **argv)
436437 return 0 ;
437438#else
438439 test.cmd_options (argc, argv);
440+
441+ if (test.m_format ) {
442+ #ifdef WITH_YAJL
443+ std::cout << " start formatting test case JSON files" << std::endl;
444+ ModSecurityTest<RegressionTests> test2;
445+ test2.cmd_options (argc, argv);
446+ test2.load_tests ();
447+ for (const auto &[name, tests] : test2) {
448+ std::ofstream ofs{name};
449+ if (!ofs.is_open ()) {
450+ std::cerr << " cannot open " << name << " for writing." << std::endl;
451+ return 1 ;
452+ }
453+ if (test2.m_update_content_length ) {
454+ tests[0 ]->update_content_lengths ();
455+ }
456+ ofs << tests[0 ]->toJSON ();
457+ ofs.close ();
458+ std::cout << " written formatted JSON to " << name << std::endl;
459+ }
460+ std::cout << " finished formatting files." << std::endl;
461+ return 0 ;
462+ #else
463+ std::cout << " Test utility cannot format test case JSON files without being built with YAJL." \
464+ << std::endl;
465+ return 1 ;
466+ #endif
467+ }
468+
439469 if (!test.m_automake_output && !test.m_count_all ) {
440470 std::cout << test.header ();
441471 }
0 commit comments