Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmladenov authored Jul 19, 2023
2 parents e51bfce + 2f42aaf commit 07d5511
Show file tree
Hide file tree
Showing 85 changed files with 971 additions and 365 deletions.
63 changes: 0 additions & 63 deletions .github/scripts/assignments_test.py

This file was deleted.

5 changes: 3 additions & 2 deletions .github/scripts/assignments_test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ def get_directories(basedir):
if os.path.isdir(os.path.join(basedir, dir)) \
and not dir.startswith('.')]

home_dir = '/home/runner/work/andy/andy/assignments'
docker_dir = '/home/runner/work/andy/andy/weblab-docker'
repo_name = os.environ['REPO_NAME']
home_dir = f'/home/runner/work/{repo_name}/{repo_name}/assignments'
docker_dir = f'/home/runner/work/{repo_name}/{repo_name}/weblab-docker'
test_dir = docker_dir + '/tests/github-ci'
output_dir = docker_dir + '/testresults'

Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/assignments_test_docker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: assignments_test_docker
on: [push, workflow_dispatch]
on: [push, pull_request, workflow_dispatch]
env:
# PR: github.sha is the SHA of the PR, not commit, we can't check this out
GHA_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
# PR: github.repository is the repository the PR is made in, not the fork
GHA_REPO: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }}
jobs:
run_assignments_docker:
runs-on: ubuntu-latest
Expand All @@ -21,12 +26,14 @@ jobs:
- name: Build Docker image
working-directory: ./weblab-docker
env:
BUILD_ARGS: "--build-arg ANDY_BRANCH=${{ github.sha }}"
BUILD_ARGS: "--build-arg ANDY_BRANCH=${{ env.GHA_SHA }} --build-arg ANDY_REPO=${{ env.GHA_REPO }}"
run: |
make
- name: Run the reference solutions of all assignments and verify the scores are 100/100
env:
COMMIT_HASH: ${{ github.sha }}
# github.repository contains owner, we don't want that
REPO_NAME: ${{ github.event.repository.name }}
COMMIT_HASH: ${{ env.GHA_SHA }}
run: |
python ./.github/scripts/assignments_test_docker.py
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ jobs:
path: ~/.m2
key: ${{ matrix.job.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ matrix.job.os }}-m2


- name: Run Checkstyle
run: mvn checkstyle:check

- name: Run Weblab runner tests
run: mvn test -pl weblab-runner -DexcludedGroups=selenium

10 changes: 10 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ Andy provides different checks for JUnit, Mockito, and JQWik tests:
- `LoopInTestMethods`: checks whether there is a loop in a test method.
- `UseOfStringLiterals`: checks whether there is a string literal in a test method.
- `MethodCalledInTestMethod`: checks whether a method was invoked in a test method.
- `ClassUsedInSolution`: checks whether a class was used anywhere in the test suite.
- `MethodCalledAnywhere`: checks whether a method was invoked in any scope.

- Mockito:
- `MockClass`: Checks whether a class was mocked in the test suite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.google.gson.Gson;
import nl.tudelft.cse1110.andy.Andy;
import nl.tudelft.cse1110.andy.config.DirectoryConfiguration;
import nl.tudelft.cse1110.andy.execution.Context.ContextBuilder;
import nl.tudelft.cse1110.andy.execution.Context.ContextDirector;
import nl.tudelft.cse1110.andy.execution.mode.Action;
import nl.tudelft.cse1110.andy.result.Result;
import nl.tudelft.cse1110.andy.utils.FilesUtils;
Expand All @@ -16,7 +19,6 @@
import java.nio.file.Path;
import java.util.Arrays;

import static nl.tudelft.cse1110.andy.execution.Context.build;
import static nl.tudelft.cse1110.andy.utils.FilesUtils.*;

public class AndyOnAWSLambda implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
Expand All @@ -30,11 +32,12 @@ public AWSResult run(AWSInput input) {
writeToFile(workDir, "Configuration.java", input.getConfiguration());
writeToFile(workDir, "Solution.java", input.getSolution());

nl.tudelft.cse1110.andy.execution.Context ctx = build(
ContextDirector director = new ContextDirector(new ContextBuilder());
nl.tudelft.cse1110.andy.execution.Context.Context ctx = director.constructWithLibraries(
Action.valueOf(input.getAction()),
workDir.toString(),
outputDir.toString(),
Arrays.asList(myself()));
new DirectoryConfiguration(workDir.toString(), outputDir.toString()),
Arrays.asList(myself())
);

Result result = new Andy().run(ctx);

Expand Down
49 changes: 49 additions & 0 deletions andy-checkstyle-checker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="^(?!.*(nl.tudelft.cse1110.andy))" />
</module>

<module name="SuppressWarningsFilter" />

<module name="TreeWalker">
<module name="SuppressWarningsHolder" />

<module name="MethodLength">
<property name="severity" value="error"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, COMPACT_CTOR_DEF"/>
<property name="max" value="50"/>
</module>

<module name="CyclomaticComplexity">
<property name="max" value="10"/>
<property name="tokens" value="LITERAL_WHILE, LITERAL_DO"/>
</module>

<module name="NestedIfDepthCheck" >
<property name="max" value="2"/>
</module>

<module name="UnnecessarySemicolonInEnumeration"/>
<module name="UnnecessarySemicolonInTryWithResources"/>
<module name="UnnecessarySemicolonAfterOuterTypeDeclaration"/>
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration"/>

<module name="DeclarationOrderCheck" />
<module name="EmptyStatementCheck" />
<module name="EqualsHashCodeCheck" />
<module name="MissingSwitchDefaultCheck" />
<module name="UnusedLocalVariableCheck" />
<module name="EmptyBlockCheck" />
<module name="EmptyCatchBlockCheck" />
<module name="StringLiteralEqualityCheck" />


</module>

</module>

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.google.common.io.Files;
import nl.tudelft.cse1110.andy.Andy;
import nl.tudelft.cse1110.andy.execution.Context;
import nl.tudelft.cse1110.andy.config.DirectoryConfiguration;
import nl.tudelft.cse1110.andy.execution.Context.Context;
import nl.tudelft.cse1110.andy.execution.Context.ContextBuilder;
import nl.tudelft.cse1110.andy.execution.Context.ContextDirector;
import nl.tudelft.cse1110.andy.execution.mode.Action;
import nl.tudelft.cse1110.andy.result.Result;
import nl.tudelft.cse1110.andy.writer.standard.StandardResultWriter;
Expand Down Expand Up @@ -72,11 +75,12 @@ public void execute() {
Timer workingIndicator = this.startWorkingIndicationTimer();

/* Run Andy! */
Context ctx = Context.build(
ContextDirector director = new ContextDirector(new ContextBuilder());
Context ctx = director.constructWithLibraries(
action(),
workDir.getAbsolutePath(),
outputDir.getAbsolutePath(),
compileClasspathElements);
new DirectoryConfiguration(workDir.getAbsolutePath(), outputDir.getAbsolutePath()),
compileClasspathElements
);

Result result = new Andy().run(ctx);

Expand Down
8 changes: 0 additions & 8 deletions andy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@

<dependencies>

<!-- https://mvnrepository.com/artifact/com.github.mauricioaniche/codesheriff -->
<dependency>
<groupId>com.github.mauricioaniche</groupId>
<artifactId>codesheriff</artifactId>
<version>0.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-reload4j</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion andy/src/main/java/nl/tudelft/cse1110/andy/Andy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nl.tudelft.cse1110.andy;

import nl.tudelft.cse1110.andy.execution.Context;
import nl.tudelft.cse1110.andy.execution.Context.Context;
import nl.tudelft.cse1110.andy.execution.ExecutionFlow;
import nl.tudelft.cse1110.andy.result.Result;

Expand Down
9 changes: 7 additions & 2 deletions andy/src/main/java/nl/tudelft/cse1110/andy/AndyLauncher.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package nl.tudelft.cse1110.andy;

import nl.tudelft.cse1110.andy.execution.Context;
import nl.tudelft.cse1110.andy.config.DirectoryConfiguration;
import nl.tudelft.cse1110.andy.execution.Context.Context;
import nl.tudelft.cse1110.andy.execution.Context.ContextBuilder;
import nl.tudelft.cse1110.andy.execution.Context.ContextDirector;
import nl.tudelft.cse1110.andy.execution.mode.Action;
import nl.tudelft.cse1110.andy.result.Result;
import nl.tudelft.cse1110.andy.writer.standard.StandardResultWriter;
Expand All @@ -16,7 +19,9 @@ public static void main(String[] args) {
Action action = getAction(args[0]);
String inputDir = args[1];
String outputDir = args[2];
Context ctx = Context.build(action, inputDir, outputDir);

ContextDirector director = new ContextDirector(new ContextBuilder());
Context ctx = director.constructBase(action, new DirectoryConfiguration(inputDir, outputDir));

StandardResultWriter writer = new StandardResultWriter();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package nl.tudelft.cse1110.andy.codechecker.checks;

import org.eclipse.jdt.core.dom.*;

/**
* Checks whether a class is used - instantiated or one of its methods called.
* Parameter:
* - the name of the method
* Output:
* - true if the class was used.
*
*/
public class ClassUsedInSolution extends WithinTestMethod {

private final String classToBeUsed;
private boolean classWasUsed = false;

public ClassUsedInSolution(String classToBeUsed) {
this.classToBeUsed = classToBeUsed;
}

/**
* Checks for class instance creations to
* check if the instantiated class if one of the classes
* we are looking for
*/
@Override
public boolean visit(ClassInstanceCreation cic) {
String className = cic.getType().toString();
if (classToBeUsed.equals(className))
classWasUsed = true;

return super.visit(cic);
}

/**
* Checks for method invocation to check if a static
* method of the said class is called. Uses Expression
*/
@Override
public boolean visit(MethodInvocation mi) {
Expression expression = mi.getExpression();
if (expression != null) {
if (expression.toString().equals(classToBeUsed))
classWasUsed = true;


}

return super.visit(mi);
}


@Override
public boolean result() {
return classWasUsed;
}

public String toString() {
return classToBeUsed + " class is used";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nl.tudelft.cse1110.andy.codechecker.checks;

import com.google.common.collect.ImmutableSet;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.NormalAnnotation;
Expand All @@ -11,15 +12,15 @@

public class JQWikProvideAnnotations extends Check {

private boolean provideAnnotationIdentified = false;
private static Set<String> JQWIK_PROVIDE_ANNOTATIONS = new HashSet<>(ImmutableSet.of(
"IntRange",
"Positive",
"Negative"

private static Set<String> JQWIK_PROVIDE_ANNOTATIONS = new HashSet<>() {{
add("IntRange");
add("Positive");
add("Negative");
// TODO: add all annotations here
));

// TODO: add all annotations here
}};
private boolean provideAnnotationIdentified = false;

@Override
public boolean visit(MarkerAnnotation node) {
Expand Down
Loading

0 comments on commit 07d5511

Please sign in to comment.