Home | History | Annotate | Download | only in wiki
      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 
      6 set -e
      7 
      8 if ! which patch > /dev/null; then
      9 	echo "Skipping test; patch command not found."
     10 	exit 0
     11 fi
     12 
     13 wiki_pid=
     14 cleanup() {
     15 	kill $wiki_pid
     16 	rm -f test_*.out Test.txt final-test.go final-test.bin final-test-port.txt a.out get.bin
     17 }
     18 trap cleanup 0 INT
     19 
     20 rm -f get.bin final-test.bin a.out
     21 
     22 # If called with -all, check that all code snippets compile.
     23 if [ "$1" == "-all" ]; then
     24 	for fn in *.go; do
     25 		go build -o a.out $fn
     26 	done
     27 fi
     28 
     29 go build -o get.bin get.go
     30 cp final.go final-test.go
     31 patch final-test.go final-test.patch > /dev/null
     32 go build -o final-test.bin final-test.go
     33 ./final-test.bin &
     34 wiki_pid=$!
     35 
     36 l=0
     37 while [ ! -f ./final-test-port.txt ]
     38 do
     39 	l=$(($l+1))
     40 	if [ "$l" -gt 5 ]
     41 	then
     42 		echo "port not available within 5 seconds"
     43 		exit 1
     44 		break
     45 	fi
     46 	sleep 1
     47 done
     48 
     49 addr=$(cat final-test-port.txt)
     50 ./get.bin http://$addr/edit/Test > test_edit.out
     51 diff -u test_edit.out test_edit.good
     52 ./get.bin -post=body=some%20content http://$addr/save/Test > test_save.out
     53 diff -u test_save.out test_view.good # should be the same as viewing
     54 diff -u Test.txt test_Test.txt.good
     55 ./get.bin http://$addr/view/Test > test_view.out
     56 diff -u test_view.out test_view.good
     57 
     58 echo PASS
     59