diff --git a/tools/parseInstrument.py b/tools/parseInstrument.py index da424d1e4..c4a00c140 100755 --- a/tools/parseInstrument.py +++ b/tools/parseInstrument.py @@ -5,7 +5,7 @@ Android Instrumentation Test Parser Given a raw Android Instrumentation log (produced by "adb shell am instrument -r ...") this script return zero if all tests pass and non-zero if some tests fail. In case of failure, this script also prints arguments that, if passed to "am instrument", will cause it to re-run just the tests -that failed. This script additionally prints warning about the tests on the STDERR; e.g. slow tests. +that failed. This script additionally prints warnings about the tests on the STDERR; e.g. slow tests. """ import sys import re @@ -14,15 +14,20 @@ STATUS_START = 1 STATUS_DISABLED = -3 SLOW_TEST_THRESHOLD = 5.0 +COLOR_RED = '\033[91m' COLOR_YELLOW = '\033[93m' COLOR_END = '\033[0m' -def warn(msg): +def error(msg): + sys.stderr.write("%s%s%s\n" % (COLOR_RED, msg, COLOR_END)) + +def warning(msg): sys.stderr.write("%s%s%s\n" % (COLOR_YELLOW, msg, COLOR_END)) log_filename = sys.argv[1] current_class, current_method = None, None -failed_tests = "" +failed_tests = [] +am_args = "-e class " exit_code = 1 for line in open(log_filename).readlines(): @@ -37,7 +42,7 @@ for line in open(log_filename).readlines(): if len(matches) > 0: current_method = matches[0] - matches = re.findall('OK \([0-9]* tests\)', line) + matches = re.findall('OK \([0-9]* tests?\)', line) if len(matches) > 0: exit_code = 0 @@ -45,14 +50,18 @@ for line in open(log_filename).readlines(): if len(matches) > 0: status_code = int(matches[0]) if (status_code < 0) and (status_code != STATUS_DISABLED): - failed_tests += f"-e class {current_class}#{current_method} " + am_args += f"{current_class}#{current_method}," + failed_tests.append(f"{current_class}#{current_method}") if status_code == STATUS_START: initial_time = current_time else: elapsed_time = current_time - initial_time if(elapsed_time > SLOW_TEST_THRESHOLD): - warn("SLOW_TEST %s#%s (%.2f seconds)" % (current_class, current_method, elapsed_time)) + warning("SLOW %s#%s (%.2f seconds)" % (current_class, current_method, elapsed_time)) if len(failed_tests) > 0: - print(failed_tests) -sys.exit(exit_code) \ No newline at end of file + for test in failed_tests: + error("FAIL %s" % test) + print(am_args[:-1]) + +sys.exit(exit_code) diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/BackupSteps.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/BackupSteps.kt index c281932eb..f98164347 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/BackupSteps.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/BackupSteps.kt @@ -20,6 +20,7 @@ package org.isoron.uhabits.acceptance.steps import android.os.Build.VERSION.SDK_INT +import android.os.SystemClock.sleep import androidx.test.uiautomator.By import androidx.test.uiautomator.UiSelector import org.isoron.uhabits.BaseUserInterfaceTest.Companion.device @@ -39,7 +40,7 @@ fun exportFullBackup() { } fun clearDownloadFolder() { - device.executeShellCommand("rm -rf /sdcard/Download/") + device.executeShellCommand("rm -rf /sdcard/Download") } fun clearBackupFolder() { @@ -86,6 +87,7 @@ fun importBackupFromDownloadFolder() { device.findObject(UiSelector().textContains("Loop")).click() } else { device.click(50, 90) // Click menu button + Thread.sleep(1000) device.findObject(UiSelector().textContains("Download")).click() device.findObject(UiSelector().textContains("Loop")).click() } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.kt index 05adfdbbe..f7dcea3c2 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.kt @@ -32,6 +32,7 @@ import org.isoron.uhabits.R import org.isoron.uhabits.core.models.Entry import org.isoron.uhabits.core.models.EntryList import org.isoron.uhabits.core.models.Habit +import org.isoron.uhabits.core.models.Timestamp import org.isoron.uhabits.core.utils.DateUtils.Companion.getTodayWithOffset import org.junit.Test import org.junit.runner.RunWith @@ -42,10 +43,12 @@ class CheckmarkWidgetTest : BaseViewTest() { private lateinit var habit: Habit private lateinit var entries: EntryList private lateinit var view: FrameLayout - private val today = getTodayWithOffset() + private lateinit var today: Timestamp + override fun setUp() { super.setUp() setTheme(R.style.WidgetTheme) + today = getTodayWithOffset() prefs.widgetOpacity = 255 prefs.isSkipEnabled = true habit = fixtures.createVeryLongHabit()