Skip to content

Commit

Permalink
tests/on-device/config-term-colors: add
Browse files Browse the repository at this point in the history
  • Loading branch information
t184256 committed Feb 14, 2024
1 parent afcb9c2 commit 203d9d8
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
88 changes: 88 additions & 0 deletions tests/on-device/config-term-colors.bats
Original file line number Diff line number Diff line change
@@ -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 <<EOF
background=#FFFFFF
color0=#00FF00
color15=#00FF15
cursor=#FF0000
foreground=#000000
EOF
echo 'background = #012345' > $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
}
12 changes: 12 additions & 0 deletions tests/on-device/config-term-colors.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_:

{
system.stateVersion = "23.05";
terminal.colors = {
background = "#FFFFFF";
foreground = "#000000";
cursor = "#FF0000";
color0 = "#00FF00";
color15 = "#00FF15";
};
}
8 changes: 7 additions & 1 deletion tests/on-device/lib.bash
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -64,3 +64,9 @@ _sed() {
storePath="$(nix-build "<nixpkgs>" --no-out-link --attr gnused)"
"${storePath}/bin/sed" "$@"
}

_diff() {
local storePath
storePath="$(nix-build "<nixpkgs>" --no-out-link --attr diffutils)"
"${storePath}/bin/diff" "$@"
}

0 comments on commit 203d9d8

Please sign in to comment.