Skip to content

Commit

Permalink
Fix compile/runtime bug caused by whitespace in paths
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse committed Nov 18, 2018
1 parent 3d8d95c commit 70c413a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
12 changes: 7 additions & 5 deletions repomate_junit4/junit4.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,10 @@ def _junit(self, test_class, prod_class):
classpath = self._generate_classpath(test_class, prod_class)
test_class_name = test_class.name[:-len(test_class.
suffix)] # remove .java
command = "java -cp {} org.junit.runner.JUnitCore {}".format(
classpath, test_class_name).split()

command = [
"java", "-cp", classpath, "org.junit.runner.JUnitCore",
test_class_name
]
proc = subprocess.run(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Expand All @@ -394,8 +395,9 @@ def _javac(self, java_files: Iterable[Union[str, pathlib.Path]]
the message describes the outcome in plain text.
"""
classpath = self._generate_classpath()
command = 'javac -cp {} {}'.format(
classpath, ' '.join([str(f) for f in java_files])).split()
command = [
"javac", "-cp", classpath, *[str(path) for path in java_files]
]
proc = subprocess.run(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Expand Down
1 change: 1 addition & 0 deletions tests/repos/space-week-10/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This repo should pass all tests
23 changes: 23 additions & 0 deletions tests/repos/space-week-10/src/dir with spaces/Fibo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Class for calculating Fibonacci numbers.
*/

public class Fibo {
private long prev;
private long current;

public Fibo() {
prev = 0;
current = 1;
}

/**
* Generate the next Fibonacci number.
*/
public long next() {
long ret = prev;
prev = current;
current = ret + current;
return ret;
}
}
12 changes: 9 additions & 3 deletions tests/test_junit4.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
NO_TESTS_REPO = REPO_DIR / 'best-student-week-13'
NO_MASTER_MATCH_REPO = REPO_DIR / 'some-student-week-nope'
COMPILE_ERROR_REPO = REPO_DIR / 'compile-error-week-10'
DIR_PATHS_WITH_SPACES = REPO_DIR / 'space-week-10'

assert SUCCESS_REPO.exists(), "test pre-requisite error, dir must exist"
assert FAIL_REPO.exists(), "test pre-requisite error, dir must exist"
Expand All @@ -50,6 +51,8 @@
assert NO_MASTER_MATCH_REPO.exists(
), "test pre-requisite error, dir must exist"
assert COMPILE_ERROR_REPO.exists(), "test pre-requisite error, dir must exist"
assert DIR_PATHS_WITH_SPACES.exists(
), "test pre-reference error, dir must exit"

RTD = str(CUR_DIR / 'reference-tests')
JUNIT_PATH = str(pytest.constants.JUNIT_PATH)
Expand Down Expand Up @@ -229,6 +232,11 @@ def test_error_result_on_compile_error(self, hooks):
assert result.status == Status.ERROR
assert 'error: illegal start of type' in result.msg

def test_runs_correctly_when_paths_include_whitespace(self, hooks):
result = hooks.act_on_cloned_repo(DIR_PATHS_WITH_SPACES)

assert result.status == Status.SUCCESS


class TestParseArgs:
def test_all_args(self, junit4_hooks, full_args):
Expand Down Expand Up @@ -265,8 +273,7 @@ def test_defaults_are_kept_if_not_specified_in_args(
"""Test that defaults are not overwritten if they are falsy in the
args.
"""
args = Args(
master_repo_names=MASTER_REPO_NAMES)
args = Args(master_repo_names=MASTER_REPO_NAMES)
expected_ignore_tests = ['some', 'tests']
expected_hamcrest_path = 'some/path/to/{}'.format(junit4.HAMCREST_JAR)
expected_junit_path = 'other/path/to/{}'.format(junit4.JUNIT_JAR)
Expand Down Expand Up @@ -376,7 +383,6 @@ def test_args_not_required_if_in_config(self, junit4_hooks,
parser.parse_args([]) # should not crash



def test_register():
"""Just test that there is no crash"""
plug.manager.register(junit4)

0 comments on commit 70c413a

Please sign in to comment.