-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create mini framework for tests & add tests for glob
- Loading branch information
1 parent
31ec879
commit 7312493
Showing
9 changed files
with
120 additions
and
47 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
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,60 @@ | ||
package teksturepako.pakku | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import teksturepako.pakku.api.data.generatePakkuId | ||
import teksturepako.pakku.api.data.workingPath | ||
import kotlin.io.path.* | ||
import kotlin.test.AfterTest | ||
import kotlin.test.BeforeTest | ||
|
||
open class PakkuTest | ||
{ | ||
private var testName: String = "" | ||
|
||
protected open suspend fun `on-set-up`() | ||
{ | ||
} | ||
|
||
protected open val teardown = true | ||
|
||
protected fun createTestFile(vararg path: String) | ||
{ | ||
val file = Path(workingPath, *path) | ||
runCatching { file.createParentDirectories() } | ||
runCatching { file.createFile() } | ||
} | ||
|
||
protected fun createTestDir(vararg path: String) | ||
{ | ||
val dir = Path(workingPath, *path) | ||
runCatching { dir.createParentDirectories() } | ||
runCatching { dir.createDirectory() } | ||
} | ||
|
||
@BeforeTest | ||
fun `set-up-test`() | ||
{ | ||
testName = this::class.simpleName ?: generatePakkuId() | ||
|
||
println("Setting up test: $testName") | ||
|
||
workingPath = "./build/test/$testName" | ||
runCatching { Path("./build/test/$testName").createParentDirectories() } | ||
runCatching { Path("./build/test/$testName").createDirectory() } | ||
|
||
runBlocking { this@PakkuTest.`on-set-up`() } | ||
} | ||
|
||
@AfterTest | ||
@OptIn(ExperimentalPathApi::class) | ||
fun `tear-down-test`() | ||
{ | ||
if (!teardown) return | ||
|
||
workingPath = "." | ||
|
||
println("Tearing down test: $testName") | ||
|
||
runCatching { Path("./build/test/$testName").deleteRecursively() } | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
src/commonTest/kotlin/teksturepako/pakku/api/actions/export/TestExport.kt
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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,40 @@ | ||
package teksturepako.pakku.io | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import teksturepako.pakku.PakkuTest | ||
import teksturepako.pakku.api.data.workingPath | ||
import kotlin.io.path.Path | ||
import kotlin.test.Test | ||
import kotlin.test.assertContains | ||
|
||
class GlobTest : PakkuTest() | ||
{ | ||
private val testFileName = "test_file.txt" | ||
private val testDirName = "test_dir" | ||
|
||
override suspend fun `on-set-up`() | ||
{ | ||
createTestFile(testFileName) | ||
createTestDir(testDirName) | ||
createTestFile(testDirName, testFileName) | ||
} | ||
|
||
@Test | ||
fun `test with basic file name`() = runBlocking { | ||
val expandedGlob = listOf(testFileName).expandWithGlob(Path(workingPath)) | ||
assertContains(expandedGlob, testFileName) | ||
} | ||
|
||
@Test | ||
fun `test with negating pattern`() = runBlocking { | ||
val expandedGlob = listOf("!$testFileName").expandWithGlob(Path(workingPath)) | ||
assert(testFileName !in expandedGlob) | ||
} | ||
|
||
@Test | ||
fun `test with dir pattern`() = runBlocking { | ||
val expandedGlob = listOf("$testDirName/**").expandWithGlob(Path(workingPath)) | ||
assert(testDirName !in expandedGlob) { "$expandedGlob should not contain $testDirName" } | ||
assertContains(expandedGlob, "$testDirName/$testFileName") | ||
} | ||
} |