Skip to content

Commit

Permalink
Merge pull request #6358 from pkriens/build/reactivate-windows-tests
Browse files Browse the repository at this point in the history
Reenable windows tests
  • Loading branch information
pkriens authored Nov 7, 2024
2 parents 848cd7d + f09282e commit 2818624
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cibuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ jobs:
runner: '{0}' # 'xvfb-run --auto-servernum {0}'
canonical: ${{ (github.repository == 'bndtools/bnd') && ((github.ref == 'refs/heads/master') || (github.ref == 'refs/heads/next')) && (github.event_name != 'pull_request') }}
fetch-depth: '0'
# - os: 'windows-latest'
# java: '17'
# runner: '{0}'
- os: 'windows-latest'
java: '17'
runner: '{0}'
name: Build JDK${{ matrix.java }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.TestInfo;
import org.osgi.framework.Bundle;

import aQute.junit.system.BndSystem;
import aQute.launchpad.LaunchpadBuilder;
import aQute.lib.io.IO;
import aQute.tester.junit.platform.test.ExitCode;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void start_withSeparateThreadProp_startsInNewThread() throws Exception {
final AtomicReference<Throwable> exception = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
bndThread.setUncaughtExceptionHandler((thread, e) -> {
exception.set(e);
exception.set(BndSystem.convert(e, ExitCode::new));
latch.countDown();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Optional;
import java.util.RandomAccess;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.IntConsumer;
import java.util.stream.Stream;

import org.assertj.core.api.Assert;
Expand Down Expand Up @@ -178,8 +177,12 @@ protected ExitCode runTests(Callback postCreateCallback, Class<?>[]... bundles)
try {
r.run();
throw new AssertionError("Expecting run() to call System.exit(), but it didn't");
} catch (ExitCode e) {
return e;
} catch (Throwable e) {
Throwable t = BndSystem.convert(e, ExitCode::new);
if (t instanceof ExitCode ec)
return ec;

throw Exceptions.duck(t);
}
}

Expand All @@ -206,7 +209,7 @@ public void runTester() {
final Runnable r = oR.get();

runThread = new Thread(r, name);
runThread.setUncaughtExceptionHandler((t, x) -> uncaught.set(x));
runThread.setUncaughtExceptionHandler((t, x) -> uncaught.set(BndSystem.convert(x, ExitCode::new)));
runThread.start();
}

Expand Down Expand Up @@ -435,15 +438,6 @@ public void succeeded() {
}

protected AutoCloseable setExitToThrowExitCode() {
IntConsumer target = code -> {
throw new ExitCode(code);
};
IntConsumer prev = BndSystem.exit.getAndSet(target);
return () -> {
boolean success = BndSystem.exit.compareAndSet(prev, target);
if (!success)
throw new Error(
"Overrode BndSystem exit function and tried to restore it. However, someone changed it in the mean time");
};
return BndSystem.throwErrorOnExit();
}
}
34 changes: 33 additions & 1 deletion biz.aQute.tester/src/aQute/junit/system/BndSystem.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
package aQute.junit.system;

import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.IntConsumer;

/**
* Centralizes calling exit
* Centralizes calling exit. Handling might give the impression that is clumsy
* but realize that this class is sometimes used with multiple classloaders that
* hold this class. E.g. Launchpad. That is the reason system properties are
* used.
*/
public class BndSystem {

static final String THROW_ERROR_ON_EXIT = "aQute.throw.error.on.exit";

@Deprecated
public static AtomicReference<IntConsumer> exit = new AtomicReference<>(System::exit);

public static void exit(int code) {
if ( Boolean.getBoolean(THROW_ERROR_ON_EXIT)) {
throw new Error(THROW_ERROR_ON_EXIT + code);
}
exit.get()
.accept(code);
}

public static AutoCloseable throwErrorOnExit() {
System.getProperties()
.setProperty(THROW_ERROR_ON_EXIT, "true");
return () -> {
System.getProperties()
.setProperty(THROW_ERROR_ON_EXIT, "false");
};
}

public static Throwable convert(Throwable throwable, Function<Integer, Throwable> converter) {
if (throwable instanceof Error) {
String message = throwable.getMessage();
if (message.startsWith(THROW_ERROR_ON_EXIT)) {
try {
return converter.apply(Integer.parseInt(message.substring(THROW_ERROR_ON_EXIT.length())));
} catch (NumberFormatException nfe) {
}
}
}
return throwable;
}
}

0 comments on commit 2818624

Please sign in to comment.