Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run the NativeCmd integration test with and without the configuration cache #2358

Merged
merged 4 commits into from
Dec 9, 2024
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 lib/src/main/java/com/diffplug/spotless/FileSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static Promised promise(Iterable<File> files) {
}

public static Promised promise(File file) {
return new Promised(List.of(file), null);
return new Promised(MoreIterables.toNullHostileList(List.of(file)), null);
}

/** Returns all of the files in this signature, throwing an exception if there are more or less than 1 file. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 DiffPlug
* Copyright 2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,26 +20,40 @@
import java.io.File;
import java.io.IOException;

import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Test;

class NativeCmdIntegrationTest extends GradleIntegrationHarness {
interface NativeCmdIntegrationTest {
@Test
void nativeCmd() throws IOException {
default void nativeCmd() throws IOException {
// This will only work if /usr/bin/sed is available
assumeThat(new File("/usr/bin/sed")).exists();

setFile("build.gradle").toLines(
GradleIntegrationHarness harness = (GradleIntegrationHarness) this;
harness.setFile("build.gradle").toLines(
"plugins {",
" id 'com.diffplug.spotless'",
"}",
"spotless {",
" lineEndings 'UNIX'",
" format 'test', {",
" target '**/*.txt'",
" target '*.txt'",
" nativeCmd('sed', '/usr/bin/sed', ['s/placeholder/replaced/g'])",
" }",
"}");
setFile("test.txt").toResource("native_cmd/dirty.txt");
gradleRunner().withArguments("spotlessApply").build();
assertFile("test.txt").sameAsResource("native_cmd/clean.txt");
harness.setFile("test.txt").toResource("native_cmd/dirty.txt");
harness.gradleRunner().withArguments("spotlessApply", "--stacktrace").build();
harness.assertFile("test.txt").sameAsResource("native_cmd/clean.txt");
}

class NativeCmdWithoutConfigCacheTest extends GradleIntegrationHarness implements NativeCmdIntegrationTest {}

class NativeCmdWithConfigCacheTest extends GradleIntegrationHarness implements NativeCmdIntegrationTest {
@Override
public GradleRunner gradleRunner() throws IOException {
setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true");
setFile("gradle.properties").toContent("org.gradle.configuration-cache=true");
return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

import org.assertj.core.api.Assertions;
import org.gradle.testkit.runner.BuildResult;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import com.diffplug.common.base.Predicates;

@Disabled("https://status.npmjs.org/ shows npm services down on 12/8/2024, should undisable this later")
class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness {

@Test
Expand Down
Loading