Skip to content

Commit 5e9c1eb

Browse files
committed
GH-294: Integration test compiling specific class names
1 parent 30f154f commit 5e9c1eb

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.github.ascopes.jct.tests.integration;
2+
3+
import static io.github.ascopes.jct.assertions.JctAssertions.assertThat;
4+
5+
import io.github.ascopes.jct.compilers.JctCompiler;
6+
import io.github.ascopes.jct.junit.JavacCompilerTest;
7+
import io.github.ascopes.jct.workspaces.Workspaces;
8+
import org.junit.jupiter.api.DisplayName;
9+
10+
/**
11+
* Integration tests that test the compilation of specific classes only.
12+
*
13+
* @author Ashley Scopes
14+
*/
15+
@DisplayName("Compiling specific classes integration tests")
16+
class CompilingSpecificClassesIntegrationTest {
17+
@DisplayName("Only the classes that I specify get compiled")
18+
@JavacCompilerTest
19+
void onlyTheClassesSpecifiedGetCompiled(JctCompiler<?, ?> compiler) {
20+
try (var workspace = Workspaces.newWorkspace()) {
21+
workspace
22+
.createSourcePathPackage()
23+
.copyContentsFrom("src", "test", "resources", "integration", "specificclasses");
24+
25+
var compilation = compiler.compile(workspace, "Fibonacci", "HelloWorld");
26+
27+
assertThat(compilation)
28+
.isSuccessfulWithoutWarnings()
29+
.classOutput()
30+
.packages()
31+
.allFilesExist("Fibonacci.class", "HelloWorld.class")
32+
.fileDoesNotExist("Sum.class");
33+
}
34+
}
35+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import static java.math.BigInteger.ONE;
2+
import static java.math.BigInteger.ZERO;
3+
4+
import java.math.BigInteger;
5+
6+
public class Fibonacci {
7+
public static void main(String[] args) {
8+
if (args.length != 1) {
9+
System.out.println("USAGE: java Fibonacci <n>");
10+
System.out.println(" <n> Fibonacci number to generate");
11+
}
12+
13+
BigInteger n = new BigInteger(args[0], 10);
14+
BigInteger a = ZERO;
15+
BigInteger b = ONE;
16+
17+
for (BigInteger i = ZERO; i.compareTo(n) < 0; i = i.add(ONE)) {
18+
BigInteger oldB = b;
19+
b = a.add(b);
20+
a = oldB;
21+
}
22+
23+
System.out.println(a);
24+
}
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class HelloWorld {
2+
public static void main(String[] args) {
3+
System.out.println("Hello, World!");
4+
}
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Sum {
2+
public static void main(String[] args) {
3+
long sum = 0;
4+
for (String arg : args) {
5+
sum += Integer.parseInt(arg);
6+
}
7+
System.out.println(sum);
8+
}
9+
}

0 commit comments

Comments
 (0)