Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions acceptance-tests/acceptance-tests-manifold-systems/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>acceptance-tests-manifold-systems</artifactId>

<properties>
<manifold.version>2022.1.26</manifold.version>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>java-compiler-testing</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>systems.manifold</groupId>
<artifactId>manifold-preprocessor</artifactId>
<version>${manifold.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>systems.manifold</groupId>
<artifactId>manifold-tuple</artifactId>
<version>${manifold.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>

<configuration>
<!-- Breaks checkstyle due to syntax voodoo in Manifold. -->
<excludes>**/resources/**</excludes>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>

<configuration>
<failIfNoTests>true</failIfNoTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2022 - 2022 Ashley Scopes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.acceptancetests.manifold

import io.github.ascopes.jct.compilers.JctCompiler
import org.junit.jupiter.api.condition.JRE

import static io.github.ascopes.jct.compilers.JctCompilerConfigurer.JctSimpleCompilerConfigurer
import static org.assertj.core.api.Assumptions.assumeThat

/**
* Configurer that sets up Javac to invoke Manifold processors.
*/
final class ManifoldPluginConfigurer implements JctSimpleCompilerConfigurer {

@Override
void configure(JctCompiler compiler) {
assumeThat(JRE.currentVersion())
.as("Manifold accesses internal JRE components at runtime which breaks after JDK 15")
.isLessThanOrEqualTo(JRE.JAVA_15)

// TODO(ascopes): look into what is breaking this. Guess there is incompatibility somewhere.
assumeThat(JRE.currentVersion())
.as("Manifold triggers exceptions after JDK 11")
.isLessThanOrEqualTo(JRE.JAVA_11)

compiler.addCompilerOptions("-Xplugin:Manifold")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright (C) 2022 - 2022 Ashley Scopes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.acceptancetests.manifold

import io.github.ascopes.jct.compilers.JctCompiler
import io.github.ascopes.jct.junit.JavacCompilerTest
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.DisplayName

import static io.github.ascopes.jct.assertions.JctAssertions.assertThatCompilation
import static io.github.ascopes.jct.pathwrappers.TempDirectory.newTempDirectory
import static org.assertj.core.api.Assertions.assertThat

@DisplayName("Manifold Preprocessor acceptance tests")
@SuppressWarnings('GrUnresolvedAccess')
class ManifoldPreprocessorTest {
@DisplayName("Preprocessor produces the expected code when a preprocessor symbol is defined")
@JavacCompilerTest(configurers = [ManifoldPluginConfigurer])
void preprocessorProducesTheExpectedCodeWhenPreprocessorSymbolIsDefined(JctCompiler compiler) {
// Given
def sources = newTempDirectory("sources")
.createDirectory("org", "example")
.copyContentsFrom("src", "test", "resources", "code", "preprocessor", "if")
.createFile("build.properties").withContents("SOME_SYMBOL=1")

// When
def compilation = compiler
.addSourcePath(sources)
.compile()

// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings()

String greeting = compilation
.classOutputs
.classLoader
.loadClass("org.example.HelloWorld")
.getDeclaredConstructor()
.newInstance()
.getGreeting()

assertThat(greeting).isEqualTo("Hello, World! (symbol was defined)")
}

@DisplayName("Preprocessor produces the expected code when a preprocessor symbol is undefined")
@JavacCompilerTest(configurers = [ManifoldPluginConfigurer])
void preprocessorProducesTheExpectedCodeWhenPreprocessorSymbolIsUndefined(JctCompiler compiler) {
// Given
def sources = newTempDirectory("sources")
.createDirectory("org", "example")
.copyContentsFrom("src", "test", "resources", "code", "preprocessor", "if")

// When
def compilation = compiler
.addSourcePath(sources)
.compile()

// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings()

String greeting = compilation
.classOutputs
.classLoader
.loadClass("org.example.HelloWorld")
.getDeclaredConstructor()
.newInstance()
.getGreeting()

assertThat(greeting).isEqualTo("Hello, World! (symbol was not defined)")
}

@Disabled("See https://github.com/manifold-systems/manifold/issues/399")
@DisplayName("Warning directives produce compiler warnings in JCT")
@JavacCompilerTest(configurers = [ManifoldPluginConfigurer])
void warningDirectivesProduceCompilerWarningsInJct(JctCompiler compiler) {
// Given
def sources = newTempDirectory("sources")
.createDirectory("org", "example")
.copyContentsFrom("src", "test", "resources", "code", "preprocessor", "warning")

// When
def compilation = compiler
.addSourcePath(sources)
.compile()

// Then
assertThatCompilation(compilation)
.isSuccessful()
.diagnostics().warnings().singleElement()
.message().isEqualTo("Hello, this is a friendly warning!")
}

@DisplayName("Error directives produce compiler errors in JCT")
@JavacCompilerTest(configurers = [ManifoldPluginConfigurer])
void warningDirectivesProduceCompilerErrorsInJct(JctCompiler compiler) {
// Given
def sources = newTempDirectory("sources")
.createDirectory("org", "example")
.copyContentsFrom("src", "test", "resources", "code", "preprocessor", "error")

// When
def compilation = compiler
.addSourcePath(sources)
.compile()

// Then
assertThatCompilation(compilation)
.isFailure()
.diagnostics().errors().singleElement()
.message().isEqualTo("Hello, this is an error!")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2022 - 2022 Ashley Scopes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.acceptancetests.manifold

import io.github.ascopes.jct.compilers.JctCompiler
import io.github.ascopes.jct.junit.JavacCompilerTest
import org.junit.jupiter.api.DisplayName

import static io.github.ascopes.jct.assertions.JctAssertions.assertThatCompilation
import static io.github.ascopes.jct.pathwrappers.TempDirectory.newTempDirectory
import static org.assertj.core.api.Assertions.assertThat
import static org.assertj.core.api.SoftAssertions.assertSoftly

@DisplayName("Manifold Tuple acceptance tests")
@SuppressWarnings(["GroovyAssignabilityCheck", "GrUnresolvedAccess"])
class ManifoldTupleTest {
@DisplayName("Tuple expressions compile as expected")
@JavacCompilerTest(configurers = [ManifoldPluginConfigurer])
void tupleExpressionsCompileAsExpected(JctCompiler compiler) {
// Given
def sources = newTempDirectory("sources")
.createDirectory("org", "example")
.copyContentsFrom("src", "test", "resources", "code", "tuple")

// When
def compilation = compiler
.addSourcePath(sources)
.compile()

// Then
assertThatCompilation(compilation)
.isSuccessfulWithoutWarnings()

def userType = compilation
.classOutputs
.classLoader
.loadClass("org.example.User")
.getDeclaredConstructor(long, String, int)

def users = [
userType.newInstance(123, "Roy Rodgers McFreely", 25),
userType.newInstance(456, "Steve-O", 30),
userType.newInstance(789, "Dave Davison", 23)
]

def oldestUsers = compilation
.classOutputs
.classLoader
.loadClass("org.example.UserRecords")
.oldestUsers(users)

assertThat(oldestUsers).hasSize(3)

assertSoftly { softly ->
softly.assertThat(oldestUsers[0].name).isEqualTo("Steve-O")
softly.assertThat(oldestUsers[0].age).isEqualTo(30)
softly.assertThat(oldestUsers[1].name).isEqualTo("Roy Rodgers McFreely")
softly.assertThat(oldestUsers[1].age).isEqualTo(25)
softly.assertThat(oldestUsers[2].name).isEqualTo("Dave Davison")
softly.assertThat(oldestUsers[2].age).isEqualTo(23)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 - 2022 Ashley Scopes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.example;

/**
* Preprocessor test snippet.
*
* @author Ashley Scopes
*/
public class ClassWithErrors {
#error "Hello, this is an error!"
}
Loading