How can I run unit-tests and set the system language of the simulator from a script?

Recently I got many complaints that my watch-app (not datafield) crashes at start. It turned out to be a translation bug: some string is too long. I opened this feature request: https://forums.garmin.com/developer/connect-iq/i/bug-reports/feature-request-add-maxlength-maxsize-attributes-to-string-resources-and-fail-at-compilation-if-a-string-is-too-long so we could set a maxSize, maxLength on strings and the compiler would tell us in compile time if some string is too long. But until that feature is implemented... I'm thinking about some workaround.

I wrote this "unit-test":

(:test)
static function validateFieldUnitTranslationLength(logger as Logger) as Boolean {
	var resources = [Rez.Strings.stepsUnits, Rez.Strings.stepsPerHourUnits, Rez.Strings.stepsPerKmUnits, Rez.Strings.stepsPerMileUnits];
	for (var i = 0; i < resources.size(); i++) {
		var res = resources[i];
		var str = WatchUi.loadResource(res) as String;
		var arr = str.toUtf8Array();
		if (arr.size() > 15) {
			logger.error("lang: " + System.getDeviceSettings().systemLanguage + ", str: " + str + ", size: " + arr.size());
			return false;
		}
	}
	return true;
}

It works, but I'll need to run this in all the existing languages. For that I'd need to do the following in VSCode:

1. Run any app
2. Set the language
3. Run the unit-tests of my app
4. because now I can't change the language of the simulator (it only displays "Not Set") I'll need to goto 1.

Is there a way to do this from a script? Something like:

for lang in [ara, eng, hun] {
    setLang(lang)
    runUnitTests(fr965)
}


  • It would be really useful if the simulator could be updated programatically to change language / units etc.

    I have a bash script that automates running the simulator and taking screenshots of the UI for testing, you can manipulate the watch using xdotool and pressing eg. Enter (to simulate the SELECT button). I guess it might be possible to do something similar to move through the simulator UI menus and change the language, but would be a lot easier if there was a command line interface to do it.