Added soft assertions
This commit is contained in:
parent
27bc3a0997
commit
09c324c8de
2 changed files with 119 additions and 97 deletions
|
@ -16,6 +16,7 @@
|
|||
|
||||
package rife.bld.extension;
|
||||
|
||||
import org.assertj.core.api.AutoCloseableSoftAssertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.BaseProject;
|
||||
|
@ -110,27 +111,27 @@ class CompileKotlinOperationTest {
|
|||
|
||||
.plugins(List.of("plugin3", "plugin4"));
|
||||
|
||||
assertThat(op.kotlinHome().getName()).as("kotlin_home").isEqualTo("kotlin_home");
|
||||
assertThat(op.kotlinc().getName()).as("kotlinc").isEqualTo("kotlinc");
|
||||
assertThat(op.workDir().getName()).as("work_dir").isEqualTo("work_dir");
|
||||
|
||||
assertThat(op.compileMainClasspath()).as("compileMainClassPath")
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
softly.assertThat(op.kotlinHome().getName()).as("kotlin_home").isEqualTo("kotlin_home");
|
||||
softly.assertThat(op.kotlinc().getName()).as("kotlinc").isEqualTo("kotlinc");
|
||||
softly.assertThat(op.workDir().getName()).as("work_dir").isEqualTo("work_dir");
|
||||
softly.assertThat(op.compileMainClasspath()).as("compileMainClassPath")
|
||||
.containsAll(List.of("path1", "path2"));
|
||||
assertThat(op.compileOptions().hasRelease()).as("hasRelease").isTrue();
|
||||
assertThat(op.compileOptions().isVerbose()).as("isVerbose").isTrue();
|
||||
assertThat(op.mainSourceDirectories()).as("mainSourceDirectories").containsExactly(
|
||||
Path.of("src", "main", "kotlin").toFile().getAbsoluteFile(), new File("dir1"),
|
||||
softly.assertThat(op.compileOptions().hasRelease()).as("hasRelease").isTrue();
|
||||
softly.assertThat(op.compileOptions().isVerbose()).as("isVerbose").isTrue();
|
||||
softly.assertThat(op.mainSourceDirectories()).as("mainSourceDirectories").containsExactly(
|
||||
Path.of("examples", "src", "main", "kotlin").toFile(), new File("dir1"),
|
||||
new File("dir2"), new File("dir3"), new File("dir4"));
|
||||
assertThat(op.testSourceDirectories()).as("testSourceDirectories").containsOnly(
|
||||
Path.of("src", "test", "kotlin").toFile().getAbsoluteFile(), new File("tdir1"),
|
||||
softly.assertThat(op.testSourceDirectories()).as("testSourceDirectories").containsOnly(
|
||||
Path.of("examples", "src", "test", "kotlin").toFile(), new File("tdir1"),
|
||||
new File("tdir2"), new File("tdir3"), new File("tdir4"));
|
||||
assertThat(op.mainSourceFiles()).as("mainSourceFiles").containsOnly(
|
||||
softly.assertThat(op.mainSourceFiles()).as("mainSourceFiles").containsOnly(
|
||||
new File("file1"), new File("file2"), new File("file3"),
|
||||
new File("file4"), new File("file5"), new File("file6"));
|
||||
assertThat(op.testSourceFiles()).as("testSourceFiles").containsOnly(
|
||||
softly.assertThat(op.testSourceFiles()).as("testSourceFiles").containsOnly(
|
||||
new File("tfile1"), new File("tfile2"), new File("tfile3"),
|
||||
new File("tfile4"), new File("tfile5"), new File("tfile6"));
|
||||
assertThat(op.plugins()).as("plugins").contains("plugin1", "plugin2", "plugin3", "plugin4",
|
||||
softly.assertThat(op.plugins()).as("plugins").contains("plugin1", "plugin2", "plugin3", "plugin4",
|
||||
"/kotlin_home/lib/kotlin-serialization-compiler-plugin.jar",
|
||||
"/kotlin_home/lib/assignment-compiler-plugin.jar",
|
||||
new File("lib/compile", "lombok-compiler-plugin.jar").getAbsolutePath(),
|
||||
|
@ -140,6 +141,7 @@ class CompileKotlinOperationTest {
|
|||
new File("lib/compile", "kotlinx-serialization-compiler-plugin.jar").getAbsolutePath(),
|
||||
new File("lib/compile", "sam-with-receiver-compiler-plugin.jar").getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute() throws Exception {
|
||||
|
@ -150,8 +152,10 @@ class CompileKotlinOperationTest {
|
|||
var mainDir = new File(buildDir, "main");
|
||||
var testDir = new File(buildDir, "test");
|
||||
|
||||
assertThat(mainDir.mkdirs()).as("make mainDir").isTrue();
|
||||
assertThat(testDir.mkdirs()).as("make testDir").isTrue();
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
softly.assertThat(mainDir.mkdirs()).as("make mainDir").isTrue();
|
||||
softly.assertThat(testDir.mkdirs()).as("make testDir").isTrue();
|
||||
}
|
||||
|
||||
var compileJars = new ArrayList<String>();
|
||||
for (var f : Objects.requireNonNull(new File("examples/lib/compile").listFiles())) {
|
||||
|
@ -182,13 +186,18 @@ class CompileKotlinOperationTest {
|
|||
|
||||
op.execute();
|
||||
|
||||
assertThat(tmpDir).as("tmpDir").isNotEmptyDirectory();
|
||||
assertThat(mainDir).as("mainDir").isNotEmptyDirectory();
|
||||
assertThat(testDir).as("testDir").isNotEmptyDirectory();
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
softly.assertThat(tmpDir).as("tmpDir").isNotEmptyDirectory();
|
||||
softly.assertThat(mainDir).as("mainDir").isNotEmptyDirectory();
|
||||
softly.assertThat(testDir).as("testDir").isNotEmptyDirectory();
|
||||
}
|
||||
|
||||
var mainOut = Path.of(mainDir.getAbsolutePath(), "com", "example").toFile();
|
||||
assertThat(new File(mainOut, "Example.class")).as("Example.class").exists();
|
||||
assertThat(new File(mainOut, "Example$Companion.class")).as("ExampleCompanion.class").exists();
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
softly.assertThat(new File(mainOut, "Example.class")).as("Example.class").exists();
|
||||
softly.assertThat(new File(mainOut, "Example$Companion.class"))
|
||||
.as("ExampleCompanion.class").exists();
|
||||
}
|
||||
|
||||
var testOut = Path.of(testDir.getAbsolutePath(), "com", "example").toFile();
|
||||
assertThat(new File(testOut, "ExampleTest.class")).as("ExampleTest.class").exists();
|
||||
|
@ -303,8 +312,10 @@ class CompileKotlinOperationTest {
|
|||
CompilerPlugin.POWER_ASSERT,
|
||||
CompilerPlugin.SAM_WITH_RECEIVER);
|
||||
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
for (var p : op.plugins()) {
|
||||
assertThat(new File(p)).as(p).exists();
|
||||
softly.assertThat(new File(p)).as(p).exists();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package rife.bld.extension.kotlin;
|
||||
|
||||
import org.assertj.core.api.AutoCloseableSoftAssertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -102,11 +103,13 @@ class CompileOptionsTest {
|
|||
args.add(options.args());
|
||||
args.add(options.apiVersion(11).jvmTarget(11).args());
|
||||
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
for (var a : args) {
|
||||
IntStream.range(0, a.size()).forEach(i -> assertThat(a.get(i))
|
||||
IntStream.range(0, a.size()).forEach(i -> softly.assertThat(a.get(i))
|
||||
.as(a.get(i) + " == " + matches.get(i)).isEqualTo(matches.get(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArgsCollections() {
|
||||
|
@ -134,22 +137,24 @@ class CompileOptionsTest {
|
|||
op.plugin(p[0], p[1], p[2]);
|
||||
});
|
||||
|
||||
assertThat(op.advancedOptions()).as("advancedOptions")
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
softly.assertThat(op.advancedOptions()).as("advancedOptions")
|
||||
.hasSize(advanceOptions.size()).containsAll(advanceOptions);
|
||||
assertThat(op.argFile()).as("argFile")
|
||||
softly.assertThat(op.argFile()).as("argFile")
|
||||
.hasSize(argFile.size()).containsAll(argFile);
|
||||
assertThat(op.classpath()).as("classpath")
|
||||
softly.assertThat(op.classpath()).as("classpath")
|
||||
.hasSize(classpath.size()).containsAll(classpath);
|
||||
assertThat(op.jvmOptions()).as("jvmOptions")
|
||||
softly.assertThat(op.jvmOptions()).as("jvmOptions")
|
||||
.hasSize(jvmOptions.size()).containsAll(jvmOptions);
|
||||
assertThat(op.optIn()).as("optIn")
|
||||
softly.assertThat(op.optIn()).as("optIn")
|
||||
.hasSize(optIn.size()).containsAll(optIn);
|
||||
assertThat(op.options()).as("options")
|
||||
softly.assertThat(op.options()).as("options")
|
||||
.hasSize(options.size()).containsAll(options);
|
||||
assertThat(op.plugin()).as("plugin")
|
||||
softly.assertThat(op.plugin()).as("plugin")
|
||||
.hasSize(plugin.size()).containsAll(plugin);
|
||||
assertThat(op.scriptTemplates()).as("scriptTemplates")
|
||||
softly.assertThat(op.scriptTemplates()).as("scriptTemplates")
|
||||
.hasSize(scriptTemplates.size()).containsAll(scriptTemplates);
|
||||
}
|
||||
|
||||
var matches = List.of(
|
||||
'@' + localPath("arg1.txt"), '@' + localPath("arg2.txt"),
|
||||
|
@ -164,6 +169,7 @@ class CompileOptionsTest {
|
|||
"-P", "plugin:id:name:value",
|
||||
"-P", "plugin:id2:name2:value2");
|
||||
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
var args = op.args();
|
||||
for (var arg : args) {
|
||||
var found = false;
|
||||
|
@ -173,7 +179,8 @@ class CompileOptionsTest {
|
|||
break;
|
||||
}
|
||||
}
|
||||
assertThat(found).as(arg + " not found.").isTrue();
|
||||
softly.assertThat(found).as(arg + " not found.").isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,6 +236,7 @@ class CompileOptionsTest {
|
|||
.verbose(true)
|
||||
.wError(true);
|
||||
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
for (var p : args) {
|
||||
var found = false;
|
||||
for (var a : params.args()) {
|
||||
|
@ -237,7 +245,8 @@ class CompileOptionsTest {
|
|||
break;
|
||||
}
|
||||
}
|
||||
assertThat(found).as(p + " not found.").isTrue();
|
||||
softly.assertThat(found).as(p + " not found.").isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,30 +342,32 @@ class CompileOptionsTest {
|
|||
.verbose(true)
|
||||
.wError(true);
|
||||
|
||||
assertThat(options.advancedOptions()).containsExactly("xopt1", "xopt2");
|
||||
assertThat(options.apiVersion()).isEqualTo("11");
|
||||
assertThat(options.argFile()).containsExactly(new File("args.txt"));
|
||||
assertThat(options.classpath()).containsExactly(new File("classpath"));
|
||||
assertThat(options.expression()).isEqualTo("expression");
|
||||
assertThat(options.isIncludeRuntime()).isTrue();
|
||||
assertThat(options.isJavaParameters()).isTrue();
|
||||
assertThat(options.isNoJdk()).isTrue();
|
||||
assertThat(options.isNoReflect()).isTrue();
|
||||
assertThat(options.isNoStdLib()).isTrue();
|
||||
assertThat(options.isNoWarn()).isTrue();
|
||||
assertThat(options.isProgressive()).isTrue();
|
||||
assertThat(options.isVerbose()).isTrue();
|
||||
assertThat(options.jdkHome()).isEqualTo(new File("jdk-home"));
|
||||
assertThat(options.jdkRelease()).isEqualTo("22");
|
||||
assertThat(options.jvmTarget()).isEqualTo("9");
|
||||
assertThat(options.kotlinHome()).isEqualTo(new File("kotlin-home"));
|
||||
assertThat(options.languageVersion()).isEqualTo("1.0");
|
||||
assertThat(options.moduleName()).isEqualTo("module");
|
||||
assertThat(options.optIn()).containsExactly("opt1", "opt2");
|
||||
assertThat(options.options()).containsExactly("-foo", "-bar");
|
||||
assertThat(options.path()).isEqualTo(new File("path"));
|
||||
assertThat(options.plugin()).containsExactly("id:name:value");
|
||||
assertThat(options.scriptTemplates()).containsExactly("name", "name2");
|
||||
assertThat(options.isWError()).isTrue();
|
||||
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||
softly.assertThat(options.advancedOptions()).containsExactly("xopt1", "xopt2");
|
||||
softly.assertThat(options.apiVersion()).isEqualTo("11");
|
||||
softly.assertThat(options.argFile()).containsExactly(new File("args.txt"));
|
||||
softly.assertThat(options.classpath()).containsExactly(new File("classpath"));
|
||||
softly.assertThat(options.expression()).isEqualTo("expression");
|
||||
softly.assertThat(options.isIncludeRuntime()).isTrue();
|
||||
softly.assertThat(options.isJavaParameters()).isTrue();
|
||||
softly.assertThat(options.isNoJdk()).isTrue();
|
||||
softly.assertThat(options.isNoReflect()).isTrue();
|
||||
softly.assertThat(options.isNoStdLib()).isTrue();
|
||||
softly.assertThat(options.isNoWarn()).isTrue();
|
||||
softly.assertThat(options.isProgressive()).isTrue();
|
||||
softly.assertThat(options.isVerbose()).isTrue();
|
||||
softly.assertThat(options.jdkHome()).isEqualTo(new File("jdk-home"));
|
||||
softly.assertThat(options.jdkRelease()).isEqualTo("22");
|
||||
softly.assertThat(options.jvmTarget()).isEqualTo("9");
|
||||
softly.assertThat(options.kotlinHome()).isEqualTo(new File("kotlin-home"));
|
||||
softly.assertThat(options.languageVersion()).isEqualTo("1.0");
|
||||
softly.assertThat(options.moduleName()).isEqualTo("module");
|
||||
softly.assertThat(options.optIn()).containsExactly("opt1", "opt2");
|
||||
softly.assertThat(options.options()).containsExactly("-foo", "-bar");
|
||||
softly.assertThat(options.path()).isEqualTo(new File("path"));
|
||||
softly.assertThat(options.plugin()).containsExactly("id:name:value");
|
||||
softly.assertThat(options.scriptTemplates()).containsExactly("name", "name2");
|
||||
softly.assertThat(options.isWError()).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue