From b2370297364486cfcebd34369df679846bde3a5e Mon Sep 17 00:00:00 2001 From: Alexander Sosedkin Date: Wed, 14 Feb 2024 22:47:41 +0100 Subject: [PATCH] tests/on-device/config-term-colors: add --- tests/on-device/config-term-colors.bats | 88 +++++++++++++++++++++++++ tests/on-device/config-term-colors.nix | 12 ++++ tests/on-device/lib.bash | 8 ++- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 tests/on-device/config-term-colors.bats create mode 100644 tests/on-device/config-term-colors.nix diff --git a/tests/on-device/config-term-colors.bats b/tests/on-device/config-term-colors.bats new file mode 100644 index 0000000..0b6d44c --- /dev/null +++ b/tests/on-device/config-term-colors.bats @@ -0,0 +1,88 @@ +# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. + +load lib + +setup() { + _setup + [[ ! -d $HOME/.termux ]] + mkdir $HOME/.termux + + cat > $HOME/.termux/colors.properties.refl < $HOME/.termux/colors.properties.refs +} + +teardown() { + rm -f $HOME/.termux/colors.properties + rm -f $HOME/.termux/colors.properties.refs + rm -f $HOME/.termux/colors.properties.refl + rm -f $HOME/.termux/colors.properties.bak + rm -fd $HOME/.termux +} + +@test 'specifying colors works (no backup)' { + [[ ! -e $HOME/.termux/colors.properties ]] + [[ ! -e $HOME/.termux/colors.properties.bak ]] + + cp \ + "$ON_DEVICE_TESTS_DIR/config-term-colors.nix" \ + ~/.config/nixpkgs/nix-on-droid.nix + nix-on-droid switch + _diff -u $HOME/.termux/colors.properties $HOME/.termux/colors.properties.refl + + [[ -e $HOME/.termux/colors.properties ]] + [[ ! -e $HOME/.termux/colors.properties.bak ]] + + switch_to_default_config + + [[ ! -e $HOME/.termux/colors.properties ]] + [[ ! -e $HOME/.termux/colors.properties.bak ]] +} + +@test 'specifying colors works (backup)' { + cat $HOME/.termux/colors.properties.refs > $HOME/.termux/colors.properties + + [[ -e $HOME/.termux/colors.properties ]] + [[ ! -e $HOME/.termux/colors.properties.bak ]] + + cp \ + "$ON_DEVICE_TESTS_DIR/config-term-colors.nix" \ + ~/.config/nixpkgs/nix-on-droid.nix + nix-on-droid switch + + [[ -e $HOME/.termux/colors.properties ]] + [[ -e $HOME/.termux/colors.properties.bak ]] + _diff -u $HOME/.termux/colors.properties $HOME/.termux/colors.properties.refl + _diff -u $HOME/.termux/colors.properties.bak \ + $HOME/.termux/colors.properties.refs + + switch_to_default_config + + [[ -e $HOME/.termux/colors.properties ]] + [[ ! -e $HOME/.termux/colors.properties.bak ]] +} + +@test 'specifying a wrong keyword for color fails' { + [[ ! -e $HOME/.termux/colors.properties ]] + [[ ! -e $HOME/.termux/colors.properties.bak ]] + + cat $HOME/.termux/colors.properties.refs > $HOME/.termux/colors.properties + _sed 's|color0|color16|' \ + "$ON_DEVICE_TESTS_DIR/config-term-colors.nix" \ + > ~/.config/nixpkgs/nix-on-droid.nix + run nix-on-droid switch + [[ $status -eq 1 ]] + [[ $output =~ \ + \`terminal.colors\`\ only\ accepts\ the\ following\ attributes: ]] + + switch_to_default_config + + [[ -e $HOME/.termux/colors.properties ]] + [[ ! -e $HOME/.termux/colors.properties.bak ]] + _diff -u $HOME/.termux/colors.properties $HOME/.termux/colors.properties.refs +} diff --git a/tests/on-device/config-term-colors.nix b/tests/on-device/config-term-colors.nix new file mode 100644 index 0000000..ee26676 --- /dev/null +++ b/tests/on-device/config-term-colors.nix @@ -0,0 +1,12 @@ +_: + +{ + system.stateVersion = "23.05"; + terminal.colors = { + background = "#FFFFFF"; + foreground = "#000000"; + cursor = "#FF0000"; + color0 = "#00FF00"; + color15 = "#00FF15"; + }; +} diff --git a/tests/on-device/lib.bash b/tests/on-device/lib.bash index b7ecdb4..137052f 100644 --- a/tests/on-device/lib.bash +++ b/tests/on-device/lib.bash @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. +# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. # call _setup when defining a setup function in your test _setup() { @@ -64,3 +64,9 @@ _sed() { storePath="$(nix-build "" --no-out-link --attr gnused)" "${storePath}/bin/sed" "$@" } + +_diff() { + local storePath + storePath="$(nix-build "" --no-out-link --attr diffutils)" + "${storePath}/bin/diff" "$@" +}