Skip to content

Commit d9ba9b4

Browse files
committed
Make test independent of local Git repo config
1 parent 4e39fc3 commit d9ba9b4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.net.UnknownHostException;
5959
import java.nio.charset.Charset;
6060
import java.nio.file.Path;
61+
import java.nio.file.Paths;
6162
import java.time.Instant;
6263
import java.util.Map;
6364
import java.util.Optional;
@@ -108,9 +109,16 @@ public class OpenTestReportGeneratingListener implements TestExecutionListener {
108109
private final AtomicInteger idCounter = new AtomicInteger();
109110
private final Map<UniqueId, String> inProgressIds = new ConcurrentHashMap<>();
110111
private DocumentWriter<Events> eventsFileWriter = DocumentWriter.noop();
112+
private final Path workingDir;
111113
private Path outputDir;
112114

115+
@SuppressWarnings("unused") // Used via ServiceLoader
113116
public OpenTestReportGeneratingListener() {
117+
this(Paths.get(".").toAbsolutePath());
118+
}
119+
120+
OpenTestReportGeneratingListener(Path workingDir) {
121+
this.workingDir = workingDir;
114122
}
115123

116124
@Override
@@ -160,7 +168,7 @@ private void reportInfrastructure() {
160168
});
161169
}
162170

163-
private static void addGitInfo(Infrastructure infrastructure) {
171+
private void addGitInfo(Infrastructure infrastructure) {
164172
boolean gitInstalled = exec("git", "--version").isPresent();
165173
if (gitInstalled) {
166174
exec("git", "config", "--get", "remote.origin.url") //
@@ -179,7 +187,7 @@ private static void addGitInfo(Infrastructure infrastructure) {
179187
}
180188
}
181189

182-
static Optional<String> exec(String... args) {
190+
Optional<String> exec(String... args) {
183191

184192
Process process = startProcess(args);
185193

@@ -211,10 +219,10 @@ private static BufferedReader newBufferedReader(InputStream stream) {
211219
return new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset()));
212220
}
213221

214-
private static Process startProcess(String[] args) {
222+
private Process startProcess(String[] command) {
215223
Process process;
216224
try {
217-
process = Runtime.getRuntime().exec(args);
225+
process = new ProcessBuilder().directory(workingDir.toFile()).command(command).start();
218226
}
219227
catch (IOException e) {
220228
throw new UncheckedIOException("Failed to start process", e);

platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ void writesValidXmlReport() throws Exception {
7979
<java:javaVersion>${xmlunit.ignore}</java:javaVersion>
8080
<java:fileEncoding>${xmlunit.ignore}</java:fileEncoding>
8181
<java:heapSize max="${xmlunit.isNumber}"/>
82-
<git:repository originUrl="${xmlunit.matchesRegex#(git@|https://).+#}"/>
83-
<git:branch>${xmlunit.ignore}</git:branch>
84-
<git:commit>${xmlunit.matchesRegex#[0-9a-f]{40}#}</git:commit>
85-
<git:status clean="${xmlunit.ignore}">${xmlunit.ignore}</git:status>
8682
</infrastructure>
8783
<e:started id="1" name="dummy" time="${xmlunit.isDateTime}">
8884
<metadata>
@@ -137,7 +133,7 @@ private void executeTests(TestEngine engine) {
137133
.configurationParameter(OUTPUT_DIR_PROPERTY_NAME,
138134
tempDirectory.resolve("junit-" + OUTPUT_DIR_UNIQUE_NUMBER_PLACEHOLDER).toString()) //
139135
.build();
140-
createLauncher(engine).execute(build, new OpenTestReportGeneratingListener());
136+
createLauncher(engine).execute(build, new OpenTestReportGeneratingListener(tempDirectory));
141137
}
142138

143139
}

0 commit comments

Comments
 (0)