Cleaned up tests

This commit is contained in:
Erik C. Thauvin 2024-06-23 21:41:13 -07:00
parent 6b6057f52e
commit c8878968ef
Signed by: erik
GPG key ID: 776702A6A2DA330E
4 changed files with 96 additions and 62 deletions

View file

@ -48,14 +48,14 @@ public class ExampleBuild extends Project {
public static void main(String[] args) {
// Enable detailed logging for the Kotlin extension
// var level = Level.ALL;
// var logger = Logger.getLogger("rife.bld.extension");
// var consoleHandler = new ConsoleHandler();
//
// consoleHandler.setLevel(level);
// logger.addHandler(consoleHandler);
// logger.setLevel(level);
// logger.setUseParentHandlers(false);
var level = Level.ALL;
var logger = Logger.getLogger("rife.bld.extension");
var consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(level);
logger.addHandler(consoleHandler);
logger.setLevel(level);
logger.setUseParentHandlers(false);
new ExampleBuild().start(args);
}

View file

@ -34,8 +34,20 @@ import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat;
class DokkaOperationTest {
private static final String FILE_1 = "file1";
private static final String FILE_2 = "file2";
private static final String FILE_3 = "file3";
private static final String FILE_4 = "file4";
private static final String OPTION_1 = "option1";
private static final String OPTION_2 = "option2";
private static final String OPTION_3 = "option3";
private static final String OPTION_4 = "option4";
private static final String PATH_1 = "path1";
private static final String PATH_2 = "path2";
private static final String PATH_3 = "path3";
private static final String PATH_4 = "path4";
@Test
@SuppressWarnings({"PMD.AvoidDuplicateLiterals"})
void executeConstructProcessCommandListTest() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-args.txt"));
@ -47,15 +59,15 @@ class DokkaOperationTest {
.delayTemplateSubstitution(true)
.failOnWarning(true)
.fromProject(new BaseProjectBlueprint(examples, "com.example", "Example"))
.globalLinks("s", "link")
.globalLinks(Map.of("s2", "link2"))
.globalPackageOptions("option1", "option2")
.globalPackageOptions(List.of("option3", "option4"))
.globalLinks("s", "gLink1")
.globalLinks(Map.of("s2", "gLink2"))
.globalPackageOptions(OPTION_1, OPTION_2)
.globalPackageOptions(List.of(OPTION_3, OPTION_4))
.globalSrcLink("link1", "link2")
.globalSrcLink(List.of("link3", "link4"))
.includes(new File("file1"))
.includes("file2")
.includes(List.of(new File("file3"), new File("file4")))
.includes(new File(FILE_1))
.includes(FILE_2)
.includes(List.of(new File(FILE_3), new File(FILE_4)))
.json(jsonConf)
.loggingLevel(LoggingLevel.DEBUG)
.moduleName("name")
@ -66,9 +78,9 @@ class DokkaOperationTest {
.outputFormat(OutputFormat.JAVADOC)
.pluginConfigurations("name", "{\"json\"}")
.pluginConfigurations(Map.of("{\"name2\"}", "json2", "name3}", "{json3"))
.pluginsClasspath(new File("path1"))
.pluginsClasspath("path2")
.pluginsClasspath(List.of(new File("path3"), new File("path4")))
.pluginsClasspath(new File(PATH_1))
.pluginsClasspath(PATH_2)
.pluginsClasspath(List.of(new File(PATH_3), new File(PATH_4)))
.sourceSet(new SourceSet().classpath(
List.of(
new File("examples/foo.jar"),
@ -104,16 +116,16 @@ class DokkaOperationTest {
path + "/lib/bld/javadoc-plugin-" + dokkaJar + ';' +
path + "/lib/bld/korte-jvm-4.0.10.jar;" +
path + "/lib/bld/kotlin-as-java-plugin-" + dokkaJar + ';' +
TestUtil.localPath("path1", "path2", "path3", "path4"),
TestUtils.localPath(PATH_1, PATH_2, PATH_3, PATH_4),
"-sourceSet", "-src " + path + "/src/main/kotlin" + " -classpath " + path + "/foo.jar;"
+ path + "/bar.jar",
"-outputDir", path + "/build",
"-delayTemplateSubstitution",
"-failOnWarning",
"-globalLinks", "s^link^^s2^link2",
"-globalPackageOptions", "option1;option2;option3;option4",
"-globalLinks", "s^gLink1^^s2^gLink2",
"-globalPackageOptions", OPTION_1 + ';' + OPTION_2 + ';' + OPTION_3 + ';' + OPTION_4,
"-globalSrcLinks_", "link1;link2;link3;link4",
"-includes", TestUtil.localPath("file1", "file2", "file3", "file4"),
"-includes", TestUtils.localPath(FILE_1, FILE_2, FILE_3, FILE_4),
"-loggingLevel", "debug",
"-moduleName", "name",
"-moduleVersion", "1.0",

View file

@ -23,8 +23,8 @@ import java.util.stream.Collectors;
import static rife.bld.extension.DokkaOperation.SEMICOLON;
@SuppressWarnings("PMD.TestClassWithoutTestCases")
public final class TestUtil {
private TestUtil() {
public final class TestUtils {
private TestUtils() {
// no-op
}
@ -35,6 +35,6 @@ public final class TestUtil {
* @return the local path
*/
public static String localPath(String... fileNames) {
return Arrays.stream(fileNames).map(it -> new File(it).getAbsolutePath()).collect(Collectors.joining(SEMICOLON));
return Arrays.stream(fileNames).map(f -> new File(f).getAbsolutePath()).collect(Collectors.joining(SEMICOLON));
}
}

View file

@ -27,36 +27,52 @@ import java.util.Map;
import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat;
import static rife.bld.extension.TestUtil.localPath;
import static rife.bld.extension.TestUtils.localPath;
class SourceSetTest {
public static final String SAMPLES_1 = "samples1";
public static final String SAMPLES_2 = "samples2";
public static final String SUP_1 = "sup1";
public static final String SUP_2 = "sup2";
private static final String CLASSPATH_1 = "classpath1";
private static final String CLASSPATH_2 = "classpath2";
private static final String INCLUDES_1 = "includes1";
private static final String INCLUDES_2 = "includes2";
private static final String INCLUDES_3 = "includes3";
private static final String INCLUDES_4 = "includes4";
private static final String OPTION_1 = "option1";
private static final String OPTION_2 = "option2";
private static final String PATH_1 = "path1";
private static final String PATH_2 = "path2";
private static final String SAMPLES_1 = "samples1";
private static final String SAMPLES_2 = "samples2";
private static final String SAMPLES_3 = "samples3";
private static final String SRC_1 = "src1";
private static final String SRC_2 = "src2";
private static final String SRC_3 = "src3";
private static final String SRC_4 = "src4";
private static final String SUP_1 = "sup1";
private static final String SUP_2 = "sup2";
private static final String SUP_3 = "sup3";
@Test
void sourceSetCollectionsTest() {
var args = new SourceSet()
.classpath(List.of(new File("path1"), new File("path2")))
.classpath(List.of(new File(PATH_1), new File(PATH_2)))
.dependentSourceSets(Map.of("set1", "set2", "set3", "set4"))
.externalDocumentationLinks(Map.of("link1", "link2", "link3", "link4"))
.perPackageOptions(List.of("option1", "option2"))
.perPackageOptions(List.of(OPTION_1, OPTION_2))
.samples(List.of(new File(SAMPLES_1)))
.samples(new File(SAMPLES_2))
.samples("samples3")
.samples(SAMPLES_3)
.suppressedFiles(List.of(new File(SUP_1)))
.suppressedFiles(new File(SUP_2))
.suppressedFiles("sup3")
.suppressedFiles(SUP_3)
.args();
var matches = List.of(
"-classpath", localPath("path1", "path2"),
"-classpath", localPath(PATH_1, PATH_2),
"-dependentSourceSets", "set1/set2;set3/set4",
"-externalDocumentationLinks", "link3^link4^^link1^link2",
"-perPackageOptions", "option1;option2",
"-samples", localPath(SAMPLES_1, SAMPLES_2, "samples3"),
"-suppressedFiles", localPath(SUP_1, SUP_2, "sup3")
"-perPackageOptions", OPTION_1 + ';' + OPTION_2,
"-samples", localPath(SAMPLES_1, SAMPLES_2, SAMPLES_3),
"-suppressedFiles", localPath(SUP_1, SUP_2, SUP_3)
);
assertThat(args).hasSize(matches.size());
@ -65,7 +81,12 @@ class SourceSetTest {
}
@Test
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
void sourceSetIntVersionsTest() {
var args = new SourceSet().apiVersion(1).languageVersion(2);
assertThat(args.args()).containsExactly("-apiVersion", "1", "-languageVersion", "2");
}
@Test
void sourceSetTest() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "dokka-sourceset-args.txt"));
@ -74,32 +95,32 @@ class SourceSetTest {
var sourceSet = new SourceSet()
.analysisPlatform(AnalysisPlatform.JVM)
.apiVersion("1.0")
.classpath("classpath1")
.classpath(new File("classpath2"))
.classpath(CLASSPATH_1)
.classpath(new File(CLASSPATH_2))
.dependentSourceSets("moduleName", "sourceSetName")
.dependentSourceSets("moduleName2", "sourceSetName2")
.displayName("name")
.documentedVisibilities(DocumentedVisibility.PACKAGE, DocumentedVisibility.PRIVATE)
.externalDocumentationLinks("url1", "packageListUrl1")
.externalDocumentationLinks("url2", "packageListUrl2")
.includes("includes1", "includes2")
.includes(new File("includes3"))
.includes(List.of(new File("includes4")))
.includes(INCLUDES_1, INCLUDES_2)
.includes(new File(INCLUDES_3))
.includes(List.of(new File(INCLUDES_4)))
.jdkVersion(18)
.languageVersion("2.0")
.noJdkLink(true)
.noSkipEmptyPackages(true)
.noStdlibLink(true)
.perPackageOptions("options1", "options2")
.perPackageOptions(OPTION_1, OPTION_2)
.reportUndocumented(true)
.samples(SAMPLES_1, SAMPLES_2)
.skipDeprecated(true)
.sourceSetName("setName")
.src("src1", "src2")
.src(new File("src3"))
.src(List.of(new File("src4")))
.srcLink("path1", "remote1", "#suffix1")
.srcLink(new File("path2"), "remote2", "#suffix2")
.src(SRC_1, SRC_2)
.src(new File(SRC_3))
.src(List.of(new File(SRC_4)))
.srcLink(PATH_1, "remote1", "#suffix1")
.srcLink(new File(PATH_2), "remote2", "#suffix2")
.suppressedFiles(SUP_1, SUP_2);
assertThat(sourceSet.classpath()).as("classpath").hasSize(2);
@ -129,31 +150,32 @@ class SourceSetTest {
var matches = List.of(
"-analysisPlatform", "jvm",
"-apiVersion", "1.0",
"-classpath", localPath("classpath1", "classpath2"),
"-classpath", localPath(CLASSPATH_1, CLASSPATH_2),
"-dependentSourceSets", "moduleName/sourceSetName;moduleName2/sourceSetName2",
"-displayName", "name",
"-documentedVisibilities", "package;private",
"-externalDocumentationLinks", "url1^packageListUrl1^^url2^packageListUrl2",
"-jdkVersion", "18",
"-includes", localPath("includes1", "includes2", "includes3", "includes4"),
"-includes", localPath(INCLUDES_1, INCLUDES_2, INCLUDES_3, INCLUDES_4),
"-languageVersion", "2.0",
"-noJdkLink", "true",
"-noSkipEmptyPackages", "true",
"-noStdlibLink", "true",
"-reportUndocumented", "true",
"-perPackageOptions", "options1;options2",
"-noJdkLink",
"-noSkipEmptyPackages",
"-noStdlibLink",
"-reportUndocumented",
"-perPackageOptions", OPTION_1 + ';' + OPTION_2,
"-samples", localPath(SAMPLES_1, SAMPLES_2),
"-skipDeprecated", "true",
"-src", localPath("src1", "src2", "src3", "src4"),
"-srcLink", localPath("path2") + "=remote2#suffix2;path1=remote1#suffix1",
"-skipDeprecated",
"-src", localPath(SRC_1, SRC_2, SRC_3, SRC_4),
"-srcLink", localPath(PATH_2) + "=remote2#suffix2;path1=remote1#suffix1",
"-sourceSetName", "setName",
"-suppressedFiles", localPath(SUP_1, SUP_2));
assertThat(params).hasSize(matches.size());
IntStream.range(0, params.size()).forEach(i -> assertThat(params.get(i)).isEqualTo(matches.get(i)));
sourceSet.classpath(List.of(new File("classpath1"), new File("classpath2")));
sourceSet.classpath(List.of(new File(CLASSPATH_1), new File(CLASSPATH_2)));
IntStream.range(0, params.size()).forEach(i -> assertThat(params.get(i)).isEqualTo(matches.get(i)));
}