Skip to content

Commit b819561

Browse files
authored
Merge pull request #9 from CodinGame/runner-builder
Prepare for new builder-runner api
2 parents 19698d6 + 470e615 commit b819561

File tree

6 files changed

+97
-23
lines changed

6 files changed

+97
-23
lines changed

Dockerfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
FROM codingame/java-compiler
1+
FROM codingame/maven3-builder:1.0
22

33
# Copy files
4-
COPY target/junit-runner-0.0.1-SNAPSHOT-jar-with-dependencies.jar /usr/src/codingame/junit-runner/junit-runner.jar
5-
COPY src/main/resources/junit-runner /usr/src/codingame/junit-runner/
4+
COPY target/java-maven3-junit4-runner-0.0.1-SNAPSHOT-jar-with-dependencies.jar /usr/src/codingame/junit-runner/junit-runner.jar
5+
COPY docker/junit-runner /usr/src/codingame/junit-runner/
66

7+
ENV CG_RUN_DIR /project/answer
78

89
ENTRYPOINT ["/usr/src/codingame/junit-runner/junit-runner"]
10+

README.md

+71-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,71 @@
1-
# junit4-runner
2-
A junit version 4 tests runner which provides the expected json file.
1+
# java-maven3-junit4-runner
2+
3+
First, this runner compiles the project and generate all jars (project + dependencies).
4+
5+
At each play, it compiles user's answer using `javac` and run the specified testcase using junit4.
6+
7+
8+
# How to Use
9+
10+
To use this runner for your project, edit the `codingame.yml` file and add the following lines to your project:
11+
12+
runner:
13+
name: codingame/java-maven3-junit4-runner
14+
version: 1.1.0-java-8
15+
16+
## Example
17+
18+
**A Git repository example**
19+
20+
```
21+
.
22+
├── about.md
23+
├── codingame.yml
24+
├── markdowns
25+
│ └── <YOUR_LESSONS>.md
26+
└── projects
27+
└── example #Your project root
28+
├── src/main/java
29+
│ └── Example.java #The stub provided to the user
30+
└── src/test/java
31+
└── ExampleTest.java #Your JUnitTest Class
32+
```
33+
34+
**In your CS project:**
35+
36+
*Example.java*
37+
```java
38+
public class Example
39+
{
40+
/**
41+
* This method should return the sum between a and b
42+
**/
43+
public void sum(int a, int b) {
44+
return 1;
45+
}
46+
}
47+
```
48+
49+
*ExampleTestTest.java*
50+
```java
51+
import static org.junit.Assert.assertEquals;
52+
public class ExampleTest {
53+
private Example example;
54+
@Before
55+
public void init() {
56+
example = new Example();
57+
}
58+
59+
@Test
60+
public void testSum(){
61+
int a = 23487;
62+
int b = 240587;
63+
assertEquals(example.sum(a, b), a + b);
64+
}
65+
}
66+
```
67+
68+
**In your lesson:**
69+
```md
70+
@[Fix the following code so that the function DoSum returns a sum of integer]({"stubs": ["src/main/java/Example.java"],"command": "ExampleTest#testSum"})
71+
```

docker/junit-runner

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
compilationExitCode=0
3+
executionExitCode=0
4+
5+
JARS_DIR="/project/target/jars"
6+
WORKSPACE_DIR="/project/workspace"
7+
8+
cd ${CG_RUN_DIR}
9+
10+
classpath=$(echo ${JARS_DIR}/*.jar | tr ' ' ':')
11+
12+
find * -name "*.java" -print0 | xargs -0 /usr/src/codingame/java-compiler/cgjavac -Xlint:all -cp "$classpath" -d "${WORKSPACE_DIR}"
13+
compilationExitCode=$?
14+
15+
if [ $compilationExitCode -eq 0 ]; then
16+
java -cp "${WORKSPACE_DIR}:$classpath:/usr/src/codingame/junit-runner/junit-runner.jar" com.codingame.codemachine.runner.junit.JUnitTestListRunner $*
17+
else
18+
exit $compilationExitCode
19+
fi

hooks/pre_build

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ echo "=> Building the junit runner jar file"
33
docker run \
44
-v $(pwd):/usr/src/junit-runner \
55
-w /usr/src/junit-runner \
6-
maven:3 \
6+
maven:3-alpine \
77
mvn clean package

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.codingame.codemachine</groupId>
5-
<artifactId>junit-runner</artifactId>
5+
<artifactId>java-maven3-junit4-runner</artifactId>
66
<version>0.0.1-SNAPSHOT</version>
77

88
<properties>

src/main/resources/junit-runner

-16
This file was deleted.

0 commit comments

Comments
 (0)