| 67 | } |
| 68 | |
| 69 | static void gjs_coverage_fixture_set_up(void* fixture_data, const void*) { |
| 70 | auto* fixture = static_cast<GjsCoverageFixture*>(fixture_data); |
| 71 | const char* js_script = "var f = function () { return 1; }\n"; |
| 72 | |
| 73 | Gjs::AutoChar tmp_output_dir_name{g_strdup("/tmp/gjs_coverage_tmp.XXXXXX")}; |
| 74 | tmp_output_dir_name = mkdtemp(tmp_output_dir_name.release()); |
| 75 | |
| 76 | if (!tmp_output_dir_name) |
| 77 | g_error("Failed to create temporary directory for test files: %s\n", |
| 78 | strerror(errno)); |
| 79 | |
| 80 | fixture->tmp_output_dir = g_file_new_for_path(tmp_output_dir_name); |
| 81 | fixture->tmp_js_script = g_file_get_child(fixture->tmp_output_dir, |
| 82 | "gjs_coverage_script.js"); |
| 83 | fixture->lcov_output_dir = g_file_get_child(fixture->tmp_output_dir, |
| 84 | "gjs_coverage_test_coverage"); |
| 85 | fixture->lcov_output = g_file_get_child(fixture->lcov_output_dir, |
| 86 | "coverage.lcov"); |
| 87 | |
| 88 | g_file_make_directory_with_parents(fixture->lcov_output_dir, nullptr, |
| 89 | nullptr); |
| 90 | |
| 91 | Gjs::AutoChar tmp_js_script_filename{ |
| 92 | g_file_get_path(fixture->tmp_js_script)}; |
| 93 | |
| 94 | // Allocate a strv that we can pass over to gjs_coverage_new() |
| 95 | char* coverage_paths[] = {tmp_js_script_filename, nullptr}; |
| 96 | char* search_paths[] = {tmp_output_dir_name, nullptr}; |
| 97 | |
| 98 | gjs_coverage_enable(); |
| 99 | fixture->gjs_context = |
| 100 | gjs_context_new_with_search_path(static_cast<char**>(search_paths)); |
| 101 | fixture->coverage = gjs_coverage_new(coverage_paths, fixture->gjs_context, |
| 102 | fixture->lcov_output_dir); |
| 103 | |
| 104 | replace_file(fixture->tmp_js_script, js_script); |
| 105 | } |
| 106 | |
| 107 | static void gjs_coverage_fixture_tear_down(void* fixture_data, const void*) { |
| 108 | auto* fixture = static_cast<GjsCoverageFixture*>(fixture_data); |
no test coverage detected