mirror of
https://github.com/apple/pkl.git
synced 2026-05-25 16:19:20 +02:00
Introduce "minimal" test reporter (#1563)
This commit is contained in:
@@ -100,6 +100,7 @@ public class PklPlugin implements Plugin<Project> {
|
||||
spec.getOutputPath()
|
||||
.convention(project.getLayout().getBuildDirectory().dir("generated/pkl/packages"));
|
||||
spec.getOverwrite().convention(false);
|
||||
spec.getReporter().convention("spec");
|
||||
var packageTask = createTask(project, ProjectPackageTask.class, spec);
|
||||
packageTask.configure(
|
||||
task -> {
|
||||
@@ -108,6 +109,7 @@ public class PklPlugin implements Plugin<Project> {
|
||||
task.getSkipPublishCheck().set(spec.getSkipPublishCheck());
|
||||
task.getJunitReportsDir().set(spec.getJunitReportsDir());
|
||||
task.getOverwrite().set(spec.getOverwrite());
|
||||
task.getTestReporter().set(spec.getReporter());
|
||||
});
|
||||
project
|
||||
.getPluginManager()
|
||||
@@ -278,12 +280,14 @@ public class PklPlugin implements Plugin<Project> {
|
||||
configureBaseSpec(project, spec);
|
||||
|
||||
spec.getOverwrite().convention(false);
|
||||
spec.getTestReporter().convention("spec");
|
||||
|
||||
var testTask = createModulesTask(project, TestTask.class, spec);
|
||||
testTask.configure(
|
||||
task -> {
|
||||
task.getJunitReportsDir().set(spec.getJunitReportsDir());
|
||||
task.getOverwrite().set(spec.getOverwrite());
|
||||
task.getTestReporter().set(spec.getTestReporter());
|
||||
});
|
||||
|
||||
project
|
||||
|
||||
@@ -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.
|
||||
@@ -29,4 +29,6 @@ public interface ProjectPackageSpec extends BasePklSpec {
|
||||
Property<Boolean> getOverwrite();
|
||||
|
||||
Property<Boolean> getSkipPublishCheck();
|
||||
|
||||
Property<String> getReporter();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -22,4 +22,6 @@ public interface TestSpec extends ModulesSpec {
|
||||
DirectoryProperty getJunitReportsDir();
|
||||
|
||||
Property<Boolean> getOverwrite();
|
||||
|
||||
Property<String> getTestReporter();
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.gradle.api.tasks.PathSensitivity;
|
||||
import org.gradle.api.tasks.UntrackedTask;
|
||||
import org.pkl.cli.CliProjectPackager;
|
||||
import org.pkl.commons.cli.CliTestOptions;
|
||||
import org.pkl.commons.cli.TestReporter;
|
||||
|
||||
@UntrackedTask(because = "Output names are known only after execution")
|
||||
public abstract class ProjectPackageTask extends BasePklTask {
|
||||
@@ -62,6 +63,10 @@ public abstract class ProjectPackageTask extends BasePklTask {
|
||||
@Optional
|
||||
public abstract Property<Boolean> getSkipPublishCheck();
|
||||
|
||||
@Input
|
||||
@Optional
|
||||
public abstract Property<String> getTestReporter();
|
||||
|
||||
public ProjectPackageTask() {
|
||||
this.getJunitAggregateSuiteName().convention("pkl-tests");
|
||||
}
|
||||
@@ -75,6 +80,18 @@ public abstract class ProjectPackageTask extends BasePklTask {
|
||||
if (projectDirectories.isEmpty()) {
|
||||
throw new InvalidUserDataException("No project directories specified.");
|
||||
}
|
||||
TestReporter testReporter;
|
||||
try {
|
||||
testReporter = TestReporter.valueOf(getTestReporter().getOrElse("SPEC").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidUserDataException(
|
||||
"Invalid reporter: '%s'. Valid reporter options: %s"
|
||||
.formatted(
|
||||
getTestReporter().get(),
|
||||
TestReporter.getEntries().stream()
|
||||
.map(it -> it.name().toLowerCase())
|
||||
.collect(Collectors.joining(", "))));
|
||||
}
|
||||
|
||||
new CliProjectPackager(
|
||||
getCliBaseOptions(),
|
||||
@@ -83,7 +100,8 @@ public abstract class ProjectPackageTask extends BasePklTask {
|
||||
mapAndGetOrNull(getJunitReportsDir(), it -> it.getAsFile().toPath()),
|
||||
getOverwrite().get(),
|
||||
getJunitAggregateReports().getOrElse(false),
|
||||
getJunitAggregateSuiteName().get()),
|
||||
getJunitAggregateSuiteName().get(),
|
||||
testReporter),
|
||||
getOutputPath().get().getAsFile().getAbsolutePath(),
|
||||
getSkipPublishCheck().getOrElse(false),
|
||||
new PrintWriter(System.out),
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.pkl.gradle.task;
|
||||
import static org.pkl.gradle.utils.PluginUtils.mapAndGetOrNull;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.stream.Collectors;
|
||||
import org.gradle.api.InvalidUserDataException;
|
||||
import org.gradle.api.file.DirectoryProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.CacheableTask;
|
||||
@@ -26,6 +28,7 @@ import org.gradle.api.tasks.Optional;
|
||||
import org.gradle.api.tasks.OutputDirectory;
|
||||
import org.pkl.cli.CliTestRunner;
|
||||
import org.pkl.commons.cli.CliTestOptions;
|
||||
import org.pkl.commons.cli.TestReporter;
|
||||
|
||||
@CacheableTask
|
||||
public abstract class TestTask extends ModulesTask {
|
||||
@@ -43,6 +46,10 @@ public abstract class TestTask extends ModulesTask {
|
||||
@Input
|
||||
public abstract Property<Boolean> getOverwrite();
|
||||
|
||||
@Input
|
||||
@Optional
|
||||
public abstract Property<String> getTestReporter();
|
||||
|
||||
public TestTask() {
|
||||
this.getJunitAggregateSuiteName().convention("pkl-tests");
|
||||
this.getPowerAssertions().convention(true);
|
||||
@@ -50,13 +57,26 @@ public abstract class TestTask extends ModulesTask {
|
||||
|
||||
@Override
|
||||
protected void doRunTask() {
|
||||
TestReporter testReporter;
|
||||
try {
|
||||
testReporter = TestReporter.valueOf(getTestReporter().getOrElse("SPEC").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidUserDataException(
|
||||
"Invalid reporter: '%s'. Valid reporter options: %s"
|
||||
.formatted(
|
||||
getTestReporter().get(),
|
||||
TestReporter.getEntries().stream()
|
||||
.map(it -> it.name().toLowerCase())
|
||||
.collect(Collectors.joining(", "))));
|
||||
}
|
||||
new CliTestRunner(
|
||||
getCliBaseOptions(),
|
||||
new CliTestOptions(
|
||||
mapAndGetOrNull(getJunitReportsDir(), it -> it.getAsFile().toPath()),
|
||||
getOverwrite().get(),
|
||||
getJunitAggregateReports().getOrElse(false),
|
||||
getJunitAggregateSuiteName().get()),
|
||||
getJunitAggregateSuiteName().get(),
|
||||
testReporter),
|
||||
new PrintWriter(System.out),
|
||||
new PrintWriter(System.err))
|
||||
.run();
|
||||
|
||||
Reference in New Issue
Block a user