Skip to content

Commit f44ae01

Browse files
committed
Fix test without relying on Gradle's --debug
1 parent 151cd36 commit f44ae01

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2015-2024 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package org.junit.platform.reporting.testutil;
12+
13+
import java.io.IOException;
14+
import java.io.UncheckedIOException;
15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
17+
18+
public class FileUtils {
19+
20+
public static Path findPath(Path rootDir, String syntaxAndPattern) {
21+
var matcher = rootDir.getFileSystem().getPathMatcher(syntaxAndPattern);
22+
try (var files = Files.walk(rootDir)) {
23+
return files.filter(matcher::matches).findFirst() //
24+
.orElseThrow(() -> new AssertionError(
25+
"Failed to find file matching '%s' in %s".formatted(syntaxAndPattern, rootDir)));
26+
}
27+
catch (IOException e) {
28+
throw new UncheckedIOException(e);
29+
}
30+
}
31+
}

platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ dependencies {
7171
}
7272
testImplementation(libs.bundles.xmlunit)
7373
testImplementation(testFixtures(projects.junitJupiterApi))
74+
testImplementation(testFixtures(projects.junitPlatformReporting))
7475

7576
thirdPartyJars(libs.junit4)
7677
thirdPartyJars(libs.assertj)

platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleMissingEngineTests.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
package platform.tooling.support.tests;
1212

13+
import static org.assertj.core.api.Assertions.assertThat;
1314
import static org.junit.jupiter.api.Assertions.assertEquals;
1415
import static org.junit.jupiter.api.Assertions.assertFalse;
15-
import static org.junit.jupiter.api.Assertions.assertLinesMatch;
1616
import static platform.tooling.support.Helper.TOOL_TIMEOUT;
1717

1818
import java.nio.file.Paths;
19-
import java.util.List;
2019

2120
import de.sormuras.bartholdy.Tool;
2221
import de.sormuras.bartholdy.tool.GradleWrapper;
2322

2423
import org.junit.jupiter.api.Test;
2524
import org.junit.jupiter.api.parallel.ResourceLock;
25+
import org.junit.platform.reporting.testutil.FileUtils;
2626
import org.opentest4j.TestAbortedException;
2727

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

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

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

5557
assertEquals(1, result.getExitCode());
56-
assertLinesMatch(List.of( //
57-
">> HEAD >>", //
58-
".+DEBUG.+Cannot create Launcher without at least one TestEngine.+", //
59-
">> TAIL >>"), //
60-
result.getOutputLines("out"));
61-
assertLinesMatch(List.of( //
62-
">> HEAD >>", //
63-
".+ERROR.+FAILURE: Build failed with an exception.", //
64-
">> TAIL >>"), //
65-
result.getOutputLines("err"));
58+
assertThat(result.getOutputLines("err")) //
59+
.contains("FAILURE: Build failed with an exception.");
60+
61+
var htmlFile = FileUtils.findPath(Request.WORKSPACE.resolve(request.getWorkspace()),
62+
"glob:**/build/reports/tests/test/classes/*.html");
63+
assertThat(htmlFile).content() //
64+
.contains("Cannot create Launcher without at least one TestEngine");
6665
}
6766
}

0 commit comments

Comments
 (0)