xref: /Universal-ctags/Tmain/unreadable-input.d/run.sh (revision 5cadb9cf5349ea7d728621f957131a253e70e4e0)
1#!/bin/sh
2
3# Copyright: 2020 Masatake YAMATO
4# License: GPL-2
5
6CTAGS=$1
7INPUT0=/tmp/u-ctags/input-0.c
8
9. ../utils.sh
10
11if ! type pidof > /dev/null 2>&1; then
12	# pidof is needed to find auditd.
13	skip "pidof command is not available"
14fi
15
16if ! pidof auditd > /dev/null 2>&1; then
17	# sudo expects auditd is running.
18	skip "auditd is not running"
19fi
20
21if [ $(id -u) = 0 ] && ! sudo -u '#1' $CTAGS --version > /dev/null; then
22	skip "sudo needed in this test case doesn't work expectedly on this platform (execution)"
23fi
24
25mkdir -p ${INPUT0%/*}
26echo "int v0;" > ${INPUT0}
27chmod a-r ${INPUT0}
28
29if [ $(id -u) = 0 ] && sudo -u '#1' cat ${INPUT0} > /dev/null 2>&1; then
30	rm ${INPUT0}
31	skip "sudo needed in this test case doesn't work expectedly on this platform (file reading)"
32elif [ $(id -u) != 0 ] && cat ${INPUT0} > /dev/null 2>&1; then
33	rm ${INPUT0}
34	skip "chmod a-r doesn't work expectedly on this platform"
35fi
36
37
38{
39	echo ${INPUT0}
40	echo input-1.c
41} | {
42	if [ $(id -u) = 0 ]; then
43		# The root can read a file even we did "chmod a-r".
44		sudo -u '#1' $CTAGS --quiet --options=NONE -L - -o -
45	else
46		$CTAGS --quiet --options=NONE -L - -o -
47	fi
48}
49rm ${INPUT0}
50