• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7#
8# pidof (unlike killall) doesn't match argv[1] unless you supply -x.
9#
10
11echo -e "#!$(which sh)\nread i < /proc/self/fd/1" > pidof-$$.test
12chmod a+x pidof-$$.test
13cp pidof-$$.test toybox.pidof-$$.test.script
14(./pidof-$$.test & echo $! > pid.txt)
15pid=$(cat pid.txt)
16testcmd "short argv[1]" "pidof-$$.test" "" "" ""
17testcmd "short argv[1] -x" "-x pidof-$$.test" "$pid\n" "" ""
18kill $pid
19
20(./toybox.pidof-$$.test.script & echo $! > pid.txt)
21pid=$(cat pid.txt)
22testcmd "long argv[1]" "toybox.pidof-$$.test.script" "" "" ""
23testcmd "long argv[1] -x" "-x toybox.pidof-$$.test.script" "$pid\n" "" ""
24kill $pid
25
26rm -f toybox.pidof-$$.test.script pidof-$$.test pid.txt
27
28# pidof (unlike killall) will match itself.
29testcmd "pidof pidof" "pidof > /dev/null && echo found" "found\n" "" ""
30