Helper to execute a fuzz test case - returns true if no crash occurred
| 1901 | |
| 1902 | // Helper to execute a fuzz test case - returns true if no crash occurred |
| 1903 | static bool fuzz_test_template(const std::string & tmpl, const json & vars) { |
| 1904 | try { |
| 1905 | // printf("Fuzz testing template: %s\n", tmpl.c_str()); |
| 1906 | jinja::lexer lexer; |
| 1907 | auto lexer_res = lexer.tokenize(tmpl); |
| 1908 | jinja::program ast = jinja::parse_from_tokens(lexer_res); |
| 1909 | jinja::context ctx(tmpl); |
| 1910 | jinja::global_from_json(ctx, vars, true); |
| 1911 | jinja::runtime runtime(ctx); |
| 1912 | const jinja::value results = runtime.execute(ast); |
| 1913 | runtime.gather_string_parts(results); |
| 1914 | return true; // success |
| 1915 | } catch (const std::exception &) { |
| 1916 | return true; // exception is acceptable, not a crash |
| 1917 | } catch (...) { |
| 1918 | return true; // any exception is acceptable, not a crash |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | static void test_fuzzing(testing & t) { |
| 1923 | const int num_iterations = JINJA_FUZZ_ITERATIONS; |
no test coverage detected