mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-17 07:33:15 +08:00
Add native test entrance
This commit is contained in:
parent
d27228c8c8
commit
89fa379f8f
40
.run/Run Native Main linuxX64.run.xml
Normal file
40
.run/Run Native Main linuxX64.run.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<!--
|
||||
~ Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
~
|
||||
~ 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
~ Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
~
|
||||
~ https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
-->
|
||||
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run Native Main linuxX64" type="GradleRunConfiguration" factoryName="Gradle"
|
||||
folderName="Native Main">
|
||||
<ExternalSystemSettings>
|
||||
<option name="env">
|
||||
<map>
|
||||
<entry key="mirai.native.test.main" value="true"/>
|
||||
</map>
|
||||
</option>
|
||||
<option name="executionName"/>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$/mirai-core"/>
|
||||
<option name="externalSystemIdString" value="GRADLE"/>
|
||||
<option name="scriptParameters" value=""/>
|
||||
<option name="taskDescriptions">
|
||||
<list/>
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value=":mirai-core:linuxX64Test"/>
|
||||
<option value="--tests"/>
|
||||
<option value=""net.mamoe.mirai.internal.test.NativeTestWrapper.test""/>
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions"/>
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<method v="2"/>
|
||||
</configuration>
|
||||
</component>
|
40
.run/Run Native Main macosArm64.run.xml
Normal file
40
.run/Run Native Main macosArm64.run.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<!--
|
||||
~ Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
~
|
||||
~ 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
~ Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
~
|
||||
~ https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
-->
|
||||
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run Native Main macosArm64" type="GradleRunConfiguration" factoryName="Gradle"
|
||||
folderName="Native Main">
|
||||
<ExternalSystemSettings>
|
||||
<option name="env">
|
||||
<map>
|
||||
<entry key="mirai.native.test.main" value="true"/>
|
||||
</map>
|
||||
</option>
|
||||
<option name="executionName"/>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$/mirai-core"/>
|
||||
<option name="externalSystemIdString" value="GRADLE"/>
|
||||
<option name="scriptParameters" value=""/>
|
||||
<option name="taskDescriptions">
|
||||
<list/>
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value=":mirai-core:macosArm64Test"/>
|
||||
<option value="--tests"/>
|
||||
<option value=""net.mamoe.mirai.internal.test.NativeTestWrapper.test""/>
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions"/>
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<method v="2"/>
|
||||
</configuration>
|
||||
</component>
|
40
.run/Run Native Main macosX64.run.xml
Normal file
40
.run/Run Native Main macosX64.run.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<!--
|
||||
~ Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
~
|
||||
~ 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
~ Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
~
|
||||
~ https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
-->
|
||||
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run Native Main macosX64" type="GradleRunConfiguration" factoryName="Gradle"
|
||||
folderName="Native Main">
|
||||
<ExternalSystemSettings>
|
||||
<option name="env">
|
||||
<map>
|
||||
<entry key="mirai.native.test.main" value="true"/>
|
||||
</map>
|
||||
</option>
|
||||
<option name="executionName"/>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$/mirai-core"/>
|
||||
<option name="externalSystemIdString" value="GRADLE"/>
|
||||
<option name="scriptParameters" value=""/>
|
||||
<option name="taskDescriptions">
|
||||
<list/>
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value=":mirai-core:macosX64Test"/>
|
||||
<option value="--tests"/>
|
||||
<option value=""net.mamoe.mirai.internal.test.NativeTestWrapper.test""/>
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions"/>
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<method v="2"/>
|
||||
</configuration>
|
||||
</component>
|
40
.run/Run Native Main mingwX64.run.xml
Normal file
40
.run/Run Native Main mingwX64.run.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<!--
|
||||
~ Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
~
|
||||
~ 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
~ Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
~
|
||||
~ https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
-->
|
||||
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run Native Main mingwX64" type="GradleRunConfiguration" factoryName="Gradle"
|
||||
folderName="Native Main">
|
||||
<ExternalSystemSettings>
|
||||
<option name="env">
|
||||
<map>
|
||||
<entry key="mirai.native.test.main" value="true"/>
|
||||
</map>
|
||||
</option>
|
||||
<option name="executionName"/>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$/mirai-core"/>
|
||||
<option name="externalSystemIdString" value="GRADLE"/>
|
||||
<option name="scriptParameters" value=""/>
|
||||
<option name="taskDescriptions">
|
||||
<list/>
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value=":mirai-core:mingwX64Test"/>
|
||||
<option value="--tests"/>
|
||||
<option value=""net.mamoe.mirai.internal.test.NativeTestWrapper.test""/>
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions"/>
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<method v="2"/>
|
||||
</configuration>
|
||||
</component>
|
@ -88,6 +88,14 @@ val UNIX_LIKE_TARGETS by lazy { LINUX_TARGETS + MAC_TARGETS }
|
||||
|
||||
val NATIVE_TARGETS by lazy { UNIX_LIKE_TARGETS + WIN_TARGETS }
|
||||
|
||||
val HOST_NATIVE_TARGET by lazy {
|
||||
when (HOST_KIND) {
|
||||
HostKind.LINUX -> "linuxX64"
|
||||
HostKind.MACOS -> if (osDetector.arch.contains("aarch")) "macosArm64" else "macosX64"
|
||||
HostKind.WINDOWS -> "mingwX64"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Project.configureHMPPJvm() {
|
||||
extensions.getByType(KotlinMultiplatformExtension::class.java).apply {
|
||||
|
24
mirai-core/src/commonTest/kotlin/test/NativeTestWrapper.kt
Normal file
24
mirai-core/src/commonTest/kotlin/test/NativeTestWrapper.kt
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmName("NativeTestWrapperKt")
|
||||
|
||||
package net.mamoe.mirai.internal.test
|
||||
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.test.Test
|
||||
|
||||
internal class NativeTestWrapper {
|
||||
@Test
|
||||
fun test() {
|
||||
startNativeTestIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
internal expect fun startNativeTestIfNeeded()
|
12
mirai-core/src/jvmBaseTest/kotlin/test/NativeTestWrapper.kt
Normal file
12
mirai-core/src/jvmBaseTest/kotlin/test/NativeTestWrapper.kt
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.internal.test
|
||||
|
||||
internal actual fun startNativeTestIfNeeded() {}
|
@ -14,6 +14,9 @@ import net.mamoe.mirai.internal.message.protocol.MessageProtocolFacade
|
||||
import net.mamoe.mirai.internal.utils.MiraiCoreServices
|
||||
|
||||
|
||||
/**
|
||||
* 初始化 Mirai Native 平台. 必须先调用此 API, 其他 API 才能正常工作.
|
||||
*/
|
||||
public fun initMirai() {
|
||||
_MiraiImpl_static_init()
|
||||
}
|
||||
|
1
mirai-core/src/nativeTest/.gitignore
vendored
Normal file
1
mirai-core/src/nativeTest/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
kotlin/local
|
8
mirai-core/src/nativeTest/kotlin/local/README.md
Normal file
8
mirai-core/src/nativeTest/kotlin/local/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
### Native local test
|
||||
|
||||
这里可以在 Native 启动自定义 main 入口. 使用方法:
|
||||
|
||||
- 复制 `TestMain.kt.template` 为 `TestMain.kt`;
|
||||
- 修改其登录信息;
|
||||
- 在 IDEA Run Configuration 的 'Run Native Main' 中找到适合你的主机平台的配置, 启动运行.
|
||||
注意不要使用 Debug 方式运行, 可能会无法启动.
|
32
mirai-core/src/nativeTest/kotlin/local/TestMain.kt.template
Normal file
32
mirai-core/src/nativeTest/kotlin/local/TestMain.kt.template
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.internal.local
|
||||
|
||||
import net.mamoe.mirai.BotFactory
|
||||
import net.mamoe.mirai.internal.initMirai
|
||||
import net.mamoe.mirai.utils.BotConfiguration
|
||||
|
||||
/**
|
||||
* This test can be started
|
||||
*/
|
||||
suspend fun main() {
|
||||
initMirai()
|
||||
|
||||
val bot = BotFactory.newBot(12346, "") {
|
||||
enableContactCache()
|
||||
protocol = BotConfiguration.MiraiProtocol.ANDROID_PAD
|
||||
workingDir = "test/run"
|
||||
}
|
||||
|
||||
bot.login()
|
||||
|
||||
bot.join()
|
||||
}
|
||||
|
21
mirai-core/src/nativeTest/kotlin/test/NativeTestWrapper.kt
Normal file
21
mirai-core/src/nativeTest/kotlin/test/NativeTestWrapper.kt
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.internal.test
|
||||
|
||||
import kotlinx.cinterop.toKString
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.internal.local.main
|
||||
import platform.posix.getenv
|
||||
|
||||
internal actual fun startNativeTestIfNeeded() {
|
||||
if (getenv("mirai.native.test.main")?.toKString() == "true") {
|
||||
runBlocking { main() } // If you see unresolved reference, create a file "TestMain.kt" in `/local` and add a `main` function in it.
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user