diff options
| author | Dan Engelbrecht <[email protected]> | 2023-02-23 13:29:54 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-23 04:29:54 -0800 |
| commit | 9439ffc0c83c8ed304149e598e7a33ec6e0be060 (patch) | |
| tree | 3f5237e4da0d7b2d1d7d476e40d4028f88c9531f /xmake.lua | |
| parent | add test for fnf responses in project store (#238) (diff) | |
| download | zen-9439ffc0c83c8ed304149e598e7a33ec6e0be060.tar.xz zen-9439ffc0c83c8ed304149e598e7a33ec6e0be060.zip | |
junit test reporting (#239)
- Feature: `--junit` switch to `xmake test` to generate junit style reports of tests.
- Feature: CI build on GitHub now uploads junit test reports as artifact to the check for PR validation and mainline validation
Diffstat (limited to 'xmake.lua')
| -rw-r--r-- | xmake.lua | 58 |
1 files changed, 49 insertions, 9 deletions
@@ -185,12 +185,17 @@ task("test") usage = "xmake runtest [core|store|server|integration|all]", description = "Run Zen tests", options = { - {'r', "run", "kv", "all", "Run test(s)", " - all", " - core ", " - store", " - server", " - integration"} + {'r', "run", "kv", "all", "Run test(s)", " - all", " - core ", " - store", " - server", " - integration"}, + {'j', "junit", "k", nil, "Enable junit report output"} } } on_run(function() import("core.base.option") + import("core.project.config") + import("core.project.project") + config.load() + local testname = option.get("run") local available_tests = { core = "zencore-test", @@ -215,13 +220,48 @@ task("test") tests[name] = test end end - - for name, test in pairs(tests) do - printf("=== %s ===\n", test) - local cmd = string.format("xmake run %s", test) - if name == "server" then - cmd = string.format("xmake run %s test", test) - end - print(os.exec(cmd)) + + local use_junit_reporting = option.get("junit") + local junit_report_files = {} + + local junit_report_dir + if use_junit_reporting then + junit_report_dir = path.join(os.projectdir(), config.get("buildir"), "reports") + os.mkdir(junit_report_dir) end + + try + { + function() + for name, test in pairs(tests) do + printf("=== %s ===\n", test) + local cmd = string.format("xmake run %s", test) + if name == "server" then + cmd = string.format("xmake run %s test", test) + end + if use_junit_reporting then + local target = project.target(test) + local junit_report_file = path.join(junit_report_dir, string.format("junit-%s-%s-%s.xml", config.plat(), arch, test)) + junit_report_files[test] = junit_report_file + cmd = string.format("%s --reporters=junit --out=%s", cmd, junit_report_file) + end + + os.exec(cmd) + end + end, + + finally + { + function (ok, errors) + for test, junit_report_file in pairs(junit_report_files) do + printf("=== report - %s ===\n", test) + local data = io.readfile(junit_report_file) + print(data) + end + if (errors) then + raise(errors) + end + end + } + } end) |