diff --git a/build.gradle.kts b/build.gradle.kts index 9b9b93f..13f3fdb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType +import org.jetbrains.intellij.platform.gradle.TestFrameworkType fun properties(key: String) = project.findProperty(key).toString() @@ -65,9 +66,10 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:2.1.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0") testImplementation("io.mockk:mockk:1.13.12") - testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + testImplementation("junit:junit:4.13.2") intellijPlatform { clion(runIdeVersion) + testFramework(TestFrameworkType.Platform) } } diff --git a/src/test/kotlin/io/xmake/TestData.kt b/src/test/kotlin/io/xmake/TestData.kt deleted file mode 100644 index 547c821..0000000 --- a/src/test/kotlin/io/xmake/TestData.kt +++ /dev/null @@ -1,44 +0,0 @@ -package io.xmake - -import java.io.BufferedReader -import java.io.File -import java.io.IOException -import java.io.InputStreamReader - -object TestData { - // get from local xmake - val xmakeVersion: String = testIORunv(listOf("xmake", "--version")) - val xmakeFHelp: String= testIORunv(listOf("xmake", "f", "-h")) - - private fun testIORunv(argv: List, workDir: String? = null): String { - var result = "" - var bufferReader: BufferedReader? = null - try { - val processBuilder = ProcessBuilder(argv) - if (workDir !== null) { - processBuilder.directory(File(workDir)) - } - processBuilder.environment().put("COLORTERM", "nocolor") - val process = processBuilder.start() - bufferReader = BufferedReader(InputStreamReader(process.getInputStream())) - var line: String? = bufferReader.readLine() - while (line != null) { - result += line + "\n" - line = bufferReader.readLine() - } - if (process.waitFor() != 0) - result = "" - } catch (e: IOException) { - e.printStackTrace() - } finally { - if (bufferReader != null) { - try { - bufferReader.close() - } catch (e: Exception) { - e.printStackTrace() - } - } - } - return result - } -} \ No newline at end of file diff --git a/src/test/kotlin/io/xmake/project/toolkit/ToolkitManagerTest.kt b/src/test/kotlin/io/xmake/project/toolkit/ToolkitManagerTest.kt new file mode 100644 index 0000000..ebb82a4 --- /dev/null +++ b/src/test/kotlin/io/xmake/project/toolkit/ToolkitManagerTest.kt @@ -0,0 +1,42 @@ +package io.xmake.project.toolkit + +import junit.framework.TestCase.assertEquals +import junit.framework.TestCase.assertNotNull +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +class ToolkitManagerTest { + + private lateinit var toolkitManager: ToolkitManager + + @Before + fun setUp() { + toolkitManager = ToolkitManager(CoroutineScope(Dispatchers.Default)) + toolkitManager.loadState(ToolkitManager.State()) + } + + @Test + fun `test register and find toolkit`() { + val localToolkit = Toolkit( + name = "Local xmake", + host = ToolkitHost(ToolkitHostType.LOCAL), + path = "/usr/local/bin/xmake", + version = "3.0.2" + ) + + toolkitManager.registerToolkit(localToolkit) + + val registeredToolkits = toolkitManager.getRegisteredToolkits() + assertEquals("Should have one registered toolkit", 1, registeredToolkits.size) + assertEquals("The registered toolkit should be the one we added", localToolkit, registeredToolkits.first()) + + val foundToolkit = toolkitManager.findRegisteredToolkitById(localToolkit.id) + assertNotNull("Should find the toolkit by its ID", foundToolkit) + assertEquals("The found toolkit should be the same as the original", localToolkit, foundToolkit) + } +} \ No newline at end of file diff --git a/src/test/kotlin/io/xmake/utils/interact/InteractTest.kt b/src/test/kotlin/io/xmake/utils/interact/InteractTest.kt deleted file mode 100644 index ff03d04..0000000 --- a/src/test/kotlin/io/xmake/utils/interact/InteractTest.kt +++ /dev/null @@ -1,102 +0,0 @@ -package io.xmake.utils.interact - -import com.intellij.testFramework.fixtures.BasePlatformTestCase -import io.mockk.every -import io.mockk.junit4.MockKRule -import io.mockk.mockkStatic -import io.xmake.TestData -import io.xmake.utils.ioRunv -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 - -@RunWith(JUnit4::class) -class XMakeVersion:BasePlatformTestCase(){ - val xmakeVersion = TestData.xmakeVersion - - @get:Rule - val mockkRule = MockKRule(this) - - @Before - fun before() { - mockkStatic(::ioRunv) - every { ioRunv(any()) } returns xmakeVersion.split("\n") - } - - @Test - fun `Test kXMakeFind`() { - val testCase: Boolean = true - val result: Boolean = kXMakeFind - assertEquals(testCase, result) - } - - @Test - fun `Test kXMakeVersion`() { - val testCase: String = "2.8.6 HEAD.211710b67" - val result: String = kXMakeVersion - assertEquals(testCase, result) - } - -} - -@RunWith(JUnit4::class) -class XMakeFH:BasePlatformTestCase() { - val xmakeFHelp = TestData.xmakeFHelp - - @get:Rule - val mockkRule = MockKRule(this) - - @Before - fun before() { - mockkStatic(::ioRunv) - every { ioRunv(any()) } returns xmakeFHelp.split("\n") - } - - @Test - fun `Test kPlatList`() { - val testCase: List = listOf( - "android", - "appletvos", - "applexros", - "bsd", - "cross", - "cygwin", - "haiku", - "iphoneos", - "linux", - "macosx", - "mingw", - "msys", - "wasm", - "watchos", - "windows", - ) - val result: List = kPlatList - assertEquals(testCase, result) - } - - @Test - fun `Test kPlatArchMap`(){ - val testCase: Map> = mapOf( - "android" to "armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mip64".split(' '), - "appletvos" to "arm64 armv7 armv7s i386 x86_64".split(' '), - "applexros" to "arm64 armv7 armv7s i386 x86_64".split(' '), - "bsd" to "i386 x86_64".split(' '), - "cross" to "i386 x86_64 arm arm64 mips mips64 riscv riscv64 s390x ppc ppc64 sh4".split(' '), - "cygwin" to "i386 x86_64".split(' '), - "haiku" to "i386 x86_64".split(' '), - "iphoneos" to "arm64 x86_64".split(' '), - "linux" to "i386 x86_64 armv7 armv7s arm64-v8a mips mips64 mipsel mips64el loongarch64".split(' '), - "macosx" to "x86_64 arm64".split(' '), - "mingw" to "i386 x86_64 arm arm64".split(' '), - "msys" to "i386 x86_64".split(' '), - "wasm" to "wasm32 wasm64".split(' '), - "watchos" to "armv7k i386".split(' '), - "windows" to "x86 x64 arm64".split(' '), - ) - val result: Map> = kPlatArchMap - assertEquals(testCase, result) - } -} \ No newline at end of file