Browse Source

fix test config and add test set

Seedking 1 năm trước cách đây
mục cha
commit
5a9ad8da5d

+ 6 - 5
build.gradle.kts

@@ -13,7 +13,7 @@ val testIde:String = if(properties("testInClion").toBoolean()) "CL" else "IC"
 plugins {
     id("java")
     id("org.jetbrains.intellij") version "1.17.1"
-    id("org.jetbrains.kotlin.jvm") version "1.9.21"
+    id("org.jetbrains.kotlin.jvm") version "1.9.22"
     id("org.jetbrains.changelog") version "2.2.0"
 }
 
@@ -53,10 +53,12 @@ tasks {
     }
     withType<KotlinCompile> {
         kotlinOptions.jvmTarget = "17"
+        kotlinOptions.languageVersion = "2.0"
     }
 
     test {
-        useJUnitPlatform()
+        useJUnit()
+        include("io/xmake/**/**")
     }
 
     patchPluginXml {
@@ -81,9 +83,8 @@ tasks {
 }
 
 dependencies {
-    implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.21")
-    testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
-    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2")
+    implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.22")
+    testImplementation("io.mockk:mockk:1.13.9")
 }
 
 

+ 103 - 0
src/test/kotlin/io/xmake/utils/interact/InteractTest.kt

@@ -0,0 +1,103 @@
+package io.xmake.utils.interact
+
+import com.intellij.testFramework.fixtures.BasePlatformTestCase
+import io.mockk.every
+import io.mockk.impl.annotations.MockK
+import io.mockk.junit4.MockKRule
+import io.mockk.mockk
+import io.mockk.mockkStatic
+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 = this::class.java.classLoader.getResource("utils/xmake --version.txt").readText()
+
+    @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 = this::class.java.classLoader.getResource("utils/xmake f -h.txt").readText()
+
+    @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<String> = listOf(
+            "android",
+            "appletvos",
+            "applexros",
+            "bsd",
+            "cross",
+            "cygwin",
+            "haiku",
+            "iphoneos",
+            "linux",
+            "macosx",
+            "mingw",
+            "msys",
+            "wasm",
+            "watchos",
+            "windows",
+        )
+        val result: List<String> = kPlatList
+        assertEquals(testCase, result)
+    }
+
+    @Test
+    fun `Test kPlatArchMap`(){
+        val testCase: Map<String, List<String>> = 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<String, List<String>> = kPlatArchMap
+        assertEquals(testCase, result)
+    }
+}

+ 11 - 0
src/test/resources/utils/xmake --version.txt

@@ -0,0 +1,11 @@
+xmake v2.8.6+HEAD.211710b67, A cross-platform build utility based on Lua
+Copyright (C) 2015-present Ruki Wang, tboox.org, xmake.io
+                         _
+    __  ___ __  __  __ _| | ______
+    \ \/ / |  \/  |/ _  | |/ / __ \
+     >  <  | \__/ | /_| |   <  ___/
+    /_/\_\_|_|  |_|\__ \|_|\_\____|
+                         by ruki, xmake.io
+
+    👉  Manual: https://xmake.io/#/getting_started
+    🙏  Donate: https://xmake.io/#/sponsor

+ 262 - 0
src/test/resources/utils/xmake f -h.txt

@@ -0,0 +1,262 @@
+xmake v2.8.6+HEAD.211710b67, A cross-platform build utility based on Lua
+Copyright (C) 2015-present Ruki Wang, tboox.org, xmake.io
+                         _
+    __  ___ __  __  __ _| | ______
+    \ \/ / |  \/  |/ _  | |/ / __ \
+     >  <  | \__/ | /_| |   <  ___/
+    /_/\_\_|_|  |_|\__ \|_|\_\____|
+                         by ruki, xmake.io
+
+    👉  Manual: https://xmake.io/#/getting_started
+    🙏  Donate: https://xmake.io/#/sponsor
+
+
+Usage: $xmake config|f [options] [target]
+
+Configure the project.
+
+Common options:
+    -q, --quiet                            Quiet operation.
+    -y, --yes                              Input yes by default if need user confirm.
+        --confirm=CONFIRM                  Input the given result if need user confirm.
+                                               - yes
+                                               - no
+                                               - def
+    -v, --verbose                          Print lots of verbose information for users.
+        --root                             Allow to run xmake as root.
+    -D, --diagnosis                        Print lots of diagnosis information (backtrace, check info ..) only for developers.
+                                           And we can append -v to get more whole information.
+                                               e.g. $ xmake -vD
+        --version                          Print the version number and exit.
+    -h, --help                             Print this help message and exit.
+
+    -F FILE, --file=FILE                   Read a given xmake.lua file.
+    -P PROJECT, --project=PROJECT          Change to the given project directory.
+                                           Search priority:
+                                               1. The Given Command Argument
+                                               2. The Envirnoment Variable: XMAKE_PROJECT_DIR
+                                               3. The Current Directory
+
+Command options (config):
+    -c, --clean                            Clean the cached user configs and detection cache.
+        --check                            Just ignore detection cache and force to check all, it will reserve the cached user configs.
+        --export=EXPORT                    Export the current configuration to the given file.
+                                               e.g.
+                                               - xmake f -m debug -xxx=y --export=build/config.txt
+        --import=IMPORT                    Import configs from the given file.
+                                               e.g.
+                                               - xmake f -import=build/config.txt
+        --menu                             Configure project with a menu-driven user interface.
+
+    -p PLAT, --plat=PLAT                   Compile for the given platform. (default: auto)
+                                               - android
+                                               - appletvos
+                                               - applexros
+                                               - bsd
+                                               - cross
+                                               - cygwin
+                                               - haiku
+                                               - iphoneos
+                                               - linux
+                                               - macosx
+                                               - mingw
+                                               - msys
+                                               - wasm
+                                               - watchos
+                                               - windows
+    -a ARCH, --arch=ARCH                   Compile for the given architecture. (default: auto)
+                                               - android: armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mip64
+                                               - appletvos: arm64 armv7 armv7s i386 x86_64
+                                               - applexros: arm64 armv7 armv7s i386 x86_64
+                                               - bsd: i386 x86_64
+                                               - cross: i386 x86_64 arm arm64 mips mips64 riscv riscv64 s390x ppc ppc64 sh4
+                                               - cygwin: i386 x86_64
+                                               - haiku: i386 x86_64
+                                               - iphoneos: arm64 x86_64
+                                               - linux: i386 x86_64 armv7 armv7s arm64-v8a mips mips64 mipsel mips64el loongarch64
+                                               - macosx: x86_64 arm64
+                                               - mingw: i386 x86_64 arm arm64
+                                               - msys: i386 x86_64
+                                               - wasm: wasm32 wasm64
+                                               - watchos: armv7k i386
+                                               - windows: x86 x64 arm64
+    -m MODE, --mode=MODE                   Compile for the given mode. (default: auto)
+                                               - debug
+                                               - release
+    -k KIND, --kind=KIND                   Compile for the given target kind. (default: static)
+                                               - static
+                                               - shared
+                                               - binary
+        --host=HOST                        Set the current host environment. (default: windows)
+        --policies=POLICIES                Set the project policies.
+                                               e.g.
+                                               - xmake f --policies=package.fetch_only
+                                               - xmake f --policies=package.precompiled:n,package.install_only
+
+Command options (Package Configuration):
+        --require=REQUIRE                  Require all dependent packages?
+                                               - yes
+                                               - no
+        --pkg_searchdirs=PKG_SEARCHDIRS    The search directories of the remote package.
+                                               e.g.
+                                               - xmake f --pkg_searchdirs=/dir1;/dir2
+
+Command options (Cross Complation Configuration):
+        --cross=CROSS                      Set cross toolchains prefix
+                                           e.g.
+                                               - i386-mingw32-
+                                               - arm-linux-androideabi-
+        --target_os=TARGET_OS              Set target os only for cross-complation
+        --bin=BIN                          Set cross toolchains bin directory
+                                           e.g.
+                                               - sdk/bin (/arm-linux-gcc ..)
+        --sdk=SDK                          Set cross SDK directory
+                                           e.g.
+                                               - sdk/bin
+                                               - sdk/lib
+                                               - sdk/include
+        --toolchain=TOOLCHAIN              Set toolchain name
+                                           e.g.
+                                               - xmake f --toolchain=clang
+                                               - xmake f --toolchain=[cross|llvm|sdcc ..] --sdk=/xxx
+                                               - run `xmake show -l toolchains` to get all toolchains
+        --nc=NC                            The Nim Compiler
+        --ncld=NCLD                        The Nim Linker
+        --ncar=NCAR                        The Nim Static Library Archiver
+        --ncsh=NCSH                        The Nim Shared Library Linker
+        --linkdirs=LINKDIRS                The Link Search Directories
+        --rc=RC                            The Rust Compiler
+        --rcld=RCLD                        The Rust Linker
+        --rcar=RCAR                        The Rust Static Library Archiver
+        --rcsh=RCSH                        The Rust Shared Library Linker
+        --cc=CC                            The C Compiler
+        --cxx=CXX                          The C++ Compiler
+        --cpp=CPP                          The C Preprocessor
+        --ld=LD                            The Linker
+        --ar=AR                            The Static Library Linker
+        --sh=SH                            The Shared Library Linker
+        --ranlib=RANLIB                    The Static Library Index Generator
+        --cflags=CFLAGS                    The C Compiler Flags
+        --cxflags=CXFLAGS                  The C/C++ compiler Flags
+        --cxxflags=CXXFLAGS                The C++ Compiler Flags
+        --ldflags=LDFLAGS                  The Binary Linker Flags
+        --arflags=ARFLAGS                  The Static Library Linker Flags
+        --shflags=SHFLAGS                  The Shared Library Linker Flags
+        --links=LINKS                      The Link Libraries
+        --syslinks=SYSLINKS                The System Link Libraries
+        --includedirs=INCLUDEDIRS          The Include Search Directories
+        --frameworks=FRAMEWORKS            The Frameworks
+        --frameworkdirs=FRAMEWORKDIRS      The Frameworks Search Directories
+        --cu=CU                            The Cuda Compiler
+        --cu-ccbin=CU-CCBIN                The Cuda Host C++ Compiler
+        --culd=CULD                        The Cuda Linker
+        --cuflags=CUFLAGS                  The Cuda Compiler Flags
+        --culdflags=CULDFLAGS              The Cuda Linker Flags
+        --go=GO                            The Golang Compiler
+        --gcld=GCLD                        The Golang Linker
+        --go-ar=GO-AR                      The Golang Static Library Linker
+        --mm=MM                            The Objc Compiler
+        --mxx=MXX                          The Objc++ Compiler
+        --mflags=MFLAGS                    The Objc Compiler Flags
+        --mxflags=MXFLAGS                  The Objc/c++ Compiler Flags
+        --mxxflags=MXXFLAGS                The Objc++ Compiler Flags
+        --mrc=MRC                          The Microsoft Resource Compiler
+        --mrcflags=MRCFLAGS                The Microsoft Resource Flags
+        --zc=ZC                            The Zig Compiler
+        --zcld=ZCLD                        The Zig Linker
+        --zcar=ZCAR                        The Zig Static Library Archiver
+        --zcsh=ZCSH                        The Zig Shared Library Linker
+        --sc=SC                            The Swift Compiler
+        --scld=SCLD                        The Swift Linker
+        --scsh=SCSH                        The Swift Shared Library Linker
+        --dc=DC                            The Dlang Compiler
+        --dcld=DCLD                        The Dlang Linker
+        --dcar=DCAR                        The Dlang Static Library Archiver
+        --dcsh=DCSH                        The Dlang Shared Library Linker
+        --pc=PC                            The Pascal Compiler
+        --pcld=PCLD                        The Pascal Linker
+        --pcsh=PCSH                        The Pascal Shared Library Linker
+        --fc=FC                            The Fortran Compiler
+        --fcld=FCLD                        The Fortran Linker
+        --fcsh=FCSH                        The Fortran Shared Library Linker
+        --as=AS                            The Assembler
+        --asflags=ASFLAGS                  The Assembler Flags
+
+Command options (Android Configuration):
+        --ndk=NDK                          The NDK Directory
+        --ndk_sdkver=NDK_SDKVER            The SDK Version for NDK (default: auto)
+        --android_sdk=ANDROID_SDK          The Android SDK Directory
+        --build_toolver=BUILD_TOOLVER      The Build Tool Version of Android SDK
+        --ndk_stdcxx=[y|n]                 Use stdc++ library for NDK (default: y)
+        --ndk_cxxstl=NDK_CXXSTL            The stdc++ stl library for NDK
+                                               - c++_static
+                                               - c++_shared
+                                               - gnustl_static
+                                               - gnustl_shared
+                                               - stlport_shared
+                                               - stlport_static
+
+Command options (Cuda SDK Configuration):
+        --cuda=CUDA                        The Cuda SDK Directory (default: auto)
+
+Command options (Qt SDK Configuration):
+        --qt=QT                            The Qt SDK Directory (default: auto)
+        --qt_sdkver=QT_SDKVER              The Qt SDK Version (default: auto)
+
+Command options (Vcpkg Configuration):
+        --vcpkg=VCPKG                      The Vcpkg Directory (default: auto)
+
+Command options (MingW Configuration):
+        --mingw=MINGW                      The MingW SDK Directory
+
+Command options (Emscripten Configuration):
+        --emsdk=EMSDK                      The emsdk directory
+
+Command options (Visual Studio SDK Configuration):
+        --vs=VS                            The Microsoft Visual Studio (default: auto)
+                                             e.g. --vs=2017
+        --vs_toolset=VS_TOOLSET            The Microsoft Visual Studio Toolset Version
+                                             e.g. --vs_toolset=14.0
+        --vs_sdkver=VS_SDKVER              The Windows SDK Version of Visual Studio
+                                             e.g. --vs_sdkver=10.0.15063.0
+        --vs_runtime=VS_RUNTIME            The Runtime library of Visual Studio
+                                               - MT
+                                               - MTd
+                                               - MD
+                                               - MDd
+
+Command options (WDK Configuration):
+        --wdk=WDK                          The WDK Directory (default: auto)
+        --wdk_sdkver=WDK_SDKVER            The WDK Version (default: auto)
+        --wdk_winver=WDK_WINVER            The WDK Windows Version (default: auto)
+                                               - win10[|_rs3]
+                                               - win81
+                                               - win8
+                                               - win7[|_sp1|_sp2|_sp3]
+
+Command options (Other Configuration):
+        --debugger=DEBUGGER                Set debugger (default: auto)
+        --ccache=[y|n]                     Enable or disable the c/c++ compiler cache. (default: y)
+        --ccachedir=CCACHEDIR              Set the ccache directory.
+        --trybuild=TRYBUILD                Enable try-build mode and set the third-party buildsystem tool.
+                                           e.g.
+                                               - xmake f --trybuild=auto; xmake
+                                               - xmake f --trybuild=autoconf -p android --ndk=xxx; xmake
+
+                                           the third-party buildsystems:
+                                               - auto
+                                               - make
+                                               - autoconf
+                                               - cmake
+                                               - scons
+                                               - meson
+                                               - bazel
+                                               - ninja
+                                               - msbuild
+                                               - xcodebuild
+                                               - ndkbuild
+                                               - xrepo
+        --tryconfigs=TRYCONFIGS            Set the extra configurations of the third-party buildsystem for the try-build mode.
+                                           e.g.
+                                               - xmake f --trybuild=autoconf --tryconfigs='--enable-shared=no'
+    -o BUILDIR, --buildir=BUILDIR          Set build directory. (default: build)