test.bash 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env bash
  2. # Copyright 2010 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. set -e
  6. if ! which patch > /dev/null; then
  7. echo "Skipping test; patch command not found."
  8. exit 0
  9. fi
  10. wiki_pid=
  11. cleanup() {
  12. kill $wiki_pid
  13. rm -f test_*.out Test.txt final-test.go final-test.bin final-test-port.txt a.out get.bin
  14. }
  15. trap cleanup 0 INT
  16. rm -f get.bin final-test.bin a.out
  17. # If called with -all, check that all code snippets compile.
  18. if [ "$1" = "-all" ]; then
  19. for fn in *.go; do
  20. go build -o a.out $fn
  21. done
  22. fi
  23. go build -o get.bin get.go
  24. cp final.go final-test.go
  25. patch final-test.go final-test.patch > /dev/null
  26. go build -o final-test.bin final-test.go
  27. ./final-test.bin &
  28. wiki_pid=$!
  29. l=0
  30. while [ ! -f ./final-test-port.txt ]
  31. do
  32. l=$(($l+1))
  33. if [ "$l" -gt 5 ]
  34. then
  35. echo "port not available within 5 seconds"
  36. exit 1
  37. break
  38. fi
  39. sleep 1
  40. done
  41. addr=$(cat final-test-port.txt)
  42. ./get.bin http://$addr/edit/Test > test_edit.out
  43. diff -u test_edit.out test_edit.good
  44. ./get.bin -post=body=some%20content http://$addr/save/Test > test_save.out
  45. diff -u test_save.out test_view.good # should be the same as viewing
  46. diff -u Test.txt test_Test.txt.good
  47. ./get.bin http://$addr/view/Test > test_view.out
  48. diff -u test_view.out test_view.good
  49. echo PASS