Skip to content

Commit

Permalink
Programming exercises: Fix an issue when parsing empty files (#8964)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strohgelaender authored Jul 3, 2024
1 parent d1318b4 commit a6eade2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,14 @@ private BuildResult parseTestResults(TarArchiveInputStream testResultsTarInputSt
else {
// ugly workaround because in swift result files \n\t breaks the parsing
var testResultFileString = xmlString.replace("\n\t", "");
processTestResultFile(testResultFileString, failedTests, successfulTests);
if (!testResultFileString.isBlank()) {
processTestResultFile(testResultFileString, failedTests, successfulTests);
}
else {
String msg = "The file " + fileName + " does not contain any testcases.";
buildLogsMap.appendBuildLogEntry(buildJobId, msg);
log.warn(msg);
}
}
}
catch (IllegalStateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public abstract class AbstractSpringIntegrationLocalCILocalVCTest extends Abstra

protected static final Path OLD_REPORT_FORMAT_TEST_RESULTS_PATH = GRADLE_TEST_RESULTS_PATH.resolve("old-report-format");

protected static final Path EMPTY_TEST_RESULTS_PATH = GRADLE_TEST_RESULTS_PATH.resolve("empty");

private static final Path SCA_REPORTS_PATH = Path.of("src", "test", "resources", "test-data", "static-code-analysis", "reports");

protected static final Path SPOTBUGS_RESULTS_PATH = SCA_REPORTS_PATH.resolve("spotbugsXml.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,25 @@ void testStaticCodeAnalysis() throws IOException {
localVCLocalCITestService.testLatestSubmission(studentParticipation.getId(), commitHash, 1, false, true, 15, null);
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testEmptyResultFile() throws Exception {
ProgrammingExerciseStudentParticipation studentParticipation = localVCLocalCITestService.createParticipation(programmingExercise, student1Login);

localVCLocalCITestService.mockTestResults(dockerClient, EMPTY_TEST_RESULTS_PATH, LOCALCI_WORKING_DIRECTORY + LOCALCI_RESULTS_DIRECTORY);
localVCServletService.processNewPush(commitHash, studentAssignmentRepository.originGit.getRepository());
localVCLocalCITestService.testLatestSubmission(studentParticipation.getId(), commitHash, 0, true);

studentParticipation = programmingExerciseStudentParticipationRepository
.findByIdWithLatestResultAndFeedbacksAndRelatedSubmissions(studentParticipation.getId(), ZonedDateTime.now()).orElseThrow();
var result = studentParticipation.getResults().iterator().next();

var buildLogs = buildLogEntryService.getLatestBuildLogs((ProgrammingSubmission) result.getSubmission());

assertThat(buildLogs).isNotEmpty().anyMatch(log -> log.getLog().equals("The file results.xml does not contain any testcases.\n"))
.noneMatch(log -> log.getLog().contains("Exception"));
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testBuildLogs() throws IOException {
Expand Down
Empty file.

0 comments on commit a6eade2

Please sign in to comment.