tests/test-run.sh: Add tests for proper installation

This commit is contained in:
Alexander Larsson
2016-05-02 10:47:59 +02:00
parent 2f465215e2
commit 123f32015d
4 changed files with 72 additions and 1 deletions

View File

@@ -30,9 +30,11 @@
#include "libgsystem.h"
#include "xdg-app-builtins.h"
#include "xdg-app-utils.h"
static gboolean opt_verbose;
static gboolean opt_version;
static gboolean opt_default_arch;
static gboolean opt_user;
typedef struct {
@@ -80,6 +82,7 @@ static XdgAppCommand commands[] = {
static GOptionEntry global_entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
{ "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", NULL },
{ "default-arch", 0, 0, G_OPTION_ARG_NONE, &opt_default_arch, "Print default arch and exit", NULL },
{ NULL }
};
@@ -187,6 +190,12 @@ xdg_app_option_context_parse (GOptionContext *context,
exit (EXIT_SUCCESS);
}
if (opt_default_arch)
{
g_print ("%s\n", xdg_app_get_arch ());
exit (EXIT_SUCCESS);
}
if (!(flags & XDG_APP_BUILTIN_FLAG_NO_DIR))
{
dir = xdg_app_dir_get (opt_user);

View File

@@ -72,6 +72,9 @@ TEST_DATA_DIR=`mktemp -d /var/tmp/test-xdg-app-XXXXXX`
export XDG_DATA_HOME=${TEST_DATA_DIR}/share
export USERDIR=${TEST_DATA_DIR}/share/xdg-app
export ARCH=`xdg-app --default-arch`
export XDG_APP="${CMD_PREFIX} xdg-app"
assert_streq () {
@@ -86,6 +89,10 @@ assert_has_file () {
test -f "$1" || (echo 1>&2 "Couldn't find '$1'"; exit 1)
}
assert_has_symlink () {
test -L "$1" || (echo 1>&2 "Couldn't find '$1'"; exit 1)
}
assert_has_dir () {
test -d "$1" || (echo 1>&2 "Couldn't find '$1'"; exit 1)
}
@@ -120,6 +127,14 @@ assert_file_has_content () {
fi
}
assert_symlink_has_content () {
if ! readlink "$1" | grep -q -e "$2"; then
readlink "$1" |sed -e 's/^/# /' >&2
echo 1>&2 "Symlink '$1' doesn't match regexp '$2'"
exit 1
fi
}
assert_file_empty() {
if test -s "$1"; then
sed -e 's/^/# /' < "$1" >&2
@@ -144,6 +159,10 @@ run () {
}
run_sh () {
${CMD_PREFIX} xdg-app run --command=bash org.test.Hello -c "$*"
}
sed s#@testdir@#${test_builddir}# ${test_srcdir}/session.conf.in > session.conf
eval `dbus-launch --config-file=session.conf --sh-syntax`

View File

@@ -14,6 +14,20 @@ echo "Hello world, from a sandbox"
EOF
chmod a+x ${DIR}/files/bin/hello.sh
mkdir -p ${DIR}/files/share/applications
cat > ${DIR}/files/share/applications/org.test.Hello.desktop <<EOF
[Desktop Entry]
Version=1.0
Type=Application
Exec=hello.sh
Icon=org.test.Hello
MimeType=x-test/Hello
EOF
mkdir -p ${DIR}/files/share/icons/hicolor/64x64/apps
cp $(dirname $0)/org.test.Hello.png ${DIR}/files/share/icons/hicolor/64x64/apps/
mkdir -p ${DIR}/files/share/app-info/xmls
mkdir -p ${DIR}/files/share/app-info/icons/xdg-app/64x64
gzip -c > ${DIR}/files/share/app-info/xmls/org.test.Hello.xml.gz <<EOF

View File

@@ -21,12 +21,41 @@ set -euo pipefail
. $(dirname $0)/libtest.sh
echo "1..1"
echo "1..3"
setup_repo
install_repo
# Verify that app is correctly installed
assert_has_dir $USERDIR/app/org.test.Hello
assert_has_symlink $USERDIR/app/org.test.Hello/current
assert_symlink_has_content $USERDIR/app/org.test.Hello/current ^$ARCH/master$
assert_has_dir $USERDIR/app/org.test.Hello/$ARCH/master
assert_has_symlink $USERDIR/app/org.test.Hello/$ARCH/master/active
assert_has_file $USERDIR/app/org.test.Hello/$ARCH/master/active/deploy
assert_has_file $USERDIR/app/org.test.Hello/$ARCH/master/active/metadata
assert_has_dir $USERDIR/app/org.test.Hello/$ARCH/master/active/files
assert_has_dir $USERDIR/app/org.test.Hello/$ARCH/master/active/export
assert_has_file $USERDIR/exports/share/applications/org.test.Hello.desktop
# Ensure Exec key is rewritten
assert_file_has_content $USERDIR/exports/share/applications/org.test.Hello.desktop "^Exec=.*/xdg-app run --branch=master --arch=$ARCH --command=hello.sh org.test.Hello$"
assert_has_file $USERDIR/exports/share/icons/hicolor/64x64/apps/org.test.Hello.png
# Ensure triggers ran
assert_has_file $USERDIR/exports/share/applications/mimeinfo.cache
assert_file_has_content $USERDIR/exports/share/applications/mimeinfo.cache x-test/Hello
assert_has_file $USERDIR/exports/share/icons/hicolor/icon-theme.cache
assert_has_file $USERDIR/exports/share/icons/hicolor/index.theme
echo "ok install"
run org.test.Hello > hello_out
assert_file_has_content hello_out '^Hello world, from a sandbox$'
echo "ok hello"
run_sh cat /run/user/`id -u`/xdg-app-info > xai
assert_file_has_content xai '^name=org.test.Hello$'
echo "ok xdg-app-info"