Skip to content

Commit

Permalink
[junit-run] apply platform args to junit run java exec (pantsbuild#8421)
Browse files Browse the repository at this point in the history
### Problem
When a test is using a particular jvm platform, it should also use that platform's args. See pantsbuild#8419

### Solution

This patch changes the junit run task to include those args in the jvm_options kwarg passed to execute the test suite.

### Result

The args are now passed to Java.

### Follow on work
I think this isn't the only place with this issue. I found it in jvm run as well.
  • Loading branch information
baroquebobcat authored and stuhood committed Oct 9, 2019
1 parent 56ab110 commit abab906
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/python/pants/backend/jvm/tasks/junit_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def parse_error_handler(parse_error):
distribution=distribution,
classpath=complete_classpath,
main=JUnit.RUNNER_MAIN,
jvm_options=self.jvm_options + extra_jvm_options + list(target_jvm_options),
jvm_options=self.jvm_options + list(platform.args) + extra_jvm_options + list(target_jvm_options),
args=args + batch_tests,
workunit_factory=self.context.new_workunit,
workunit_name='run',
Expand Down
29 changes: 29 additions & 0 deletions tests/python/pants_test/backend/jvm/tasks/test_junit_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from textwrap import dedent

from pants.backend.jvm.subsystems.junit import JUnit
from pants.backend.jvm.subsystems.jvm_platform import JvmPlatform
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.backend.jvm.targets.junit_tests import JUnitTests
from pants.backend.jvm.tasks.coverage.cobertura import Cobertura
Expand Down Expand Up @@ -226,6 +227,34 @@ def test_junit_runner_extra_jvm_options(self):
}
"""))], target_name='tests/java/org/pantsbuild/foo:foo_test')

@ensure_cached(JUnitRun, expected_num_artifacts=1)
def test_junit_runner_platform_args(self):
self.make_target(
spec='tests/java/org/pantsbuild/foo:foo_test',
target_type=JUnitTests,
sources=['FooTest.java'],
test_platform='java8-extra',
#extra_jvm_options=['-Dexample.property=1'],
)
self.set_options_for_scope(JvmPlatform.options_scope,
platforms={
'java8-extra': {
'source': '8',
'target': '8',
'args': ['-Dexample.property=1'] },})
self._execute_junit_runner([('FooTest.java', dedent("""
package org.pantsbuild.foo;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class FooTest {
@Test
public void testFoo() {
String exampleProperty = System.getProperty("example.property");
assertTrue(exampleProperty != null && exampleProperty.equals("1"));
}
}
"""))], target_name='tests/java/org/pantsbuild/foo:foo_test')

@ensure_cached(JUnitRun, expected_num_artifacts=1)
def test_junit_runner_multiple_extra_jvm_options(self):
self.make_target(
Expand Down

0 comments on commit abab906

Please sign in to comment.