@@ -287,6 +287,58 @@ jobs:
287287 condition: succeeded()
288288
289289
290+ #####################################################################################
291+ # Essentially run devtools::test() on the checked out code. This is wrapped up with
292+ # code coverage. The actual command is vary convoluted as it had to do some things
293+ # which are not default behaviour: output the results to a JUnit xml file, not stop
294+ # when a small number of errors have happened, run through the code coverage tool.
295+ # TODO: Tidy up variable names - use timestamps here.
296+ - bash : |
297+
298+ # See, 'Code coverage and JUnit report output' for issues with the approach and improvement needed.
299+ sudo R --verbose -e 'devtools::check()'
300+
301+ pwd
302+ mkdir $(Pipeline.Workspace)/logs
303+
304+ # run the coverage tool and output to coveragelist.csv
305+ # testthat::testpackage uses a MultiReporter, comprised of a ProgressReporter and JunitReporter
306+ # R output and messages are redirected by sink() to test_console_output.txt
307+ # junit reporter output is to test_results.xml
308+ sudo R -q -e '
309+ library(covr);
310+ write.csv(
311+ coverage_to_list(
312+ covr::package_coverage(
313+ type = c("none"),
314+ code = c(
315+ '"'"'library(testthat);
316+ output_file <- file("test_console_output.txt");
317+ sink(output_file);
318+ sink(output_file, type = "message");
319+ library(testthat);
320+ junit_rep <- JunitReporter$new(file = "test_results.xml");
321+ progress_rep <- ProgressReporter$new(max_failures = 999999);
322+ multi_rep <- MultiReporter$new(reporters = list(progress_rep, junit_rep));
323+ testthat::test_package("$(projectName)", filter = "$(test_filter)",reporter = multi_rep, stop_on_failure = FALSE)'"'"')
324+ )
325+ ),
326+ "coveragelist.csv"
327+ )'
328+
329+ # display the test console output
330+ cat test_console_output.txt
331+ mv coveragelist.csv $(Pipeline.Workspace)/logs
332+ mv test_results.xml $(Pipeline.Workspace)/logs
333+ mv test_console_output.txt $(Pipeline.Workspace)/logs
334+
335+ grep --quiet "Failed: 0" $(Pipeline.Workspace)/logs/test_console_output.txt
336+
337+ workingDirectory: $(Pipeline.Workspace)/dsBaseClient
338+ displayName: 'Code coverage and JUnit report output'
339+ condition: succeeded()
340+
341+
290342 #####################################################################################
291343 # Parse the JUnit file to see if there are any errors/warnings. If there are then
292344 # echo them so finding bugs should be easier.
0 commit comments