Skip to content

Commit

Permalink
fix JavaTest.testResultPropertyZeroNoFork
Browse files Browse the repository at this point in the history
  • Loading branch information
jaikiran committed Aug 16, 2023
1 parent 3c03f54 commit 8778136
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,16 @@ public class JavaTest {

private boolean runFatalTests = false;

private static final boolean allowedToIssueSystemExit;
private static final String SKIP_MSG_CAUSE_SYSTEM_EXIT_USE =
private static final boolean allowedToUseSecurityManager;
private static final String SKIP_SEC_MGR_USAGE =
"Skipping test on current Java version " + JavaEnvUtils.getJavaVersion()
+ " because test calls System.exit() in non-forked VM";
+ " because SecurityManager is no longer supported";
static {
final JavaVersion javaVersion = new JavaVersion();
javaVersion.setAtMost("17");
// don't run tests which call System.exit() on a non-forked VM because
// Ant no longer sets a custom SecurityManager to prevent the VM exit
// for Java versions >= 18
allowedToIssueSystemExit = javaVersion.eval();
// don't run tests which require usage of SecurityManager.
// Ant no longer sets a custom SecurityManager for Java versions >= 18
allowedToUseSecurityManager = javaVersion.eval();
}

/**
Expand Down Expand Up @@ -222,14 +221,14 @@ public void testRun() {
@Test
public void testRunFail() {
assumeTrue("Fatal tests have not been set to run", runFatalTests);
assumeTrue(SKIP_MSG_CAUSE_SYSTEM_EXIT_USE, allowedToIssueSystemExit);
assumeTrue(SKIP_SEC_MGR_USAGE, allowedToUseSecurityManager);
buildRule.executeTarget("testRunFail");
}

@Test
public void testRunFailFoe() {
assumeTrue("Fatal tests have not been set to run", runFatalTests);
assumeTrue(SKIP_MSG_CAUSE_SYSTEM_EXIT_USE, allowedToIssueSystemExit);
assumeTrue(SKIP_SEC_MGR_USAGE, allowedToUseSecurityManager);
thrown.expect(BuildException.class);
thrown.expectMessage("Java returned:");
buildRule.executeTarget("testRunFailFoe");
Expand Down Expand Up @@ -282,20 +281,21 @@ public void testResultPropertyNonZero() {

@Test
public void testResultPropertyZeroNoFork() {
assumeTrue(SKIP_SEC_MGR_USAGE, allowedToUseSecurityManager);
buildRule.executeTarget("testResultPropertyZeroNoFork");
assertEquals("0", buildRule.getProject().getProperty("exitcode"));
}

@Test
public void testResultPropertyNonZeroNoFork() {
assumeTrue(SKIP_MSG_CAUSE_SYSTEM_EXIT_USE, allowedToIssueSystemExit);
assumeTrue(SKIP_SEC_MGR_USAGE, allowedToUseSecurityManager);
buildRule.executeTarget("testResultPropertyNonZeroNoFork");
assertEquals("-1", buildRule.getProject().getProperty("exitcode"));
}

@Test
public void testRunFailWithFailOnError() {
assumeTrue(SKIP_MSG_CAUSE_SYSTEM_EXIT_USE, allowedToIssueSystemExit);
assumeTrue(SKIP_SEC_MGR_USAGE, allowedToUseSecurityManager);
thrown.expect(BuildException.class);
thrown.expectMessage("Java returned:");
buildRule.executeTarget("testRunFailWithFailOnError");
Expand Down

0 comments on commit 8778136

Please sign in to comment.