Skip to content
Draft
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
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ groovy = "org.apache.groovy:groovy:4.0.29"
junit4 = "junit:junit:4.13.2"
junit-vintage = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit-vintage" }
junit-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-launcher" }
junit-engine = { module = "org.junit.platform:junit-platform-engine", version.ref = "junit-launcher" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-launcher" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-launcher" }
jsr305 = "com.google.code.findbugs:jsr305:3.0.2"
objenesis = "org.objenesis:objenesis:3.4"
spock-core = { module="org.spockframework:spock-core", version.ref="spock" }
spock-junit4 = { module="org.spockframework:spock-junit4", version.ref="spock" }
typesafe-config = "com.typesafe:config:1.4.3"

[bundles]
spock = ["spock-core", "spock-junit4"]
spock = ["spock-core", "spock-junit4"]
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-9.4.0-20251226063043+0000-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static List<Sample> filteredExternalSamples(File rootSamplesDir, String[]
// FIXME: Currently the temp directory used when running samples-check has a different name.
// This causes Gradle project names to differ when one is not explicitly set in settings.gradle. This should be preserved.
final File sampleProjectDir = sampleConfigFile.getParentFile();
samples.add(new Sample(id, sampleProjectDir, commands));
samples.add(new Sample(id, sampleProjectDir, commands, sampleConfigFile));
} catch (Exception e) {
samples.add(new InvalidSample(id, e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@
*/
package org.gradle.exemplar.model;

import javax.annotation.Nullable;
import java.io.File;
import java.util.List;

public class Sample {
private final String id;
private final File projectDir;
private final List<Command> commands;
private final File configFile;

public Sample(String id, File projectDir, List<Command> commands) {
this.id = id;
this.projectDir = projectDir;
this.commands = commands;
this.configFile = null;
}

public Sample(String id, File projectDir, List<Command> commands, File configFile) {
this.id = id;
this.projectDir = projectDir;
this.commands = commands;
this.configFile = configFile;
}

public String getId() {
Expand All @@ -40,4 +50,9 @@ public File getProjectDir() {
public List<Command> getCommands() {
return commands;
}

@Nullable
public File getConfigFile() {
return configFile;
}
}
40 changes: 40 additions & 0 deletions samples-junit-engine/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
id("exemplar.java-conventions")
id("jvm-test-suite")
id("exemplar.publishing-conventions")
}

dependencies {
implementation(project(":samples-check"))
implementation(project(":samples-discovery"))
implementation(libs.junit.engine)
implementation(libs.commons.io)
implementation(libs.commons.lang3)
}

testing {
suites {
register("integTest", JvmTestSuite::class) {
useJUnitJupiter()
dependencies {
implementation(project())
implementation(project(":samples-check"))
}

targets {
all {
testTask.configure {
mustRunAfter(tasks.named("jar"))
testDefinitionDirs.from("src/test-definitions")
systemProperty("exemplar.sample.modifiers", "test.TestSampleModifier")
systemProperty("exemplar.output.normalizers", "test.TestOutputNormalizer")
}
}
}
}
}
}

tasks.named("test", Test::class) {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package test;

import org.gradle.exemplar.executor.ExecutionMetadata;
import org.gradle.exemplar.test.normalizer.OutputNormalizer;

@SuppressWarnings("unused") // used by system property
public class TestOutputNormalizer implements OutputNormalizer {
@Override
public String normalize(String commandOutput, ExecutionMetadata executionMetadata) {
return commandOutput;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package test;

import org.gradle.exemplar.model.Sample;
import org.gradle.exemplar.test.runner.SampleModifier;

@SuppressWarnings("unused") // used by system property
public class TestSampleModifier implements SampleModifier {
@Override
public Sample modify(Sample sampleIn) {
return new Sample(sampleIn.getId(), sampleIn.getProjectDir(), sampleIn.getCommands());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.gradle.exemplar;

import org.gradle.exemplar.model.Command;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;
import org.junit.platform.engine.support.descriptor.DirectorySource;

public final class ExemplarCommandDescriptor extends AbstractTestDescriptor {

private final Command command;

public ExemplarCommandDescriptor(ExemplarSampleDescriptor parent, Command command) {
super(
uniqueId(parent, command),
displayName(command),
DirectorySource.from(parent.getSample().getProjectDir())
);
setParent(parent);
this.command = command;
}

private static UniqueId uniqueId(ExemplarSampleDescriptor exemplarTestDescriptor, Command command) {
return exemplarTestDescriptor.getUniqueId().append("commandName", displayName(command));
}

private static String displayName(Command command) {
StringBuilder displayName = new StringBuilder(command.getExecutable());
for (String flag : command.getFlags()) {
displayName.append(" ");
displayName.append(flag);
}
for (String arg : command.getArgs()) {
displayName.append(" ");
displayName.append(arg);
}
return displayName.toString();
}

@Override
public Type getType() {
return Type.TEST;
}

public Command getCommand() {
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.gradle.exemplar;

import org.gradle.exemplar.model.Command;
import org.gradle.exemplar.model.Sample;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;
import org.junit.platform.engine.support.descriptor.DirectorySource;

import java.io.File;

public final class ExemplarSampleDescriptor extends AbstractTestDescriptor {
private final Sample sample;

public ExemplarSampleDescriptor(UniqueId parentId, Sample sample) {
super(
parentId.append("testDefinitionFile", fileNameWithoutExtension(sample.getConfigFile()))
.append("testDefinition", sample.getId()),
sample.getConfigFile().getParentFile().getName(),
DirectorySource.from(sample.getProjectDir()));
this.sample = sample;
defineTests(sample);
}

private void defineTests(Sample sample) {
for (Command command : sample.getCommands()) {
children.add(new ExemplarCommandDescriptor(this, command));
}
}

private static String fileNameWithoutExtension(File file) {
String name = file.getName();
int i = name.indexOf(".sample.conf");
if (i > 0) {
return name.substring(0, i);
}
return name;
}

@Override
public Type getType() {
return Type.CONTAINER;
}

public Sample getSample() {
return sample;
}

@Override
public String toString() {
return "Sample[file=" + sample.getConfigFile().getName() + ", name=" + sample.getId() + "]";
}
}
Loading
Loading