From 6de4300cb855a5b842811bccb7a72f9b5ac4e00d Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 3 Sep 2020 14:03:17 +0300 Subject: [PATCH] Testing how the test errors are displayed in Travis --- .../assets/jsons/translations/Polish.properties | 2 +- core/src/com/unciv/UncivGame.kt | 2 +- core/src/com/unciv/models/ruleset/Ruleset.kt | 14 +++++++------- .../com/unciv/models/translations/Translations.kt | 12 ++++++------ tests/build.gradle.kts | 14 ++++++++++++++ tests/src/com/unciv/testing/TranslationTests.kt | 13 ++++++++++++- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/android/assets/jsons/translations/Polish.properties b/android/assets/jsons/translations/Polish.properties index c9fadc58d2..6d87bda407 100644 --- a/android/assets/jsons/translations/Polish.properties +++ b/android/assets/jsons/translations/Polish.properties @@ -29,7 +29,7 @@ Hydro Plant = Elektrownia Wodna # Diplomacy,Trade,Nations -Requires [buildingName] to be built in the city = Miasto musi posiadać: [buildingName] +Requires [buildingName] to be built in the city = Miasto musi posiadać: [errorInducingChange] Requires [buildingName] to be built in all cities = Wszystkie twoje miasta muszą posiadać: [buildingName] Provides a free [buildingName] in the city = Zapewnia darmowy budynek: [buildingName] w tym mieście Requires worked [resource] near city = Wymaga ulepszonego źródła surowca [resource] w pobliżu miasta diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 9cee9f70e1..1bd4916f93 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -78,7 +78,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() { Gdx.graphics.isContinuousRendering = settings.continuousRendering thread(name = "LoadJSON") { - RulesetCache.loadRulesets() + RulesetCache.loadRulesets(printOutput = true) translations.tryReadTranslationForCurrentLanguage() translations.loadPercentageCompleteOfLanguages() diff --git a/core/src/com/unciv/models/ruleset/Ruleset.kt b/core/src/com/unciv/models/ruleset/Ruleset.kt index 85d2ab1925..c1b8d1b07f 100644 --- a/core/src/com/unciv/models/ruleset/Ruleset.kt +++ b/core/src/com/unciv/models/ruleset/Ruleset.kt @@ -98,7 +98,7 @@ class Ruleset { } - fun load(folderHandle: FileHandle) { + fun load(folderHandle: FileHandle, printOutput:Boolean) { val gameBasicsStartTime = System.currentTimeMillis() val modOptionsFile = folderHandle.child("ModOptions.json") @@ -163,7 +163,7 @@ class Ruleset { if (difficultiesFile.exists()) difficulties += createHashmap(jsonParser.getFromJson(Array::class.java, difficultiesFile)) val gameBasicsLoadTime = System.currentTimeMillis() - gameBasicsStartTime - println("Loading game basics - " + gameBasicsLoadTime + "ms") + if(printOutput) println("Loading ruleset - " + gameBasicsLoadTime + "ms") } /** Building costs are unique in that they are dependant on info in the technology part. @@ -204,13 +204,13 @@ class Ruleset { * save all of the loaded rulesets somewhere for later use * */ object RulesetCache :HashMap() { - fun loadRulesets(consoleMode:Boolean=false) { + fun loadRulesets(consoleMode:Boolean=false, printOutput: Boolean=false) { clear() for (ruleset in BaseRuleset.values()) { val fileName = "jsons/${ruleset.fullName}" val fileHandle = if (consoleMode) FileHandle(fileName) else Gdx.files.internal(fileName) - this[ruleset.fullName] = Ruleset().apply { load(fileHandle) } + this[ruleset.fullName] = Ruleset().apply { load(fileHandle, printOutput) } } val modsHandles = if(consoleMode) FileHandle("mods").list() @@ -220,11 +220,11 @@ object RulesetCache :HashMap() { if (modFolder.name().startsWith('.')) continue try { val modRuleset = Ruleset() - modRuleset.load(modFolder.child("jsons")) + modRuleset.load(modFolder.child("jsons"), printOutput) modRuleset.name = modFolder.name() this[modRuleset.name] = modRuleset - println("Mod loaded successfully: " + modRuleset.name) - checkModLinks(modRuleset) + if(printOutput) println("Mod loaded successfully: " + modRuleset.name) + if(printOutput) checkModLinks(modRuleset) } catch (ex: Exception) { println("Exception loading mod '${modFolder.name()}':") println(" ${ex.localizedMessage}") diff --git a/core/src/com/unciv/models/translations/Translations.kt b/core/src/com/unciv/models/translations/Translations.kt index 0d71b90285..c15bbad89d 100644 --- a/core/src/com/unciv/models/translations/Translations.kt +++ b/core/src/com/unciv/models/translations/Translations.kt @@ -71,7 +71,7 @@ class Translations : LinkedHashMap(){ } - private fun tryReadTranslationForLanguage(language: String) { + private fun tryReadTranslationForLanguage(language: String, printOutput: Boolean) { val translationStart = System.currentTimeMillis() val translationFileName = "jsons/translations/$language.properties" @@ -99,7 +99,7 @@ class Translations : LinkedHashMap(){ createTranslations(language, languageTranslations) val translationFilesTime = System.currentTimeMillis() - translationStart - println("Loading translation file for $language - " + translationFilesTime + "ms") + if(printOutput) println("Loading translation file for $language - " + translationFilesTime + "ms") } private fun createTranslations(language: String, @@ -120,7 +120,7 @@ class Translations : LinkedHashMap(){ } fun tryReadTranslationForCurrentLanguage(){ - tryReadTranslationForLanguage(UncivGame.Current.settings.language) + tryReadTranslationForLanguage(UncivGame.Current.settings.language, false) } // This function is too strange for me, however, let's keep it "as is" for now. - JackRainy @@ -152,7 +152,7 @@ class Translations : LinkedHashMap(){ .filter { Gdx.files.internal("jsons/translations/$it.properties").exists() } } - fun readAllLanguagesTranslation() { + fun readAllLanguagesTranslation(printOutput:Boolean=false) { // Apparently you can't iterate over the files in a directory when running out of a .jar... // https://www.badlogicgames.com/forum/viewtopic.php?f=11&t=27250 // which means we need to list everything manually =/ @@ -160,11 +160,11 @@ class Translations : LinkedHashMap(){ val translationStart = System.currentTimeMillis() for (language in getLanguagesWithTranslationFile()) { - tryReadTranslationForLanguage(language) + tryReadTranslationForLanguage(language, printOutput) } val translationFilesTime = System.currentTimeMillis() - translationStart - println("Loading translation files - "+translationFilesTime+"ms") + if(printOutput) println("Loading translation files - "+translationFilesTime+"ms") } fun loadPercentageCompleteOfLanguages(){ diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 1ca0c6ee43..2455deaf40 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -1,4 +1,5 @@ import com.unciv.build.BuildConfig +import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { id("java") @@ -11,6 +12,19 @@ java { tasks { test { workingDir = file("../android/assets") + testLogging.debug { + events( + TestLogEvent.STARTED, + TestLogEvent.FAILED, + TestLogEvent.PASSED, + TestLogEvent.SKIPPED, + TestLogEvent.STANDARD_ERROR, + TestLogEvent.STANDARD_OUT + ) + + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL + } + } compileJava { diff --git a/tests/src/com/unciv/testing/TranslationTests.kt b/tests/src/com/unciv/testing/TranslationTests.kt index 9d75fa7821..552c76385b 100644 --- a/tests/src/com/unciv/testing/TranslationTests.kt +++ b/tests/src/com/unciv/testing/TranslationTests.kt @@ -7,12 +7,13 @@ import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.RulesetCache import com.unciv.models.translations.TranslationFileWriter import com.unciv.models.translations.Translations -import com.unciv.models.translations.eitherSquareBraceRegex import com.unciv.models.translations.squareBraceRegex import org.junit.Assert import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import java.io.OutputStream +import java.io.PrintStream import java.util.* @RunWith(GdxTestRunner::class) @@ -22,9 +23,19 @@ class TranslationTests { @Before fun loadTranslations() { + // Since the ruleset and translation loader have their own output, + // We 'disable' the output stream for their outputs, and only enable it for the twst itself. + val outputChannel = System.out + System.setOut(PrintStream(object : OutputStream() { + override fun write(b: Int) {} + })) +// System.setOut(TextWriter.Null) +// Console(). //(TextWriter.Null); translations.readAllLanguagesTranslation() RulesetCache.loadRulesets() ruleset = RulesetCache.getBaseRuleset() + System.setOut(outputChannel) +// Console.SetOut() } @Test