From aa5a73f31ec4dca45f33c359ba657274e4c3965f Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Sat, 27 Jan 2024 08:33:13 +0100 Subject: [PATCH] WIP Add integration test for CLI --- build.gradle | 82 ++++++++++++++++++++++++++++++----- integration-test/cli/.gitkeep | 0 2 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 integration-test/cli/.gitkeep diff --git a/build.gradle b/build.gradle index db9d6ae2..40656c30 100644 --- a/build.gradle +++ b/build.gradle @@ -48,9 +48,9 @@ configure(subprojects) { implementation platform(libs.groovy.bom) implementation 'org.codehaus.groovy:groovy' - implementation platform (libs.slf4j.bom) + implementation platform(libs.slf4j.bom) - testImplementation platform (libs.spock) + testImplementation platform(libs.spock) testImplementation "org.spockframework:spock-core" testImplementation "org.spockframework:spock-junit4" @@ -68,7 +68,7 @@ configure(subprojects) { maven { name = 'myLocalRepositoryForFullIntegrationTests' //noinspection GrDeprecatedAPIUsage - url = new File (project.parent.buildDir, "maven-repo") + url = new File(project.parent.buildDir, "maven-repo") } mavenLocal() } @@ -83,26 +83,88 @@ configure(subprojects) { // apply plugin: 'codenarc' } -tasks.register("integrationTest") { - group("Verification") - description("Run overall integration tests") +final String INTEGRATION_TEST_DIRECTORY = "integration-test" +final String INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN = "${INTEGRATION_TEST_DIRECTORY}/gradle-plugin" +final String INTEGRATION_TEST_DIRECTORY_CLI = "${INTEGRATION_TEST_DIRECTORY}/cli" +static void cleanBuild(String baseDirectory) { + File integrationTestBuildDir = new File("${baseDirectory}/${Project.DEFAULT_BUILD_DIR_NAME}") + if (integrationTestBuildDir.exists()) { + integrationTestBuildDir.eachFileRecurse { file -> + file.delete() + } + integrationTestBuildDir.deleteDir() + } + assert !integrationTestBuildDir.exists() +} - final String INTEGRATION_TEST_DIRECTORY = "integration-test/gradle-plugin" +tasks.register("integrationTestGradlePlugin") { + group("Verification") + description("Run gradle-plugin integration tests") doLast { def result = exec { - workingDir INTEGRATION_TEST_DIRECTORY + workingDir INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN commandLine "./gradlew", "clean", "htmlSanityCheck", "-PhtmlSanityCheckVersion=${project.version}" } logger.debug "Script output: $result" - final File testIndex = new File(INTEGRATION_TEST_DIRECTORY, "build/reports/index.html") + final File testIndex = new File(INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN, "${Project.DEFAULT_BUILD_DIR_NAME}/reports/index.html") assert testIndex.exists() } } -integrationTest.dependsOn( +integrationTestGradlePlugin.dependsOn( ':htmlSanityCheck-core:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository', ':htmlSanityCheck-gradle-plugin:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository' ) +tasks.register("cleanIntegrationTestGradlePlugin", Delete) { + group("Build") + description("Deletes the result directory from gradle-plugin integration tests") + + doLast { + cleanBuild INTEGRATION_TEST_DIRECTORY_GRADLE_PLUGIN + } +} +clean.dependsOn cleanIntegrationTestGradlePlugin + +tasks.register("integrationTestCli") { + group("Verification") + description("Run CLI integration tests") + + final String BUILD_REPORTS_DIRECTORY = "${Project.DEFAULT_BUILD_DIR_NAME}/reports" + + doLast { + def result = exec { + workingDir INTEGRATION_TEST_DIRECTORY_CLI + new File(BUILD_REPORTS_DIRECTORY).mkdirs() + commandLine "../../htmlSanityCheck-cli/${Project.DEFAULT_BUILD_DIR_NAME}/install/hsc/bin/hsc", "-r", BUILD_REPORTS_DIRECTORY, "../common/src/test/resources" + } + logger.debug "Script output: ${result}" + final File testIndex = new File(INTEGRATION_TEST_DIRECTORY_CLI, "${BUILD_REPORTS_DIRECTORY}/index.html") + assert testIndex.exists() + } +} +integrationTestCli.dependsOn( + ':htmlSanityCheck-cli:installDist' +) +tasks.register("cleanIntegrationTestCli", Delete) { + group("Build") + description("Deletes the result directory from CLI integration tests") + + doLast { + cleanBuild INTEGRATION_TEST_DIRECTORY_CLI + } +} +//noinspection GroovyAssignabilityCheck +clean.dependsOn cleanIntegrationTestCli +integrationTestCli.dependsOn cleanIntegrationTestCli + +tasks.register("integrationTest") { + group("Verification") + description("Run overall integration tests") +} +integrationTest.dependsOn( + 'integrationTestGradlePlugin', + 'integrationTestCli' +) /* * Copyright Gernot Starke and aim42 contributors. diff --git a/integration-test/cli/.gitkeep b/integration-test/cli/.gitkeep new file mode 100644 index 00000000..e69de29b