Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/modules/pkl-gradle/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ Default: `false` +
Whether to ignore expected example files and generate them again.
====

[[show-only-failed]]
.showOnlyFailed: Property<Boolean>
[%collapsible]
====
Default: `false` +
Example: `showOnlyFailed = true` +
Only show failed test output, hiding passing tests from the report.
====

[[power-assertions-test]]
.powerAssertions: Property<Boolean>
[%collapsible]
Expand Down Expand Up @@ -677,6 +686,14 @@ Default: `false` +
Whether to ignore expected example files and generate them again.
====

.showOnlyFailed: Property<Boolean>
[%collapsible]
====
Default: `false` +
Example: `showOnlyFailed = true` +
Only show failed test output, hiding passing tests from the report.
====

Common properties:

include::../partials/gradle-common-properties.adoc[]
Expand Down
8 changes: 3 additions & 5 deletions pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.pkl.core.util.ErrorMessages
class CliTestRunner
@JvmOverloads
constructor(
private val options: CliBaseOptions,
options: CliBaseOptions,
private val testOptions: CliTestOptions,
private val consoleWriter: Writer = System.out.writer(),
private val errWriter: Writer = System.err.writer(),
Expand Down Expand Up @@ -64,13 +64,11 @@ constructor(
var failed = false
var isExampleWrittenFailure = true
val moduleNames = mutableSetOf<String>()
val reporter = SimpleReport(useColor)
val reporter = SimpleReport(useColor, testOptions.showOnlyFailed)
val allTestResults = mutableListOf<TestResults>()

val junitDir = testOptions.junitDir
if (junitDir != null) {
junitDir.toFile().mkdirs()
}
junitDir?.toFile()?.mkdirs()

for ((idx, moduleUri) in sources.withIndex()) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 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.
Expand All @@ -22,4 +22,5 @@ class CliTestOptions(
val overwrite: Boolean = false,
val junitAggregateReports: Boolean = false,
val junitAggregateSuiteName: String = "pkl-tests",
val showOnlyFailed: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 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.
Expand Down Expand Up @@ -51,7 +51,16 @@ class TestOptions : OptionGroup() {
private val overwrite: Boolean by
option(names = arrayOf("--overwrite"), help = "Force generation of expected examples.").flag()

private val showOnlyFailed: Boolean by
option(names = arrayOf("--show-only-failed"), help = "Only show failed test output.").flag()

val cliTestOptions: CliTestOptions by lazy {
CliTestOptions(junitReportDir, overwrite, junitAggregateReports, junitAggregateSuiteName)
CliTestOptions(
junitReportDir,
overwrite,
junitAggregateReports,
junitAggregateSuiteName,
showOnlyFailed,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 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.
Expand Down Expand Up @@ -36,9 +36,11 @@ public final class SimpleReport implements TestReport {
private static final String failingMark = "✘ ";

private final boolean useColor;
private final boolean showOnlyFailed;

public SimpleReport(boolean useColor) {
public SimpleReport(boolean useColor, boolean showOnlyFailed) {
this.useColor = useColor;
this.showOnlyFailed = showOnlyFailed;
}

@Override
Expand Down Expand Up @@ -92,10 +94,13 @@ public void summarize(List<TestResults> allTestResults, Writer writer) throws IO
}

private void reportResults(TestSectionResults section, AnsiStringBuilder builder) {
if (!section.results().isEmpty()) {
var results =
showOnlyFailed
? section.results().stream().filter(TestResult::isFailure).toList()
: section.results();
if (!results.isEmpty()) {
builder.append(" ").append(section.name()).append('\n');
StringUtils.joinToStringBuilder(
builder, section.results(), "\n", res -> reportResult(res, builder));
StringUtils.joinToStringBuilder(builder, results, "\n", res -> reportResult(res, builder));
builder.append('\n');
}
}
Expand Down
68 changes: 67 additions & 1 deletion pkl-core/src/test/kotlin/org/pkl/core/stdlib/SimpleReportTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SimpleReportTest {
val testResults = listOf(resultsBuilder.build())

val writer = StringWriter()
val simpleReport = SimpleReport(false)
val simpleReport = SimpleReport(false, false)
simpleReport.summarize(testResults, writer)

val expectedOutput =
Expand All @@ -71,4 +71,70 @@ class SimpleReportTest {

assertThat(writer.toString().trimIndent()).isEqualTo(expectedOutput)
}

@Test
fun `report with showOnlyFailed filters out passing tests`() {
val resultsBuilder = TestResults.Builder("module1", "module1")
resultsBuilder.setFactsSection(
TestSectionResults(
TestResults.TestSectionName.FACTS,
listOf(
TestResult("passing fact", 1, emptyList(), emptyList(), false),
TestResult(
"failing fact",
1,
listOf(TestResults.Failure("Fact Failure", "failed")),
emptyList(),
false,
),
),
)
)
resultsBuilder.setExamplesSection(
TestSectionResults(
TestResults.TestSectionName.EXAMPLES,
listOf(TestResult("passing example", 1, emptyList(), emptyList(), false)),
)
)
val testResults = resultsBuilder.build()

val writer = StringWriter()
val simpleReport = SimpleReport(false, true)
simpleReport.report(testResults, writer)

val output = writer.toString()
assertThat(output).contains("failing fact")
assertThat(output).doesNotContain("passing fact")
assertThat(output).doesNotContain("passing example")
assertThat(output).doesNotContain("examples")
}

@Test
fun `report without showOnlyFailed includes all tests`() {
val resultsBuilder = TestResults.Builder("module1", "module1")
resultsBuilder.setFactsSection(
TestSectionResults(
TestResults.TestSectionName.FACTS,
listOf(
TestResult("passing fact", 1, emptyList(), emptyList(), false),
TestResult(
"failing fact",
1,
listOf(TestResults.Failure("Fact Failure", "failed")),
emptyList(),
false,
),
),
)
)
val testResults = resultsBuilder.build()

val writer = StringWriter()
val simpleReport = SimpleReport(false, false)
simpleReport.report(testResults, writer)

val output = writer.toString()
assertThat(output).contains("passing fact")
assertThat(output).contains("failing fact")
}
}
4 changes: 4 additions & 0 deletions pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private void configureProjectPackageTasks(
spec.getOutputPath()
.convention(project.getLayout().getBuildDirectory().dir("generated/pkl/packages"));
spec.getOverwrite().convention(false);
spec.getShowOnlyFailed().convention(false);
var packageTask = createTask(project, ProjectPackageTask.class, spec);
packageTask.configure(
task -> {
Expand All @@ -106,6 +107,7 @@ private void configureProjectPackageTasks(
task.getSkipPublishCheck().set(spec.getSkipPublishCheck());
task.getJunitReportsDir().set(spec.getJunitReportsDir());
task.getOverwrite().set(spec.getOverwrite());
task.getShowOnlyFailed().set(spec.getShowOnlyFailed());
});
project
.getPluginManager()
Expand Down Expand Up @@ -274,12 +276,14 @@ private void configureTestTasks(Project project, NamedDomainObjectContainer<Test
configureBaseSpec(project, spec);

spec.getOverwrite().convention(false);
spec.getShowOnlyFailed().convention(false);

var testTask = createModulesTask(project, TestTask.class, spec);
testTask.configure(
task -> {
task.getJunitReportsDir().set(spec.getJunitReportsDir());
task.getOverwrite().set(spec.getOverwrite());
task.getShowOnlyFailed().set(spec.getShowOnlyFailed());
});

project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 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.
Expand Down Expand Up @@ -29,4 +29,6 @@ public interface ProjectPackageSpec extends BasePklSpec {
Property<Boolean> getOverwrite();

Property<Boolean> getSkipPublishCheck();

Property<Boolean> getShowOnlyFailed();
}
4 changes: 3 additions & 1 deletion pkl-gradle/src/main/java/org/pkl/gradle/spec/TestSpec.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 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.
Expand All @@ -22,4 +22,6 @@ public interface TestSpec extends ModulesSpec {
DirectoryProperty getJunitReportsDir();

Property<Boolean> getOverwrite();

Property<Boolean> getShowOnlyFailed();
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public abstract class ProjectPackageTask extends BasePklTask {
@Optional
public abstract Property<Boolean> getSkipPublishCheck();

@Input
@Optional
public abstract Property<Boolean> getShowOnlyFailed();

public ProjectPackageTask() {
this.getJunitAggregateSuiteName().convention("pkl-tests");
}
Expand All @@ -81,7 +85,8 @@ protected void doRunTask() {
mapAndGetOrNull(getJunitReportsDir(), it -> it.getAsFile().toPath()),
getOverwrite().get(),
getJunitAggregateReports().getOrElse(false),
getJunitAggregateSuiteName().get()),
getJunitAggregateSuiteName().get(),
getShowOnlyFailed().getOrElse(false)),
getOutputPath().get().getAsFile().getAbsolutePath(),
getSkipPublishCheck().getOrElse(false),
new PrintWriter(System.out),
Expand Down
7 changes: 6 additions & 1 deletion pkl-gradle/src/main/java/org/pkl/gradle/task/TestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public abstract class TestTask extends ModulesTask {
@Input
public abstract Property<Boolean> getOverwrite();

@Input
@Optional
public abstract Property<Boolean> getShowOnlyFailed();

public TestTask() {
this.getJunitAggregateSuiteName().convention("pkl-tests");
this.getPowerAssertions().convention(true);
Expand All @@ -54,7 +58,8 @@ protected void doRunTask() {
mapAndGetOrNull(getJunitReportsDir(), it -> it.getAsFile().toPath()),
getOverwrite().get(),
getJunitAggregateReports().getOrElse(false),
getJunitAggregateSuiteName().get()),
getJunitAggregateSuiteName().get(),
getShowOnlyFailed().getOrElse(false)),
new PrintWriter(System.out),
new PrintWriter(System.err))
.run();
Expand Down
Loading