From 84a73785021d83078ed722942cc7aac377deb13b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 29 Sep 2018 19:12:11 -0400 Subject: test: Have $HOME be owned by test-common.sh instead of testenv --- test/test-common.sh | 27 +++++++++++++++++++++++---- test/testenv | 18 ------------------ 2 files changed, 23 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/test/test-common.sh b/test/test-common.sh index bd66fc7..2adab60 100755 --- a/test/test-common.sh +++ b/test/test-common.sh @@ -1,7 +1,7 @@ #!/hint/bash -if [[ $HOME == "$(eval echo ~$USER)" ]]; then - libremessages error "\$HOME is the default for %s; use testenv: %s" "$USER" "$HOME" +if [[ -z $LIBRETOOLS_LIBDIR || -z $_librelib_conf_sh_sysconfdir || -z $_librelib_conf_sh_pkgconfdir ]]; then + libremessages error 'Must be run with ./testenv' exit 1 fi @@ -28,6 +28,25 @@ before() { stat=0 + export HOME="$tmpdir/home" + export GNUPGHOME="$HOME/.gnupg" + export XDG_CACHE_HOME="$HOME/.cache" + export XDG_CONFIG_HOME="$HOME/.config" + + mkdir -p -- "$GNUPGHOME" + chmod 700 -- "$GNUPGHOME" + unset GPGKEY + gpg --quiet --no-tty --batch --gen-key <<-eot + Key-Type: default + Key-Usage: sign + Name-Real: Bob Tester + Name-Email: tester@localhost + Expire-Date: 0 + %no-protection + %commit + eot + export GPGKEY="$(gpg --quiet --list-secret-keys --with-colons | awk -F: '/^sec:/{print substr($5,9)}')" + _common_before common_before } @@ -36,9 +55,9 @@ after() { common_after gpg-connect-agent KILLAGENT /bye || true if [[ -f "$tmpdir/.used-sudo" ]]; then - sudo rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" + sudo rm -rf -- "$tmpdir" else - rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" + rm -rf -- "$tmpdir" fi } diff --git a/test/testenv b/test/testenv index a61fd24..f6c19d5 100755 --- a/test/testenv +++ b/test/testenv @@ -55,27 +55,9 @@ # Set up the environment export PATH="$destdir/usr/bin:$PATH" export LIBRETOOLS_LIBDIR="$destdir/usr/lib/libretools" - export HOME=$TMPDIR/home - export GNUPGHOME="$HOME/.gnupg" - export XDG_CACHE_HOME="$HOME/.cache" - export XDG_CONFIG_HOME="$HOME/.config" export _librelib_conf_sh_sysconfdir="$destdir/etc" export _librelib_conf_sh_pkgconfdir="$destdir/etc/libretools.d" - mkdir -p -- "$GNUPGHOME" - chmod 700 -- "$GNUPGHOME" - unset GPGKEY - gpg --quiet --no-tty --batch --gen-key <<-eot - Key-Type: default - Key-Usage: sign - Name-Real: Bob Tester - Name-Email: tester@localhost - Expire-Date: 0 - %no-protection - %commit - eot - export GPGKEY="$(gpg --quiet --list-secret-keys --with-colons | awk -F: '/^sec:/{print substr($5,9)}')" - # Hack to respect our variables in sudo _sudo() { local vars=(TMPDIR PATH LIBRETOOLS_LIBDIR GNUPGHOME XDG_CACHE_HOME XDG_CONFIG_HOME _librelib_conf_sh_sysconfdir GPGKEY) -- cgit v1.2.2