Aggregate junit report into one file (#1056)

Some systems require junit report to be in a single file. For example `bazel` https://bazel.build/reference/test-encyclopedia needs single file to be available in `XML_OUTPUT_FILE` path.

To avoid implementing junit aggregation in pkl wrappers in different places this PR instead adds a `--junit-aggregate-reports` flag to return all junit reports as a single file.

Additional flag `--junit-aggregate-suite-name` is added to allow overriding global test suite name from default `pkl-tests`
This commit is contained in:
Artem Yarmoliuk
2025-06-07 01:33:13 +01:00
committed by GitHub
parent 0b0f3b131d
commit 3bd8a88506
11 changed files with 353 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,6 +43,13 @@ public abstract class ProjectPackageTask extends BasePklTask {
@OutputDirectory
public abstract DirectoryProperty getJunitReportsDir();
@Input
@Optional
public abstract Property<Boolean> getJunitAggregateReports();
@Input
public abstract Property<String> getJunitAggregateSuiteName();
@Input
public abstract Property<Boolean> getOverwrite();
@@ -50,6 +57,10 @@ public abstract class ProjectPackageTask extends BasePklTask {
@Optional
public abstract Property<Boolean> getSkipPublishCheck();
public ProjectPackageTask() {
this.getJunitAggregateSuiteName().convention("pkl-tests");
}
@Override
protected void doRunTask() {
var projectDirectories =
@@ -59,12 +70,15 @@ public abstract class ProjectPackageTask extends BasePklTask {
if (projectDirectories.isEmpty()) {
throw new InvalidUserDataException("No project directories specified.");
}
new CliProjectPackager(
getCliBaseOptions(),
projectDirectories,
new CliTestOptions(
mapAndGetOrNull(getJunitReportsDir(), it -> it.getAsFile().toPath()),
getOverwrite().get()),
getOverwrite().get(),
getJunitAggregateReports().getOrElse(false),
getJunitAggregateSuiteName().get()),
getOutputPath().get().getAsFile().getAbsolutePath(),
getSkipPublishCheck().getOrElse(false),
new PrintWriter(System.out),

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,16 +29,29 @@ public abstract class TestTask extends ModulesTask {
@OutputDirectory
public abstract DirectoryProperty getJunitReportsDir();
@Input
@Optional
public abstract Property<Boolean> getJunitAggregateReports();
@Input
public abstract Property<String> getJunitAggregateSuiteName();
@Input
public abstract Property<Boolean> getOverwrite();
public TestTask() {
this.getJunitAggregateSuiteName().convention("pkl-tests");
}
@Override
protected void doRunTask() {
new CliTestRunner(
getCliBaseOptions(),
new CliTestOptions(
mapAndGetOrNull(getJunitReportsDir(), it -> it.getAsFile().toPath()),
getOverwrite().get()),
getOverwrite().get(),
getJunitAggregateReports().getOrElse(false),
getJunitAggregateSuiteName().get()),
new PrintWriter(System.out),
new PrintWriter(System.err))
.run();