@@ -26,6 +26,7 @@ struct SuiteCtx {
2626 verbose : bool = false
2727 compile_only : bool = false
2828 use_aot : bool = false
29+ cov_path : string = ""
2930
3031 // Testing-related options.
3132 testNames : array<string>
@@ -91,6 +92,7 @@ def SuiteCtx(args : array<string>) : SuiteCtx {
9192 ctx .projectPath = args | > get_str_arg ("--test-project" , "" )
9293 ctx .compile_only = args | > has_value ("--compile-only" )
9394 ctx .use_aot = args | > has_value ("--use-aot" ) || is_in_aot ()
95+ ctx .cov_path = args | > get_str_arg ("--cov-path" , "" )
9496 collect_tests_names (args , ctx .testNames )
9597
9698 ctx .bench_enabled = args | > has_value ("--bench" )
@@ -168,6 +170,11 @@ def test_file(file_name : string; var ctx : SuiteCtx; var file_ctx : FileCtx) :
168170 if (jit_enabled ()) {
169171 access | > add_extra_module ("just_in_time" , "{ get_das_root ()} /daslib/just_in_time.das" )
170172 }
173+ if (! ctx .cov_path | > empty ()) {
174+ cop .export_all = true
175+ cop .rtti = true
176+ access | > add_extra_module ("coverage" , "{ get_das_root ()} /daslib/coverage.das" )
177+ }
171178 compile_file (file_name , access , unsafe (addr (mg )), cop ) $ (ok, program, output) {
172179 var expectedErrors : table < CompilationError ; int >
173180 if (program ! = null ) {
@@ -242,6 +249,21 @@ def test_file(file_name : string; var ctx : SuiteCtx; var file_ctx : FileCtx) :
242249 var mod = program | > get_this_module ()
243250 if (mod ! = null && context ! = null ) {
244251 let module_result = test_module (* mod , * context , ctx , file_ctx )
252+ if (module_result .total > 0 && ! ctx .cov_path | > empty ()) {
253+ var report = ""
254+ unsafe (invoke_in_context (* context , "fill_report" , unsafe (addr (report )), "" ))
255+ // Clone to current context.
256+ report := report
257+ fopen (ctx .cov_path , "ab" ) < | $ (fw) {
258+ if (fw ! = null ) {
259+ to_log (LOG_INFO , "Coverage to { ctx .cov_path } \n " )
260+ fwrite (fw , report )
261+ } else {
262+ to_log (LOG_ERROR , "Couldn't create output file { ctx .cov_path } \n " )
263+ }
264+ }
265+
266+ }
245267 if (module_result .failed + module_result .errors == 0 ) {
246268 unsafe {
247269 file_ctx .context = addr (* context )
0 commit comments