veyron/examples/todos: add simple test.sh

Change-Id: Ibf7684002a93e1979146bb6431ae0dc14cfb5dec
diff --git a/examples/mdb/test.sh b/examples/mdb/test.sh
index 656560f..ed8d790 100755
--- a/examples/mdb/test.sh
+++ b/examples/mdb/test.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# Tests the mdb example.
+# Tests this example.
 #
 # Builds binaries, starts up services, waits a few seconds, then checks that the
 # store browser responds with valid data.
@@ -41,7 +41,7 @@
 
   curl 2>/dev/null "${URL}" -o "${FILE}" || fail "line ${LINENO}: failed to fetch ${URL}"
 
-  if grep -q moviesbox "${FILE}"; then
+  if grep -q "moviesbox" "${FILE}"; then
     pass
   else
     cat ${FILE}
diff --git a/examples/todos/Makefile b/examples/todos/Makefile
index 76f0c00..95fd02b 100644
--- a/examples/todos/Makefile
+++ b/examples/todos/Makefile
@@ -11,7 +11,7 @@
 	(cd todos_appd && npm install)
 
 buildgo:
-	${VEYRON_ROOT}/veyron/scripts/build/go install {veyron,veyron2}/...
+	${VEYRON_ROOT}/veyron/scripts/build/go install veyron/examples/todos/... veyron/services/mounttable/mounttabled veyron/services/store/stored veyron/tools/identity
 
 buildapp: node_modules
 	browserify -d todos_appd/browser/*.js -p [minifyify --map bundle.js.map --output ${BUNDLE_JS}.map] -o ${BUNDLE_JS}
@@ -21,6 +21,9 @@
 run: build
 	./run.sh
 
+test:
+	./test.sh
+
 runapp: buildapp
 	(cd todos_appd && npm start)
 
diff --git a/examples/todos/run.sh b/examples/todos/run.sh
index c08ae3b..a145ff0 100755
--- a/examples/todos/run.sh
+++ b/examples/todos/run.sh
@@ -9,8 +9,8 @@
 trap onexit INT TERM EXIT
 
 onexit() {
-  exec 2> /dev/null
-  kill $(jobs -pr)
+  exec 2>/dev/null
+  kill $(jobs -p)
   rm -rf "${ID_FILE}"
 }
 
diff --git a/examples/todos/test.sh b/examples/todos/test.sh
new file mode 100755
index 0000000..7ae1fa4
--- /dev/null
+++ b/examples/todos/test.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+# Tests this example.
+#
+# Builds binaries, starts up services, waits a few seconds, then checks that the
+# store browser responds with valid data.
+
+set -e
+set -u
+
+readonly THIS_SCRIPT="$0"
+readonly WORK_DIR=$(mktemp -d)
+
+trap onexit INT TERM EXIT
+
+onexit() {
+  exec 2>/dev/null
+  kill $(jobs -p)
+  rm -rf "${WORK_DIR}"
+}
+
+fail() {
+  [[ $# -gt 0 ]] && echo "${THIS_SCRIPT} $*"
+  echo FAIL
+  exit 1
+}
+
+pass() {
+  echo PASS
+  exit 0
+}
+
+main() {
+  make build || fail "line ${LINENO}: failed to build"
+  ./run.sh >/dev/null 2>&1 &
+
+  sleep 5  # Wait for services to warm up.
+
+  URL="http://localhost:5000"
+  FILE="${WORK_DIR}/index.html"
+
+  curl 2>/dev/null "${URL}" -o "${FILE}" || fail "line ${LINENO}: failed to fetch ${URL}"
+
+  if grep -q "/lists" "${FILE}"; then
+    pass
+  else
+    cat ${FILE}
+    fail "line ${LINENO}: fetched page does not meet expectations"
+  fi
+}
+
+main "$@"