Skip to content

Commit

Permalink
chore: Add a windows build for Java 1.8 (#3746)
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse authored Jan 13, 2021
1 parent 51f1dc6 commit e815c80
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 4 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
java: [1.8, 11, 15]
name: Tests with Java ${{ matrix.java }}
os: [ubuntu-latest, windows-latest]
exclude:
- os: windows-latest
java: 11
- os: windows-latest
java: 15

name: Tests with Java ${{ matrix.java }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
- uses: actions/setup-java@d202f5dbf7256730fb690ec59f6381650114feb2 # v1.4.3
Expand All @@ -30,7 +37,9 @@ jobs:
- name: Use silent log config
run: mv chore/travis/logback.xml src/test/resources/
- name: Build and test
run: mvn -Djava.src.version=${{ matrix.java }} test
env:
MAVEN_OPTS: -Djava.src.version=${{ matrix.java }}
run: mvn test

coverage:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/spoon/MavenLauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;

public class MavenLauncherTest {

Expand Down Expand Up @@ -138,6 +139,7 @@ public void mavenLauncherOnDirectoryWithoutPomTest() {

@Test
public void testSystemDependency() {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: scope dependencies are added to classpath
MavenLauncher launcher = new MavenLauncher("./src/test/resources/maven-launcher/system-dependency", MavenLauncher.SOURCE_TYPE.ALL_SOURCE);
assertEquals(1, launcher.getEnvironment().getSourceClasspath().length);
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/spoon/test/SpoonTestHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assume.assumeFalse;

public class SpoonTestHelpers {
// only static methods
private SpoonTestHelpers(){
Expand Down Expand Up @@ -144,4 +146,9 @@ public static boolean isMetamodelProperty(CtType<?> baseType, CtMethod<?> m) {
// return type
isMetamodelRelatedType(m.getType());
}

/** Place at the top of a JUnit4 test method to disable it for Windows. */
public static void assumeNotWindows() {
assumeFalse(System.getProperty("os.name").toLowerCase().contains("windows"));
}
}
2 changes: 2 additions & 0 deletions src/test/java/spoon/test/comment/CommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;

public class CommentTest {

Expand Down Expand Up @@ -798,6 +799,7 @@ public void testAddCommentsToSnippet() {

@Test
public void testDocumentationContract() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
// contract: all metamodel classes must be commented with an example.

final Launcher launcher = new Launcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;


/**
Expand Down Expand Up @@ -284,6 +285,7 @@ private Charset detectEncodingDummy(SpoonFile unused, byte[] fileBytes) {

@Test
public void testDifferentEncodings() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: both utf-8 and cp1251 files in the same project should be handled properly
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/resources/encodings/Cp1251.java");
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/spoon/test/field/FieldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;
import static spoon.testing.utils.ModelUtils.buildClass;
import static spoon.testing.utils.ModelUtils.createFactory;

Expand Down Expand Up @@ -191,6 +192,7 @@ public void getFQNofFieldReference() {

@Test
public void bugAfterRefactoringImports() {
assumeNotWindows(); // FIXME Make test case pass on Windows
Launcher launcher = new Launcher();
Factory factory = launcher.getFactory();
final CtClass<?> klass = factory.createClass("foo.A");
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/spoon/test/imports/ImportScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;
import static spoon.testing.utils.ModelUtils.build;

public class ImportScannerTest {

@Test
public void testImportOnSpoon() throws IOException {
assumeNotWindows(); // FIXME Make test case pass on Windows

File targetDir = new File("./target/import-test");
Launcher spoon = new Launcher();
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/spoon/test/imports/ImportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;
import static spoon.testing.utils.ModelUtils.canBeBuilt;

public class ImportTest {
Expand Down Expand Up @@ -1583,6 +1584,7 @@ public void testFQNJavadoc() {
}
@Test
public void testImportOnSpoon() throws IOException {
assumeNotWindows(); // FIXME Make test case pass on Windows

File targetDir = new File("./target/import-test");
Launcher spoon = new Launcher();
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/spoon/test/model/IncrementalLauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -57,6 +58,7 @@ private CtType<?> getTypeByName(Collection<CtType<?>> types, String name) {

@Test
public void testCache() throws IOException {
assumeNotWindows(); // FIXME Make test case pass on Windows
// Build model from A.java, B.java, C.java, D.java, and then load the same model from cache several times.
FileUtils.copyDirectory(ORIGINAL_FILES_DIR, WORKING_DIR);

Expand Down Expand Up @@ -92,6 +94,7 @@ public void testCache() throws IOException {

@Test
public void testIncremental1() throws IOException, InterruptedException {
assumeNotWindows(); // FIXME Make test case pass on Windows
// Build model from A.java, B.java, C.java, D.java, then change D.java => load A, B, C from cache and build D.
FileUtils.copyDirectory(ORIGINAL_FILES_DIR, WORKING_DIR);

Expand Down Expand Up @@ -138,6 +141,7 @@ public void testIncremental1() throws IOException, InterruptedException {

@Test
public void testIncremental2() throws IOException {
assumeNotWindows(); // FIXME Make test case pass on Windows
// Build model from A.java, B.java, C.java, then remove C.java and add D.java
FileUtils.copyDirectory(ORIGINAL_FILES_DIR, WORKING_DIR);

Expand Down Expand Up @@ -178,6 +182,7 @@ public void testIncremental2() throws IOException {

@Test
public void testIncremental3() throws IOException, InterruptedException {
assumeNotWindows(); // FIXME Make test case pass on Windows
// Build model from A.java, B.java, C.java, then change type of field val in C.
// B refers to C, so we should check reference resolution in B as well.
FileUtils.copyDirectory(ORIGINAL_FILES_DIR, WORKING_DIR);
Expand Down Expand Up @@ -227,6 +232,7 @@ public void testIncremental3() throws IOException, InterruptedException {

@Test
public void testSaveCacheIssue3404() {
assumeNotWindows(); // FIXME Make test case pass on Windows
// contract: IncrementalLauncher does not crash with classnotfound in noclasspath
// see isse 3404
Set<File> inputResources = new HashSet<>();
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/spoon/test/pkg/PackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;
import static spoon.testing.Assert.assertThat;
import static spoon.testing.utils.ModelUtils.canBeBuilt;

public class PackageTest {

@Test
public void testPackage() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
final String classFilePath = "./src/test/java/spoon/test/pkg/name/PackageTestClass.java";
final String packageInfoFilePath = "./src/test/java/spoon/test/pkg/package-info.java";
final File packageInfoFile = new File(packageInfoFilePath);
Expand Down
23 changes: 22 additions & 1 deletion src/test/java/spoon/test/position/PositionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
import spoon.support.compiler.VirtualFile;
import spoon.support.reflect.CtExtendedModifier;
import spoon.test.comment.testclasses.BlockComment;
import spoon.test.comment.testclasses.Comment1;import spoon.test.position.testclasses.AnnonymousClassNewIface;
import spoon.test.comment.testclasses.Comment1;
import spoon.test.position.testclasses.AnnonymousClassNewIface;
import spoon.test.position.testclasses.ArrayArgParameter;
import spoon.test.position.testclasses.CatchPosition;
import spoon.test.position.testclasses.CompilationUnitComments;
Expand Down Expand Up @@ -109,13 +110,15 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;
import static spoon.testing.utils.ModelUtils.build;
import static spoon.testing.utils.ModelUtils.buildClass;

public class PositionTest {

@Test
public void testPositionClass() {
assumeNotWindows(); // FIXME Make test case pass on Windows
final Factory build = build(new File("src/test/java/spoon/test/position/testclasses/"));
final CtType<FooClazz> foo = build.Type().get(FooClazz.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -147,6 +150,7 @@ public void testPositionClass() {

@Test
public void testPositionClassWithComments() {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: check that comments before and after the 'class' keyword are handled well by PositionBuilder
//and it produces correct `modifierEnd`
final Factory build = build(new File("src/test/java/spoon/test/position/testclasses/"));
Expand Down Expand Up @@ -187,6 +191,7 @@ public void testPositionClassWithComments() {

@Test
public void testPositionParameterTypeReference() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: the parameterized type reference has a source position which includes parameter types, etc.
final CtType<?> foo = buildClass(PositionParameterTypeWithReference.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -234,6 +239,7 @@ public void testPositionParameterTypeReference() throws Exception {

@Test
public void testPositionInterface() {
assumeNotWindows(); // FIXME Make test case pass on Windows
final Factory build = build(new File("src/test/java/spoon/test/position/testclasses/"));
final CtType<FooInterface> foo = build.Type().get(FooInterface.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -268,6 +274,7 @@ public void testPositionInterface() {

@Test
public void testPositionAnnotation() {
assumeNotWindows(); // FIXME Make test case pass on Windows
final Factory build = build(new File("src/test/java/spoon/test/position/testclasses/"));
final CtType<FooAnnotation> foo = build.Type().get(FooAnnotation.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -311,6 +318,7 @@ public void testPositionAnnotation() {

@Test
public void testPositionField() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
final Factory build = build(FooField.class);
final CtType<FooField> foo = build.Type().get(FooField.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -374,6 +382,7 @@ public void testPositionField() throws Exception {

@Test
public void testPositionGeneric() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
final Factory build = build(FooGeneric.class);
final CtClass<FooGeneric> foo = build.Class().get(FooGeneric.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -435,6 +444,7 @@ public void testPositionTerminates() {

@Test
public void testPositionMethod() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
final Factory build = build(FooMethod.class);
final CtClass<FooMethod> foo = build.Class().get(FooMethod.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -505,6 +515,7 @@ public void testPositionMethod() throws Exception {

@Test
public void testPositionAbstractMethod() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
final Factory build = build(FooAbstractMethod.class);
final CtClass<FooMethod> foo = build.Class().get(FooAbstractMethod.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -539,6 +550,7 @@ public void testPositionAbstractMethod() throws Exception {

@Test
public void testPositionStatement() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
final Factory build = build(FooStatement.class);
final CtType<FooStatement> foo = build.Type().get(FooStatement.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -732,6 +744,7 @@ public void testPositionMethodTypeParameter() throws Exception {

@Test
public void testPositionOfAnnonymousType() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: the annonymous type has consistent position
final CtEnum foo = (CtEnum) buildClass(SomeEnum.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -916,6 +929,7 @@ public void testPositionTryCatch() throws Exception {
}
@Test
public void testArrayArgParameter() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: the parameter declared like `String arg[]`, `String[] arg` and `String []arg` has correct positions
final CtType<?> foo = buildClass(ArrayArgParameter.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -966,6 +980,7 @@ public void testArrayArgParameter() throws Exception {

@Test
public void testExpressions() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: the expression including type casts has correct position which includes all brackets too
final CtType<?> foo = buildClass(Expressions.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -1012,6 +1027,7 @@ public void testExpressions() throws Exception {
}
@Test
public void testCatchPosition() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: check the catch position
final CtType<?> foo = buildClass(CatchPosition.class);
String classContent = getClassContent(foo);
Expand Down Expand Up @@ -1074,6 +1090,7 @@ public void testCatchPosition() throws Exception {
}
@Test
public void testEnumConstructorCallComment() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: check position the enum constructor call
final CtType<?> foo = buildClass(FooEnum.class);

Expand All @@ -1091,6 +1108,7 @@ public void testEnumConstructorCallComment() throws Exception {
}
@Test
public void testSwitchCase() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: check position of the statements of the case of switch
final CtType<?> foo = buildClass(FooSwitch.class);

Expand Down Expand Up @@ -1128,6 +1146,7 @@ public void testSwitchCase() throws Exception {
}
@Test
public void testFooForEach() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
//contract: check position of the for each position
final CtType<?> foo = buildClass(FooForEach.class);

Expand Down Expand Up @@ -1269,6 +1288,7 @@ public void testPackageDeclarationPosition() throws Exception {

@Test
public void testImportPosition() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
// contract: import position includes its comment
CtType<?> type = ModelUtils.buildClass(cfg -> {
cfg.getEnvironment().setCommentEnabled(true);
Expand All @@ -1286,6 +1306,7 @@ public void testImportPosition() throws Exception {

@Test
public void testPackageDeclarationWithCommentPosition() throws Exception {
assumeNotWindows(); // FIXME Make test case pass on Windows
// contract: package declaration position includes its comment. The file comment is not included
CtType<?> type = ModelUtils.buildClass(cfg -> {
cfg.getEnvironment().setCommentEnabled(true);
Expand Down
Loading

0 comments on commit e815c80

Please sign in to comment.