forked from terrakok/kmp-web-wizard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test with check of generated project.
- Loading branch information
Showing
5 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/build | ||
local.properties | ||
.gradle | ||
.idea | ||
.idea | ||
**yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.jetbrains.webwiz | ||
|
||
import org.apache.commons.compress.archivers.zip.UnixStat | ||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry | ||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream | ||
import org.jetbrains.webwiz.generator.files.GradleBat | ||
import org.jetbrains.webwiz.generator.files.GradleWrapperJar | ||
import org.jetbrains.webwiz.generator.files.Gradlew | ||
import org.jetbrains.webwiz.generator.generate | ||
import org.jetbrains.webwiz.models.ProjectInfo | ||
import java.io.File | ||
|
||
fun ProjectInfo.asDir(workingDir: File): File { | ||
val dir = workingDir.resolve(projectName) | ||
dir.deleteRecursively() | ||
dir.mkdirs() | ||
|
||
generate().forEach { projectFile -> | ||
val f = dir.resolve(projectFile.path) | ||
f.parentFile.mkdirs() | ||
f.createNewFile() | ||
|
||
if (projectFile is GradleWrapperJar) { | ||
f.outputStream().use { out -> | ||
javaClass.getResourceAsStream("/binaries/gradle-wrapper").use { it.copyTo(out) } | ||
} | ||
} else { | ||
if (projectFile is Gradlew) f.setExecutable(true) | ||
if (projectFile is GradleBat) f.setExecutable(true) | ||
|
||
f.writeText(projectFile.content) | ||
} | ||
} | ||
return dir | ||
} | ||
|
||
fun ProjectInfo.asZip(workingDir: File) = | ||
asDir(workingDir).zip().also { it.deleteRecursively() } | ||
|
||
fun File.zip(): File { | ||
val dir = this | ||
val resultZip = dir.parentFile.resolve("${dir.name}.zip") | ||
ZipArchiveOutputStream(resultZip).use { output -> | ||
dir.walk().forEach { file -> | ||
val entry = ZipArchiveEntry(file.relativeTo(dir).path) | ||
|
||
//Set unix mode to preserve execution rights for gradlew script | ||
if (file.isDirectory) { | ||
entry.unixMode = UnixStat.DIR_FLAG or UnixStat.DEFAULT_DIR_PERM | ||
} else { | ||
entry.unixMode = UnixStat.FILE_FLAG or | ||
if (file.name == "gradlew") UnixStat.DEFAULT_DIR_PERM else UnixStat.DEFAULT_FILE_PERM | ||
} | ||
|
||
output.putArchiveEntry(entry) | ||
if (!file.isDirectory) { | ||
file.inputStream().use { it.copyTo(output) } | ||
} | ||
output.closeArchiveEntry() | ||
} | ||
} | ||
|
||
return resultZip | ||
} |
68 changes: 68 additions & 0 deletions
68
src/jvmTest/kotlin/org/jetbrains/webwiz/GeneratedProjectTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.jetbrains.webwiz | ||
|
||
import org.jetbrains.webwiz.models.GradlePlugin | ||
import org.jetbrains.webwiz.models.KmpLibrary | ||
import org.jetbrains.webwiz.models.KotlinVersion | ||
import org.jetbrains.webwiz.models.ProjectInfo | ||
import org.jetbrains.webwiz.models.Target | ||
import org.junit.AfterClass | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
import java.io.File | ||
import java.lang.ProcessBuilder.* | ||
import kotlin.io.path.createTempDirectory | ||
import kotlin.test.assertEquals | ||
|
||
class GeneratedProjectTest { | ||
|
||
companion object { | ||
private lateinit var workingDir: File | ||
|
||
@BeforeClass | ||
@JvmStatic | ||
fun prepare() { | ||
workingDir = createTempDirectory().toFile() | ||
} | ||
|
||
@AfterClass | ||
@JvmStatic | ||
fun release() { | ||
workingDir.deleteRecursively() | ||
} | ||
} | ||
|
||
@Test | ||
fun testGeneratedProjectJvmLinux() { | ||
checkProject( | ||
ProjectInfo( | ||
"wizard-sample", | ||
"library", | ||
"my.test.lib", | ||
KotlinVersion.Stable, | ||
setOf(Target.JVM, Target.LINUX), | ||
setOf(KmpLibrary.KERMIT_LOGGER, KmpLibrary.COROUTINES, KmpLibrary.DATE_TIME), | ||
emptySet(), | ||
emptySet(), | ||
setOf(GradlePlugin.PUBLISH), | ||
true | ||
) | ||
) | ||
} | ||
|
||
private fun checkProject(projectInfo: ProjectInfo) { | ||
val dir = projectInfo.asDir(workingDir) | ||
|
||
println("Project dir: ${dir.absolutePath}") | ||
println("============start of the build============") | ||
val proc = ProcessBuilder("${dir.path}/gradlew", "check", "--info").apply { | ||
directory(dir) | ||
redirectOutput(Redirect.INHERIT) | ||
redirectError(Redirect.INHERIT) | ||
}.start() | ||
|
||
proc.waitFor() | ||
println("============end of the build============") | ||
assertEquals(0, proc.exitValue(), "'./gradlew check --info' exit code") | ||
|
||
} | ||
} |