From 341d4cd851a7b62ddd653e2b656eba8ead366db2 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Wed, 20 Dec 2023 17:46:02 +0800 Subject: [PATCH] add -t argument for test run --- project/MornyConfiguration.scala | 2 +- .../scala/cc/sukazyo/cono/morny/MornyCoeur.scala | 16 ++++++++++++---- .../scala/cc/sukazyo/cono/morny/ServerMain.scala | 6 +++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/project/MornyConfiguration.scala b/project/MornyConfiguration.scala index bdfd34d..b6422b7 100644 --- a/project/MornyConfiguration.scala +++ b/project/MornyConfiguration.scala @@ -8,7 +8,7 @@ object MornyConfiguration { val MORNY_CODE_STORE = "https://github.com/Eyre-S/Coeur-Morny-Cono" val MORNY_COMMIT_PATH = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s" - val VERSION = "2.0.0-alpha2" + val VERSION = "2.0.0-alpha3" val VERSION_DELTA: Option[String] = None val CODENAME = "guanggu" diff --git a/src/main/scala/cc/sukazyo/cono/morny/MornyCoeur.scala b/src/main/scala/cc/sukazyo/cono/morny/MornyCoeur.scala index 3f3f2d4..c17eb9b 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/MornyCoeur.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/MornyCoeur.scala @@ -3,7 +3,7 @@ package cc.sukazyo.cono.morny import cc.sukazyo.cono.morny.bot.command.MornyCommands import cc.sukazyo.cono.morny.daemon.MornyDaemons import cc.sukazyo.cono.morny.Log.{exceptionLog, logger} -import cc.sukazyo.cono.morny.MornyCoeur.THREAD_SERVER_EXIT +import cc.sukazyo.cono.morny.MornyCoeur.{TestRun, THREAD_SERVER_EXIT} import cc.sukazyo.cono.morny.bot.api.EventListenerManager import cc.sukazyo.cono.morny.bot.event.{MornyEventListeners, MornyOnInlineQuery, MornyOnTelegramCommand, MornyOnUpdateTimestampOffsetLock} import cc.sukazyo.cono.morny.bot.query.MornyQueries @@ -21,9 +21,11 @@ object MornyCoeur { val THREAD_SERVER_EXIT = "system-exit" + object TestRun + } -class MornyCoeur (using val config: MornyConfig) { +class MornyCoeur (using val config: MornyConfig)(testRun: Boolean = false) { given MornyCoeur = this @@ -43,8 +45,6 @@ class MornyCoeur (using val config: MornyConfig) { System exit -1 throw RuntimeException() - configure_exitCleanup() - ///<<< BLOCK END instance configure & startup stage 1 /** inner value: about why morny exit, used in [[daemon.MornyReport]]. */ @@ -94,6 +94,14 @@ class MornyCoeur (using val config: MornyConfig) { ///>>> BLOCK START instance configure & startup stage 2 + logger info "done initialize." + if testRun then + logger info "done test run, exiting." + this.exit(0, TestRun) + + configure_exitCleanup() + // put things that need to cleanup when exit below + // so that it will be correctly cleanup when normal run and will not execute in testRun. daemons.start() logger info "start telegram event listening" import com.pengrad.telegrambot.TelegramException diff --git a/src/main/scala/cc/sukazyo/cono/morny/ServerMain.scala b/src/main/scala/cc/sukazyo/cono/morny/ServerMain.scala index de6374a..ba86cd9 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/ServerMain.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/ServerMain.scala @@ -21,6 +21,7 @@ object ServerMain { val config = new MornyConfig.Prototype() var mode_echoVersion = false var mode_echoHello = false + var mode_testRun = false var showHello = true val unknownArgs = ArrayBuffer[String]() @@ -31,6 +32,7 @@ object ServerMain { args(i) match { case "-d" | "--dbg" | "--debug" => Log.debug(true) + case "-t" | "--test" => mode_testRun = true case "--no-hello" | "-hf" | "--quiet" | "-q" => showHello = false case "--only-hello" | "-ho" | "-o" | "-hi" => mode_echoHello = true @@ -156,7 +158,9 @@ object ServerMain { Thread.currentThread setName THREAD_MORNY_INIT try - MornyCoeur(using config build) + MornyCoeur(using config build)( + testRun = mode_testRun + ) catch { case _: CheckFailure.NullTelegramBotKey => logger.info("Parameter required has no value:\n --token.")