Skip to content

Commit

Permalink
Make KtLintCompat0Dot48Dot0AdapterTest workable
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 24, 2023
1 parent c4df046 commit 057f6c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ dependencies {
spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes)

apply from: rootProject.file('gradle/special-tests.gradle')
tasks.withType(Test).configureEach {
def jdkVersion = JavaVersion.current().majorVersion.toInteger()
def args = []
if (jdkVersion >= 16) {
// https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers
args += [
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED",
]
}
if (jdkVersion >= 18) {
// https://openjdk.org/jeps/411
args += "-Djava.security.manager=allow"
}
jvmArgs(args)
}

jar {
for (glue in NEEDS_GLUE) {
from sourceSets.getByName(glue).output.classesDirs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -33,27 +34,29 @@ public class KtLintCompat0Dot48Dot0AdapterTest {
public void testDefaults(@TempDir Path path) throws IOException {
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
String text = loadAndWriteText(path, "empty_class_body.kt");
final Path filePath = Paths.get(path.toString(), "empty_class_body.kt");

Map<String, String> userData = new HashMap<>();

Map<String, Object> editorConfigOverrideMap = new HashMap<>();

String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap);
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap);
assertEquals("class empty_class_body\n", formatted);
}

@Test
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
String text = loadAndWriteText(path, "fails_no_semicolons.kt");
final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt");

Map<String, String> userData = new HashMap<>();

Map<String, Object> editorConfigOverrideMap = new HashMap<>();
editorConfigOverrideMap.put("indent_style", "tab");
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");

String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap);
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap);
assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted);
}

Expand Down

0 comments on commit 057f6c4

Please sign in to comment.