Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,55 @@ import org.gradle.testkit.runner.TaskOutcome

class ElasticsearchTestBasePluginFuncTest extends AbstractGradleFuncTest {

def setup() {
// see https://github.com/gradle/gradle/issues/24172
configurationCacheCompatible = false
def "can disable assertions via cmdline param"() {
given:
file("src/test/java/acme/SomeTests.java").text = """
public class SomeTests {
@org.junit.Test
public void testAsserts() {
assert false;
}
}
"""
buildFile.text = """
plugins {
id 'java'
id 'elasticsearch.test-base'
}

repositories {
mavenCentral()
}

dependencies {
testImplementation 'junit:junit:4.12'
}
"""

when:
def result = gradleRunner("test").buildAndFail()
then:
result.task(':test').outcome == TaskOutcome.FAILED

when:
result = gradleRunner("test", "-Dtests.asserts=false").build()
then:
result.task(':test').outcome == TaskOutcome.SUCCESS

when:
result = gradleRunner("test", "-Dtests.jvm.argline=-da").build()
then:
result.task(':test').outcome == TaskOutcome.SUCCESS

when:
result = gradleRunner("test", "-Dtests.jvm.argline=-disableassertions").build()
then:
result.task(':test').outcome == TaskOutcome.SUCCESS

when:
result = gradleRunner("test", "-Dtests.asserts=false", "-Dtests.jvm.argline=-da").build()
then:
result.task(':test').outcome == TaskOutcome.SUCCESS
}

def "can configure nonInputProperties for test tasks"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ public void execute(Task t) {
test.jvmArgs((Object[]) argline.split(" "));
}

if (Util.getBooleanProperty("tests.asserts", true)) {
test.jvmArgs("-ea", "-esa");
// Check if "tests.asserts" is false or "tests.jvm.argline" contains the "-da" flag.
boolean disableAssertions = Util.getBooleanProperty("tests.asserts", true) == false
|| (argline != null && (argline.contains("-da")))
|| (argline != null && (argline.contains("-disableassertions")));

if (disableAssertions) {
System.out.println("disable assertions");
test.setEnableAssertions(false);
}

Map<String, String> sysprops = Map.of(
"java.awt.headless",
"true",
Expand Down