Skip to content

Run tests on Android ​

dub cannot cross-compile, so an Android test build skips it: the Nix builder legacyPackages.buildDAndroidTests (nix/packages/android/build-d-android-tests.nix) compiles a package's unittests into one executable per ABI (arm64-v8a and x86_64) with ldc2 -i. A device has no runner executable, so the binary runs its tests itself, one at a time: the -i, -e, -v, -l and -t flags work, and benchmarks, workloads and @ctfe tests do not run (see the CLI reference's runner section).

Declare the package ​

Call the builder from a file under nix/packages/android/, as font-tests.nix does for sparkles:font:

nix
androidPackages.font-android-tests = config.legacyPackages.buildDAndroidTests {
  pname = "font-android-tests";
  exeName = "font-tests";
  testedDirs = [ "libs/font/src" "libs/font/test" ];
  versions = [ "Have_sparkles_base" ];
};
  • testedDirs are the directories whose modules are tested. The builder writes the dub_test_root module dub would generate from them: every module except package.d, which dub omits too.
  • srcDirs adds -I paths for in-tree dependencies. The runner's own closure, sparkles:base and what it imports, is always added.
  • dubDeps unzips registry dependencies from their flake inputs. Their own unittests are not built.

Declaring it under androidPackages rather than packages both publishes it and keeps it out of the desktop aggregate (androidPackageNames is derived from that set). Add it to the all-android aggregate in nix/packages/android/default.nix too, so CI builds it.

Build and run ​

bash
nix build .#font-android-tests
nix develop .#android -c hue-emulator -no-window &   # or a device on adb
adb push result/bin/x86_64/font-tests /data/local/tmp/
adb shell /data/local/tmp/font-tests -t 1

Environment variables the tests read, such as SPARKLES_FONTS_PATH, go on the adb shell command line, and the files they name must be pushed too. A test whose input is missing skips, as on the host.

What differs from the host ​

  • Plain-text reports. sparkles:ui stays off the import path, so the live progress region and the result tables fall back to plain lines.
  • No @ctfe probe. There is no compiler on the device, so a package with @ctfe tests gets a "no D compiler found" notice and the probe is skipped.
  • Bench and perf modes degrade. Counters, tracepoints and pressure files that Android does not expose are reported as missing capabilities.