pidof.test 879 B

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