Skip to content

Commit 3750e34

Browse files
committed
GH-294: Integration test compiling specific class names
1 parent 5b67a71 commit 3750e34

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.github.ascopes.jct.tests.integration;
17+
18+
import static io.github.ascopes.jct.assertions.JctAssertions.assertThat;
19+
20+
import io.github.ascopes.jct.compilers.JctCompiler;
21+
import io.github.ascopes.jct.junit.JavacCompilerTest;
22+
import io.github.ascopes.jct.workspaces.Workspaces;
23+
import org.junit.jupiter.api.DisplayName;
24+
25+
/**
26+
* Integration tests that test the compilation of specific classes only.
27+
*
28+
* @author Ashley Scopes
29+
*/
30+
@DisplayName("Compiling specific classes integration tests")
31+
class CompilingSpecificClassesIntegrationTest {
32+
@DisplayName("Only the classes that I specify get compiled")
33+
@JavacCompilerTest
34+
void onlyTheClassesSpecifiedGetCompiled(JctCompiler<?, ?> compiler) {
35+
try (var workspace = Workspaces.newWorkspace()) {
36+
workspace
37+
.createSourcePathPackage()
38+
.copyContentsFrom("src", "test", "resources", "integration", "specificclasses");
39+
40+
var compilation = compiler.compile(workspace, "Fibonacci", "HelloWorld");
41+
42+
assertThat(compilation)
43+
.isSuccessfulWithoutWarnings()
44+
.classOutput()
45+
.packages()
46+
.allFilesExist("Fibonacci.class", "HelloWorld.class")
47+
.fileDoesNotExist("Sum.class");
48+
}
49+
}
50+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import static java.math.BigInteger.ONE;
17+
import static java.math.BigInteger.ZERO;
18+
19+
import java.math.BigInteger;
20+
21+
/**
22+
* Command line app to calculate the nth number of the fibonacci sequence.
23+
*/
24+
public class Fibonacci {
25+
public static void main(String[] args) {
26+
if (args.length != 1) {
27+
System.out.println("USAGE: java Fibonacci <n>");
28+
System.out.println(" <n> Fibonacci number to generate");
29+
}
30+
31+
BigInteger n = new BigInteger(args[0], 10);
32+
BigInteger a = ZERO;
33+
BigInteger b = ONE;
34+
35+
for (BigInteger i = ZERO; i.compareTo(n) < 0; i = i.add(ONE)) {
36+
BigInteger oldB = b;
37+
b = a.add(b);
38+
a = oldB;
39+
}
40+
41+
System.out.println(a);
42+
}
43+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Command line app that says hello to me.
19+
*/
20+
public class HelloWorld {
21+
public static void main(String[] args) {
22+
System.out.println("Hello, World!");
23+
}
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Command line app that sums together given integers.
19+
*/
20+
public class Sum {
21+
public static void main(String[] args) {
22+
long sum = 0;
23+
for (String arg : args) {
24+
sum += Integer.parseInt(arg);
25+
}
26+
System.out.println(sum);
27+
}
28+
}

0 commit comments

Comments
 (0)