aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanos Gyerik <janos@kronos>2017-07-07 23:37:28 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-08-02 09:53:07 +0200
commit51bc742e575d45310852962625952f895a5cc24b (patch)
treea54782ee60e6d0261e67c993eadec2bea59768a7
parent1ea693ad819a587a5a70e9b7d4c377e286a36263 (diff)
downloadsonar-scanner-cli-51bc742e575d45310852962625952f895a5cc24b.tar.gz
sonar-scanner-cli-51bc742e575d45310852962625952f895a5cc24b.zip
Add symlink tester for real_path and sonar-scanner
-rwxr-xr-xmisc/symlink-tester.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/misc/symlink-tester.sh b/misc/symlink-tester.sh
new file mode 100755
index 0000000..bab955e
--- /dev/null
+++ b/misc/symlink-tester.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+
+usage() {
+ echo usage: $0 path/to/sonar-scanner
+ exit 1
+}
+
+test -f "$1" && test -x "$1" || usage
+
+scanner=$1
+
+if type mktemp &>/dev/null; then
+ tempdir=$(mktemp -d)
+ tempdir=$(cd "$tempdir"; pwd -P)
+else
+ tempdir=/tmp/"$(basename "$0")-$$"
+ mkdir -p "$tempdir"
+fi
+
+cleanup() {
+ rm -fr "$tempdir"
+}
+
+trap 'cleanup; exit 1' 1 2 3 15
+trap 'cleanup; exit 0' 0
+
+abspath() {
+ (cd "$(dirname "$1")"; echo $PWD/"$(basename "$1")")
+}
+
+verify() {
+ printf '%s -> ' "$1"
+ shift
+ "$@" &>/dev/null && echo ok || echo failed
+}
+
+relpath_to_root() {
+ (
+ cd "$1"
+ relpath=.
+ while test "$PWD" != /; do
+ cd ..
+ relpath=$relpath/..
+ done
+ echo $relpath
+ )
+}
+
+ln -s "$(abspath "$scanner")" "$tempdir"/scanner
+verify 'launch from abs symlink to abs path' "$tempdir"/scanner -h
+
+ln -s "$(relpath_to_root "$tempdir")$(abspath "$scanner")" "$tempdir"/scanner-rel
+verify 'symlink to rel path is valid' test -e "$tempdir"/scanner-rel
+verify 'launch from abs symlink to rel path' "$tempdir"/scanner-rel -h
+
+mkdir "$tempdir/x"
+ln -s ../scanner "$tempdir"/x/scanner
+verify 'symlink to rel symlink is valid' test -f "$tempdir"/x/scanner
+verify 'launch from abs symlink that is rel symlink to abs path' "$tempdir"/x/scanner -h