Skip to content

Commit

Permalink
[fix] Avoid trying to read directories with java suffixes (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse authored Sep 25, 2022
1 parent e80a720 commit 396e97e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
extend-ignore = E501
4 changes: 2 additions & 2 deletions repobee_junit4/_junit4_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


LOGGER = daiquiri.getLogger(__file__)
HAMCREST_JAR_PATTERN = fr"([^{os.pathsep}]*hamcrest-core-1.3.jar)"
JUNIT4_JAR_PATTERN = fr"([^{os.pathsep}]*junit-4\.\d+\.(\d+\.)?jar)"
HAMCREST_JAR_PATTERN = rf"([^{os.pathsep}]*hamcrest-core-1.3.jar)"
JUNIT4_JAR_PATTERN = rf"([^{os.pathsep}]*junit-4\.\d+\.(\d+\.)?jar)"

_DEFAULT_SECURITY_POLICY_TEMPLATE = """grant {{
}};
Expand Down
4 changes: 3 additions & 1 deletion repobee_junit4/junit4.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def _compile_all(
a tuple of lists ``(succeeded, failed)``, where ``succeeded``
are tuples on the form ``(test_class, prod_class)`` paths.
"""
java_files = list(repo.path.rglob("*.java"))
java_files = [
file for file in repo.path.rglob("*.java") if file.is_file()
]
assignment_name = self._extract_assignment_name(repo.name)
reference_test_classes = self._find_test_classes(assignment_name)
test_classes = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This repo should pass all tests
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;
}
}
13 changes: 13 additions & 0 deletions tests/integration_tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
BAD_TESTS_REPO = REPO_DIR / "student-with-bad-tests-week-10"
DUPLICATE_TESTS_REPO = REPO_DIR / "student-with-duplicate-tests-week-10"
ENDLESS_WHILE_LOOP = REPO_DIR / "endless-loop-week-10"
DIRECTORY_WITH_JAVA_SUFFIX_REPO = (
REPO_DIR / "directory-with-java-suffix-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 Down Expand Up @@ -168,6 +171,16 @@ def test_runs_student_tests_correctly(self):
assert result.status == plug.Status.WARNING
assert "Student wrote a bad test" in str(result.msg)

def test_handles_directory_with_java_suffix(self):
"""Should not attempt to read a directory with .java suffix like a file."""
hooks = setup_hooks(verbose=True)

result = hooks.post_clone(
wrap_in_student_repo(DIRECTORY_WITH_JAVA_SUFFIX_REPO), api=None
)

assert result.status == plug.Status.SUCCESS

def test_handles_duplicate_student_tests(self):
hooks = setup_hooks(run_student_tests=True, verbose=True)

Expand Down

0 comments on commit 396e97e

Please sign in to comment.