Skip to content
Open
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* 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 com.palantir.baseline;

import static com.palantir.gradle.testing.assertion.GradlePluginTestAssertions.assertThat;

import com.palantir.gradle.testing.execution.GradleInvoker;
import com.palantir.gradle.testing.execution.InvocationResult;
import com.palantir.gradle.testing.junit.DisabledConfigurationCache;
import com.palantir.gradle.testing.junit.GradlePluginTests;
import com.palantir.gradle.testing.project.RootProject;
import org.junit.jupiter.api.Test;

@GradlePluginTests
@DisabledConfigurationCache("ProjectBuilder-based test converted to integration test")
class BaselineJavaCompilerDiagnosticsTest {

@Test
void test_default(GradleInvoker gradle, RootProject rootProject) {
rootProject.buildGradle().plugins().add("java");
rootProject.buildGradle().plugins().add("com.palantir.baseline-java-compiler-diagnostics");

rootProject.buildGradle().append("""
repositories {
mavenCentral()
}

tasks.withType(JavaCompile).configureEach {
doFirst {
logger.lifecycle("allCompilerArgs: {}", options.allCompilerArgs)
}
}
""");

rootProject.mainSourceSet().java().writeClass("""
package com.example;

public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
""");

InvocationResult result = gradle.withArgs("compileJava").buildsSuccessfully();

assertThat(result).output().as("Xmaxerrs should be set to 10000").contains("-Xmaxerrs", "10000");

assertThat(result).output().as("Xmaxwarns should be set to 10000").contains("-Xmaxwarns", "10000");
}

@Test
void test_overridden(GradleInvoker gradle, RootProject rootProject) {
rootProject.buildGradle().plugins().add("java");

rootProject.buildGradle().append("""
repositories {
mavenCentral()
}

tasks.named('compileJava', JavaCompile) {
options.compilerArgs += ['-Xmaxerrs', '1000']
}

tasks.withType(JavaCompile).configureEach {
doFirst {
logger.lifecycle("allCompilerArgs: {}", options.allCompilerArgs)
}
}
""");

rootProject.buildGradle().plugins().add("com.palantir.baseline-java-compiler-diagnostics");

rootProject.mainSourceSet().java().writeClass("""
package com.example;

public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
""");

InvocationResult result = gradle.withArgs("compileJava").buildsSuccessfully();

assertThat(result).output().as("Xmaxerrs should be overridden to 1000").contains("-Xmaxerrs", "1000");

assertThat(result).output().as("Xmaxwarns should still be present").contains("-Xmaxwarns");
}
}
Loading