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
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-avaje-inject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-avaje-jsonb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-checkerframework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-dagger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-dogfood/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-error-prone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-immutables/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-lombok/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-mapstruct/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-micronaut/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-serviceloader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/acceptance-tests-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>acceptance-tests</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>java-compiler-testing-parent</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion java-compiler-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>io.github.ascopes.jct</groupId>
<artifactId>java-compiler-testing-parent</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@

import io.github.ascopes.jct.compilers.JctCompilation;
import io.github.ascopes.jct.repr.TraceDiagnosticListRepresentation;
import io.github.ascopes.jct.utils.StringUtils;
import java.util.Collection;
import java.util.List;
import javax.tools.Diagnostic.Kind;
import javax.tools.JavaFileManager.Location;
import javax.tools.StandardLocation;
import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractListAssert;
import org.assertj.core.api.AbstractStringAssert;
import org.assertj.core.api.AssertFactory;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.FactoryBasedNavigableListAssert;
import org.assertj.core.api.StringAssert;
import org.jspecify.annotations.Nullable;

/**
Expand All @@ -48,6 +56,23 @@ public JctCompilationAssert(@Nullable JctCompilation value) {
super(value, JctCompilationAssert.class);
}

/**
* Assert that the arguments passed to the compiler were the expected values.
*
* @return a list assertion object to perform assertions on the arguments with.
* @throws AssertionError if the compilation was null.
*/
public AbstractListAssert<?, List<? extends String>, String, ? extends AbstractStringAssert<?>> arguments() {
isNotNull();

var arguments = actual.getArguments();

// TODO(ascopes): find a way to use Assertions::assertThat here instead of passing the
// StringAssert constructor around.
return FactoryBasedNavigableListAssert.assertThat(arguments, StringAssert::new)
.as("Compiler arguments %s", StringUtils.quotedIterable(arguments));
}

/**
* Assert that the compilation was successful.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@
@API(since = "0.0.1", status = Status.STABLE)
public interface JctCompilation {

/**
* Get the command line arguments that were passed to the compiler.
*
* <p>Note that this throws an unsupported operation exception by default
* to prevent breaking existing functionality. In v1.0.0, this will become
* required behaviour.
*
* @return the command line arguments.
* @since 0.5.0
*/
@API(since = "0.5.0", status = Status.STABLE)
default List<String> getArguments() {
throw new UnsupportedOperationException(
"This operation is not implemented, but will be mandatory in v1.0.0"
);
}

/**
* Determine if warnings were treated as errors.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private JctCompilation createCheckedCompilation(

return JctCompilationImpl
.builder()
.arguments(flags)
.compilationUnits(Set.copyOf(compilationUnits))
.fileManager(fileManager)
.outputLines(writer.getContent().lines().collect(toList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@API(since = "0.0.1", status = Status.INTERNAL)
public final class JctCompilationImpl implements JctCompilation {

private final List<String> arguments;
private final boolean success;
private final boolean failOnWarnings;
private final List<String> outputLines;
Expand All @@ -47,6 +48,10 @@ public final class JctCompilationImpl implements JctCompilation {
private final JctFileManager fileManager;

private JctCompilationImpl(Builder builder) {
arguments = unmodifiableList(
requireNonNullValues(builder.arguments, "arguments")
);

success = requireNonNull(
builder.success, "success"
);
Expand All @@ -67,6 +72,11 @@ private JctCompilationImpl(Builder builder) {
);
}

@Override
public List<String> getArguments() {
return arguments;
}

@Override
public boolean isSuccessful() {
return success;
Expand Down Expand Up @@ -103,6 +113,7 @@ public String toString() {
.attribute("success", success)
.attribute("failOnWarnings", failOnWarnings)
.attribute("fileManager", fileManager)
.attribute("arguments", arguments)
.toString();
}

Expand All @@ -124,6 +135,7 @@ public static Builder builder() {
@API(since = "0.0.1", status = Status.INTERNAL)
public static final class Builder {

private List<String> arguments;
private Boolean failOnWarnings;
private Boolean success;
private List<String> outputLines;
Expand All @@ -133,6 +145,7 @@ public static final class Builder {

private Builder() {
// Only initialized in this file.
arguments = null;
failOnWarnings = null;
success = null;
outputLines = null;
Expand All @@ -141,6 +154,17 @@ private Builder() {
fileManager = null;
}

/**
* Set the command-line arguments that were passed to the compiler.
*
* @param arguments the command-line arguments that were passed to the compiler.
* @return this builder.
*/
public Builder arguments(List<String> arguments) {
this.arguments = arguments;
return this;
}

/**
* Set whether to treat warnings as errors.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,23 @@ public static byte[] someBinaryData() {
return unboxed;
}

/**
* Get a random command line flag.
*
* @return a flag.
*/
public static String someFlag() {
return "--" + UUID.randomUUID();
}

/**
* Get some random command line flags.
*
* @return some flags.
*/
public static List<String> someFlags() {
return Stream
.generate(UUID::randomUUID)
.map(UUID::toString)
.map("--"::concat)
.generate(Fixtures::someFlag)
.limit(someInt(2, 4))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package io.github.ascopes.jct.tests.unit.assertions;

import static io.github.ascopes.jct.tests.helpers.Fixtures.someFlags;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -40,6 +42,42 @@
@DisplayName("JctCompilationAssert tests")
class JctCompilationAssertTest {

@DisplayName("JctCompilationAssert#arguments tests")
@Nested
class ArgumentsTest {

@DisplayName(".arguments() fails if the compilation is null")
@Test
void argumentsFailsIfCompilationIsNull() {
// Given
var assertions = new JctCompilationAssert(null);

// Then
assertThatThrownBy(assertions::arguments)
.isInstanceOf(AssertionError.class);
}

@DisplayName(".arguments() returns assertions on the arguments")
@Test
void argumentsReturnsAssertionsOnArguments() {
// Given
var compilation = mock(JctCompilation.class);
var arguments = someFlags();
when(compilation.getArguments())
.thenReturn(arguments);

// When
var assertions = new JctCompilationAssert(compilation).arguments();

// Then
assertThatCode(() -> assertions.containsExactlyElementsOf(arguments))
.doesNotThrowAnyException();

assertThatCode(() -> assertions.containsExactly("foo", "bar", "baz"))
.isInstanceOf(AssertionError.class);
}
}

@DisplayName("JctCompilationAssert#isSuccessful tests")
@Nested
class IsSuccessfulTest {
Expand Down
Loading