tests: increase readability through small helper functions

This commit is contained in:
Tobias Happ 2021-12-12 17:14:24 +01:00
parent 7f983228fe
commit 248632699e
4 changed files with 20 additions and 15 deletions

View file

@ -10,10 +10,9 @@ load lib
# set up / build / activate the configuration # set up / build / activate the configuration
cat "$ON_DEVICE_TESTS_DIR/config-flake-h-m.cfg.nix" \ cat "$ON_DEVICE_TESTS_DIR/config-flake-h-m.cfg.nix" \
> ~/.config/nixpkgs/nix-on-droid.nix > ~/.config/nixpkgs/nix-on-droid.nix
nix-shell -p gnused --run \ _sed "s|<<FLAKE_URL>>|$FLAKE_URL|g" \
"sed 's|<<FLAKE_URL>>|$FLAKE_URL|g' \ "$ON_DEVICE_TESTS_DIR/config-flake-h-m.flake.nix" \
< '$ON_DEVICE_TESTS_DIR/config-flake-h-m.flake.nix' \ > ~/.config/nixpkgs/flake.nix
> ~/.config/nixpkgs/flake.nix"
pushd ~/.config/nixpkgs pushd ~/.config/nixpkgs
nix-shell -p nixFlakes --run \ nix-shell -p nixFlakes --run \
'nix build \ 'nix build \

View file

@ -8,17 +8,15 @@ load lib
assert_no_command unzip assert_no_command unzip
# set up / build / activate the configuration # set up / build / activate the configuration
nix-shell -p gnused --run \ _sed \
"sed \ -e 's/vim/nano/' \
-e s/vim/nano/ \ -e 's/#unzip/unzip/' \
-e s/#unzip/unzip/ \ "$CHANNEL_DIR/modules/environment/login/nix-on-droid.nix.default" \
< '$CHANNEL_DIR/modules/environment/login/nix-on-droid.nix.default' \ > ~/.config/nixpkgs/nix-on-droid.nix
> ~/.config/nixpkgs/nix-on-droid.nix"
nix-shell -p gnused --run \ _sed "s|<<FLAKE_URL>>|$FLAKE_URL|g" \
"sed 's|<<FLAKE_URL>>|$FLAKE_URL|g' \ "$ON_DEVICE_TESTS_DIR/config-flake.nix" \
< '$ON_DEVICE_TESTS_DIR/config-flake.nix' \ > ~/.config/nixpkgs/flake.nix
> ~/.config/nixpkgs/flake.nix"
# this is more cumbersome than options, # this is more cumbersome than options,
# but this is what we recommend to users, so taking the hard way # but this is what we recommend to users, so taking the hard way

View file

@ -4,7 +4,9 @@
TEMPDIR=/tmp/.tmp-gnumake.$$ TEMPDIR=/tmp/.tmp-gnumake.$$
mkdir -p "$TEMPDIR" mkdir -p "$TEMPDIR"
echo -e 'x:\n\techo desired output > x' > "$TEMPDIR/Makefile" echo -e 'x:\n\techo desired output > x' > "$TEMPDIR/Makefile"
nix-shell -p gnumake --run "make -C $TEMPDIR x"
"$(nix-build "<nixpkgs>" --no-out-link --attr gnumake)/bin/make" -C "$TEMPDIR" x
[[ -e "$TEMPDIR/x" ]] [[ -e "$TEMPDIR/x" ]]
[[ "$(cat "$TEMPDIR/x")" == 'desired output' ]] [[ "$(cat "$TEMPDIR/x")" == 'desired output' ]]
} }

View file

@ -51,3 +51,9 @@ switch_to_default_config() {
> ~/.config/nixpkgs/nix-on-droid.nix > ~/.config/nixpkgs/nix-on-droid.nix
nix-on-droid switch nix-on-droid switch
} }
_sed() {
local storePath
storePath="$(nix-build "<nixpkgs>" --no-out-link --attr gnused)"
"${storePath}/bin/sed" "$@"
}