-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-plugins.sh
More file actions
executable file
·93 lines (75 loc) · 2.28 KB
/
test-plugins.sh
File metadata and controls
executable file
·93 lines (75 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /bin/bash
set -eo pipefail
repodir="${REPODIR:-"$(git rev-parse --show-toplevel)"}"
tempdir="$(mktemp --tmpdir --directory linuxdeploy-misc-plugin-XXXXX)"
_cleanup() {
# shellcheck disable=SC2317
[[ -d "$tempdir" ]] && rm -r "$tempdir"
}
trap _cleanup EXIT
# allow running plugins which require linuxdeploy internally
pushd "$tempdir" &>/dev/null
echo -e -n "\033[1mDownloading linuxdeploy and plugins...\033[0m"
wget -qN https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
wget -qN https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage
chmod +x linuxdeploy*
popd &>/dev/null
export LINUXDEPLOY="$tempdir"/linuxdeploy-x86_64.AppImage
echo "done"
appdir="${APPDIR:-$tempdir/AppDir}"
count=0
failed=0
run_valid_command() {
set +e
((count++))
if out="$("$@" 2>&1 )"; then
echo -e "[\033[1;32m OK \033[0m]"
else
echo -e "[\033[1;31mFAILED\033[0m]"
((failed++))
echo "$out"
fi
set -e
}
run_invalid_command() {
set +e
((count++))
if out="$("$@" 2>&1 )"; then
echo -e "[\033[1;31mFAILED\033[0m]"
((failed++))
echo "$out"
else
echo -e "[\033[1;32m OK \033[0m]"
fi
set -e
}
while IFS= read -r -d '' plugin; do
name="$(basename "$plugin")"
echo -e "\033[1mTesting plugin $name...\033[0m"
printf "%-60s" " - lint plugin"
run_valid_command shellcheck --external-sources "$plugin"
printf "%-60s" " - run with wrong usage"
run_invalid_command bash "$plugin"
printf "%-60s" " - run with --plugin-api-version"
run_valid_command bash "$plugin" --plugin-api-version
printf "%-60s" " - run with --appdir"
env="$(dirname "$plugin")/.test.env"
if [ -f "$env" ]; then
# shellcheck disable=SC1090
(set -o allexport; source "$env"; run_valid_command bash "$plugin" --appdir "$appdir")
else
run_valid_command bash "$plugin" --appdir "$appdir"
fi
hook="$appdir/apprun-hooks/$name"
if [ -f "$hook" ]; then
printf "%-60s" " - lint apprun-hook"
run_valid_command shellcheck -s sh "$hook"
fi
echo
done < <(find "$repodir" -name 'linuxdeploy-plugin-*.sh' -print0)
if [ "$failed" -eq 0 ]; then
echo -e "\033[1;32mAll $count tests passed with success!\033[0m"
else
echo -e "\033[1;31mError: $failed tests failed.\033[0m"
fi
exit "$failed"