Skip to content

Commit

Permalink
Fix test without relying on Gradle's --debug
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Nov 20, 2024
1 parent 151cd36 commit f44ae01
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package org.junit.platform.reporting.testutil;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class FileUtils {

public static Path findPath(Path rootDir, String syntaxAndPattern) {
var matcher = rootDir.getFileSystem().getPathMatcher(syntaxAndPattern);
try (var files = Files.walk(rootDir)) {
return files.filter(matcher::matches).findFirst() //
.orElseThrow(() -> new AssertionError(
"Failed to find file matching '%s' in %s".formatted(syntaxAndPattern, rootDir)));
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies {
}
testImplementation(libs.bundles.xmlunit)
testImplementation(testFixtures(projects.junitJupiterApi))
testImplementation(testFixtures(projects.junitPlatformReporting))

thirdPartyJars(libs.junit4)
thirdPartyJars(libs.assertj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

package platform.tooling.support.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;
import static platform.tooling.support.Helper.TOOL_TIMEOUT;

import java.nio.file.Paths;
import java.util.List;

import de.sormuras.bartholdy.Tool;
import de.sormuras.bartholdy.tool.GradleWrapper;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.platform.reporting.testutil.FileUtils;
import org.opentest4j.TestAbortedException;

import platform.tooling.support.Helper;
Expand All @@ -41,27 +41,26 @@ void gradle_wrapper() {
}

private void test(Tool gradle) {
var result = Request.builder() //
var request = Request.builder() //
.setProject(Projects.GRADLE_MISSING_ENGINE) //
.setTool(gradle) //
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") //
.putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) //
.setTimeout(TOOL_TIMEOUT).build() //
.run();
.setTimeout(TOOL_TIMEOUT) //
.build();

var result = request.run();

assertFalse(result.isTimedOut(), () -> "tool timed out: " + result);

assertEquals(1, result.getExitCode());
assertLinesMatch(List.of( //
">> HEAD >>", //
".+DEBUG.+Cannot create Launcher without at least one TestEngine.+", //
">> TAIL >>"), //
result.getOutputLines("out"));
assertLinesMatch(List.of( //
">> HEAD >>", //
".+ERROR.+FAILURE: Build failed with an exception.", //
">> TAIL >>"), //
result.getOutputLines("err"));
assertThat(result.getOutputLines("err")) //
.contains("FAILURE: Build failed with an exception.");

var htmlFile = FileUtils.findPath(Request.WORKSPACE.resolve(request.getWorkspace()),
"glob:**/build/reports/tests/test/classes/*.html");
assertThat(htmlFile).content() //
.contains("Cannot create Launcher without at least one TestEngine");
}
}

0 comments on commit f44ae01

Please sign in to comment.