Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception handling Meta Tests #260

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -30,43 +30,44 @@ public String evaluate(String oldLibraryCode) {
}

@Override
public boolean execute(Context ctx, DirectoryConfiguration dirCfg, RunConfiguration runCfg) throws Exception {
/* Get the student solution, which we will run for each meta test */
String solutionFile = findSolution(dirCfg.getWorkingDir());

/* Get the original library content that we will keep changing according to the meta test */
File libraryFile = new File(findLibrary(dirCfg.getWorkingDir()));
String originalLibraryContent = readFile(libraryFile);

/*
* For each meta test, we basically perform a string replace in the
* original library code, recompile it, and run the tests.
* If there's a failing test, the meta test is killed.
*
* We reuse our execution framework to run the code with the meta test.
*/

/* Copy the library and replace the library by the meta test */
File metaWorkingDir = createTemporaryDirectory("metaWorkplace").toFile();
copyFile(solutionFile, metaWorkingDir.getAbsolutePath());
String metaFileContent = generateMetaFileContent(originalLibraryContent);
createMetaTestFile(metaWorkingDir, metaFileContent);

/* We then run the meta test, using our infrastructure */
Result metaResult = runMetaTest(ctx, dirCfg, metaWorkingDir);

/* And check the result. If there's a failing test, the test suite is good! */
int testsRan = metaResult.getTests().getTestsRan();
int testsSucceeded = metaResult.getTests().getTestsSucceeded();
boolean passesTheMetaTest = testsSucceeded < testsRan;

/* Clean up the directory */
deleteDirectory(metaWorkingDir);

/* Set the classloader back to the one with the student's original code */
Thread.currentThread().setContextClassLoader(ctx.getClassloaderWithStudentsCode());

return passesTheMetaTest;
public boolean execute(Context ctx, DirectoryConfiguration dirCfg, RunConfiguration runCfg)throws Exception{
{/* Get the student solution, which we will run for each meta test */
String solutionFile = findSolution(dirCfg.getWorkingDir());

/* Get the original library content that we will keep changing according to the meta test */
File libraryFile = new File(findLibrary(dirCfg.getWorkingDir()));
String originalLibraryContent = readFile(libraryFile);

/*
* For each meta test, we basically perform a string replace in the
* original library code, recompile it, and run the tests.
* If there's a failing test, the meta test is killed.
*
* We reuse our execution framework to run the code with the meta test.
*/

/* Copy the library and replace the library by the meta test */
File metaWorkingDir = createTemporaryDirectory("metaWorkplace").toFile();
copyFile(solutionFile, metaWorkingDir.getAbsolutePath());
String metaFileContent = generateMetaFileContent(originalLibraryContent);
createMetaTestFile(metaWorkingDir, metaFileContent);

/* We then run the meta test, using our infrastructure */
Result metaResult = runMetaTest(ctx, dirCfg, metaWorkingDir);

/* And check the result. If there's a failing test, the test suite is good! */
int testsRan = metaResult.getTests().getTestsRan();
int testsSucceeded = metaResult.getTests().getTestsSucceeded();
boolean passesTheMetaTest = testsSucceeded < testsRan;

/* Clean up the directory */
deleteDirectory(metaWorkingDir);

/* Set the classloader back to the one with the student's original code */
Thread.currentThread().setContextClassLoader(ctx.getClassloaderWithStudentsCode());

return passesTheMetaTest;
}
}

private String generateMetaFileContent(String originalLibraryContent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import nl.tudelft.cse1110.andy.execution.ExecutionStep;
import nl.tudelft.cse1110.andy.result.MetaTestResult;
import nl.tudelft.cse1110.andy.result.ResultBuilder;
import nl.tudelft.cse1110.andy.execution.mode.Mode;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -43,7 +44,15 @@ public void execute(Context ctx, ResultBuilder result) {

result.logMetaTests(score, totalWeight, metaTestResults);
} catch (Exception ex) {
result.genericFailure(this, ex);
if(runCfg.mode().equals(Mode.EXAM)){
System.out.println("Meta test compilation error occurred.");
result.genericFailure(this, ex);
}
else {
System.err.println("Meta test compilation error occurred:");
result.genericFailure(this, ex);
ex.printStackTrace(System.err);
}
} finally {
/* restore the class loader to the one before meta tests */
Thread.currentThread().setContextClassLoader(currentClassLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import nl.tudelft.cse1110.andy.config.MetaTest;
import nl.tudelft.cse1110.andy.execution.metatest.library.LibraryMetaTest;
import nl.tudelft.cse1110.andy.execution.mode.Mode;
import nl.tudelft.cse1110.andy.execution.Context.Context;
import nl.tudelft.cse1110.andy.config.RunConfiguration;
import nl.tudelft.cse1110.andy.config.DirectoryConfiguration;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.stream.Stream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;


public class LibraryMetaTestTest {

Expand Down