Skip to content

Commit

Permalink
Run the NativeCmd integration test with and without the configuration…
Browse files Browse the repository at this point in the history
… cache (#2358 fixes #2347)
  • Loading branch information
nedtwigg authored Dec 9, 2024
2 parents 339d2c9 + 4938c84 commit 671b6ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
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

0 comments on commit 671b6ee

Please sign in to comment.