auto import from //depot/cupcake/@135843
diff --git a/amend/tests/001-nop/expected.txt b/amend/tests/001-nop/expected.txt
new file mode 100644
index 0000000..d4a85ce
--- /dev/null
+++ b/amend/tests/001-nop/expected.txt
@@ -0,0 +1 @@
+I am a jelly donut.
diff --git a/amend/tests/001-nop/info.txt b/amend/tests/001-nop/info.txt
new file mode 100644
index 0000000..9942f10
--- /dev/null
+++ b/amend/tests/001-nop/info.txt
@@ -0,0 +1,2 @@
+This is a sample no-op test, which does at least serve to verify that the
+test harness is working.
diff --git a/amend/tests/001-nop/run b/amend/tests/001-nop/run
new file mode 100644
index 0000000..51637c1
--- /dev/null
+++ b/amend/tests/001-nop/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+echo 'I am a jelly donut.'
diff --git a/amend/tests/002-lex-empty/SKIP b/amend/tests/002-lex-empty/SKIP
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/amend/tests/002-lex-empty/SKIP
diff --git a/amend/tests/002-lex-empty/expected.txt b/amend/tests/002-lex-empty/expected.txt
new file mode 100644
index 0000000..822a54c
--- /dev/null
+++ b/amend/tests/002-lex-empty/expected.txt
@@ -0,0 +1 @@
+ EOF
diff --git a/amend/tests/002-lex-empty/info.txt b/amend/tests/002-lex-empty/info.txt
new file mode 100644
index 0000000..090083f
--- /dev/null
+++ b/amend/tests/002-lex-empty/info.txt
@@ -0,0 +1 @@
+Test to make sure that an empty file is accepted properly.
diff --git a/amend/tests/002-lex-empty/input b/amend/tests/002-lex-empty/input
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/amend/tests/002-lex-empty/input
diff --git a/amend/tests/002-lex-empty/run b/amend/tests/002-lex-empty/run
new file mode 100644
index 0000000..35c4a4f
--- /dev/null
+++ b/amend/tests/002-lex-empty/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+amend --debug-lex input
diff --git a/amend/tests/003-lex-command/expected.txt b/amend/tests/003-lex-command/expected.txt
new file mode 100644
index 0000000..e40db0c
--- /dev/null
+++ b/amend/tests/003-lex-command/expected.txt
@@ -0,0 +1,13 @@
+ IDENTIFIER<this_identifier_is_not_assert> EOL
+ IDENTIFIER<NEITHER_IS_THIS_123> EOL
+ IDENTIFIER<but_the_next_one_is> EOL
+ IDENTIFIER<assert> EOL
+ IDENTIFIER<next_one_is_not_an_identifier> EOL
+line 6: unexpected character at '1'
+ EOF
+line 1: unexpected character at '"'
+ EOF
+line 1: unexpected character at '='
+ EOF
+line 1: unexpected character at '9'
+ EOF
diff --git a/amend/tests/003-lex-command/info.txt b/amend/tests/003-lex-command/info.txt
new file mode 100644
index 0000000..9296648
--- /dev/null
+++ b/amend/tests/003-lex-command/info.txt
@@ -0,0 +1 @@
+Test to make sure that simple command names are tokenized properly.
diff --git a/amend/tests/003-lex-command/input b/amend/tests/003-lex-command/input
new file mode 100644
index 0000000..b9ef231
--- /dev/null
+++ b/amend/tests/003-lex-command/input
@@ -0,0 +1,6 @@
+this_identifier_is_not_assert
+NEITHER_IS_THIS_123
+but_the_next_one_is
+assert
+next_one_is_not_an_identifier
+12not_an_identifier
diff --git a/amend/tests/003-lex-command/input2 b/amend/tests/003-lex-command/input2
new file mode 100644
index 0000000..eb5daf7
--- /dev/null
+++ b/amend/tests/003-lex-command/input2
@@ -0,0 +1 @@
+"quoted"
diff --git a/amend/tests/003-lex-command/input3 b/amend/tests/003-lex-command/input3
new file mode 100644
index 0000000..f1c8738
--- /dev/null
+++ b/amend/tests/003-lex-command/input3
@@ -0,0 +1 @@
+==
diff --git a/amend/tests/003-lex-command/input4 b/amend/tests/003-lex-command/input4
new file mode 100644
index 0000000..3ad5abd
--- /dev/null
+++ b/amend/tests/003-lex-command/input4
@@ -0,0 +1 @@
+99
diff --git a/amend/tests/003-lex-command/run b/amend/tests/003-lex-command/run
new file mode 100644
index 0000000..2e21fab
--- /dev/null
+++ b/amend/tests/003-lex-command/run
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+amend --debug-lex input
+amend --debug-lex input2
+amend --debug-lex input3
+amend --debug-lex input4
diff --git a/amend/tests/004-lex-comment/expected.txt b/amend/tests/004-lex-comment/expected.txt
new file mode 100644
index 0000000..a728a5e
--- /dev/null
+++ b/amend/tests/004-lex-comment/expected.txt
@@ -0,0 +1,5 @@
+ IDENTIFIER<comment_on_this_line> EOL
+ IDENTIFIER<none_on_this_one> EOL
+ EOL
+ EOL
+ EOF
diff --git a/amend/tests/004-lex-comment/info.txt b/amend/tests/004-lex-comment/info.txt
new file mode 100644
index 0000000..0691248
--- /dev/null
+++ b/amend/tests/004-lex-comment/info.txt
@@ -0,0 +1 @@
+Test to make sure that comments are stripped out.
diff --git a/amend/tests/004-lex-comment/input b/amend/tests/004-lex-comment/input
new file mode 100644
index 0000000..6736c95
--- /dev/null
+++ b/amend/tests/004-lex-comment/input
@@ -0,0 +1,4 @@
+comment_on_this_line # this is a "comment" (with / a bunch) # \\ of stuff \
+none_on_this_one
+# beginning of line
+                         # preceded by whitespace
diff --git a/amend/tests/004-lex-comment/run b/amend/tests/004-lex-comment/run
new file mode 100644
index 0000000..35c4a4f
--- /dev/null
+++ b/amend/tests/004-lex-comment/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+amend --debug-lex input
diff --git a/amend/tests/005-lex-quoted-string/expected.txt b/amend/tests/005-lex-quoted-string/expected.txt
new file mode 100644
index 0000000..9bb5ac4
--- /dev/null
+++ b/amend/tests/005-lex-quoted-string/expected.txt
@@ -0,0 +1,13 @@
+ IDENTIFIER<test> WORD<string> EOL
+ IDENTIFIER<test> WORD<string with spaces> EOL
+ IDENTIFIER<test> WORD<string with "escaped" quotes> EOL
+ IDENTIFIER<test> WORD<string with \escaped\ backslashes> EOL
+ IDENTIFIER<test> WORD<string with # a comment character> EOL
+ EOF
+ EOL
+ IDENTIFIER<test1>line 2: unterminated string at '
+'
+ ??? <0>
+ EOL
+ IDENTIFIER<test1>line 2: illegal escape at '\n'
+ ??? <0>
diff --git a/amend/tests/005-lex-quoted-string/info.txt b/amend/tests/005-lex-quoted-string/info.txt
new file mode 100644
index 0000000..be458bd
--- /dev/null
+++ b/amend/tests/005-lex-quoted-string/info.txt
@@ -0,0 +1 @@
+Test to make sure that quoted strings are tokenized properly.
diff --git a/amend/tests/005-lex-quoted-string/input b/amend/tests/005-lex-quoted-string/input
new file mode 100644
index 0000000..2b34bbc
--- /dev/null
+++ b/amend/tests/005-lex-quoted-string/input
@@ -0,0 +1,5 @@
+test "string"
+test "string with spaces"
+test "string with \"escaped\" quotes"
+test "string with \\escaped\\ backslashes"
+test "string with # a comment character"
diff --git a/amend/tests/005-lex-quoted-string/input2 b/amend/tests/005-lex-quoted-string/input2
new file mode 100644
index 0000000..09e6689
--- /dev/null
+++ b/amend/tests/005-lex-quoted-string/input2
@@ -0,0 +1,2 @@
+# This should fail
+test1 "unterminated string
diff --git a/amend/tests/005-lex-quoted-string/input3 b/amend/tests/005-lex-quoted-string/input3
new file mode 100644
index 0000000..02f3f85
--- /dev/null
+++ b/amend/tests/005-lex-quoted-string/input3
@@ -0,0 +1,2 @@
+# This should fail
+test1 "string with illegal escape \n in the middle"
diff --git a/amend/tests/005-lex-quoted-string/run b/amend/tests/005-lex-quoted-string/run
new file mode 100644
index 0000000..7b1292a
--- /dev/null
+++ b/amend/tests/005-lex-quoted-string/run
@@ -0,0 +1,19 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+amend --debug-lex input
+amend --debug-lex input2
+amend --debug-lex input3
diff --git a/amend/tests/006-lex-words/SKIP b/amend/tests/006-lex-words/SKIP
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/amend/tests/006-lex-words/SKIP
diff --git a/amend/tests/006-lex-words/expected.txt b/amend/tests/006-lex-words/expected.txt
new file mode 100644
index 0000000..a78a0b1
--- /dev/null
+++ b/amend/tests/006-lex-words/expected.txt
@@ -0,0 +1,6 @@
+ IDENTIFIER<test> WORD<this> WORD<has> WORD<a> WORD<bunch> WORD<of> WORD<BARE> WORD<ALPHA> WORD<WORDS> EOL
+ IDENTIFIER<test> WORD<12> WORD<this> WORD<has(some> WORD<)> WORD<ALPHANUMER1C> WORD<and> WORD<\\> WORD<whatever> WORD<characters> EOL
+ IDENTIFIER<test> WORD<this> WORD<has> WORD<mixed> WORD<bare> WORD<and quoted> WORD<words> EOL
+ IDENTIFIER<test> WORD<what> WORD<about> WORD<quotesin the middle?> EOL
+ IDENTIFIER<test> WORD<"""shouldn't> WORD<be> WORD<a> WORD<quoted> WORD<string> EOL
+ EOF
diff --git a/amend/tests/006-lex-words/info.txt b/amend/tests/006-lex-words/info.txt
new file mode 100644
index 0000000..dd37016
--- /dev/null
+++ b/amend/tests/006-lex-words/info.txt
@@ -0,0 +1 @@
+Test to make sure that argument words are tokenized properly.
diff --git a/amend/tests/006-lex-words/input b/amend/tests/006-lex-words/input
new file mode 100644
index 0000000..a4de638
--- /dev/null
+++ b/amend/tests/006-lex-words/input
@@ -0,0 +1,5 @@
+test this has a bunch of BARE ALPHA WORDS
+test 12 this has(some ) ALPHANUMER1C and \\ whatever characters
+test this has mixed bare "and quoted" words
+test what about quotes"in the middle?"
+test \"\"\"shouldn't be a quoted string
diff --git a/amend/tests/006-lex-words/input2 b/amend/tests/006-lex-words/input2
new file mode 100644
index 0000000..09e6689
--- /dev/null
+++ b/amend/tests/006-lex-words/input2
@@ -0,0 +1,2 @@
+# This should fail
+test1 "unterminated string
diff --git a/amend/tests/006-lex-words/input3 b/amend/tests/006-lex-words/input3
new file mode 100644
index 0000000..02f3f85
--- /dev/null
+++ b/amend/tests/006-lex-words/input3
@@ -0,0 +1,2 @@
+# This should fail
+test1 "string with illegal escape \n in the middle"
diff --git a/amend/tests/006-lex-words/run b/amend/tests/006-lex-words/run
new file mode 100644
index 0000000..35c4a4f
--- /dev/null
+++ b/amend/tests/006-lex-words/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+amend --debug-lex input
diff --git a/amend/tests/007-lex-real-script/expected.txt b/amend/tests/007-lex-real-script/expected.txt
new file mode 100644
index 0000000..012f62c
--- /dev/null
+++ b/amend/tests/007-lex-real-script/expected.txt
@@ -0,0 +1,11 @@
+ IDENTIFIER<assert> IDENTIFIER<hash_dir> ( STRING<SYS:> ) == STRING<112345oldhashvalue1234123> EOL
+ IDENTIFIER<mark> WORD<SYS:> WORD<dirty> EOL
+ IDENTIFIER<copy_dir> WORD<PKG:android-files> WORD<SYS:> EOL
+ IDENTIFIER<assert> IDENTIFIER<hash_dir> ( STRING<SYS:> ) == STRING<667890newhashvalue6678909> EOL
+ IDENTIFIER<mark> WORD<SYS:> WORD<clean> EOL
+ IDENTIFIER<done> EOL
+ IDENTIFIER<assert> IDENTIFIER<hash_dir> ( STRING<SYS:> , STRING<blah> ) == STRING<112345oldhashvalue1234123> EOL
+ IDENTIFIER<assert> STRING<true> == STRING<false> EOL
+ IDENTIFIER<assert> IDENTIFIER<one> ( STRING<abc> , IDENTIFIER<two> ( STRING<def> ) ) == STRING<five> EOL
+ IDENTIFIER<assert> IDENTIFIER<hash_dir> ( STRING<SYS:> ) == STRING<667890newhashvalue6678909> || IDENTIFIER<hash_dir> ( STRING<SYS:> ) == STRING<667890newhashvalue6678909> EOL
+ EOF
diff --git a/amend/tests/007-lex-real-script/info.txt b/amend/tests/007-lex-real-script/info.txt
new file mode 100644
index 0000000..5e321f5
--- /dev/null
+++ b/amend/tests/007-lex-real-script/info.txt
@@ -0,0 +1 @@
+An input script similar to one that will actually be used in practice.
diff --git a/amend/tests/007-lex-real-script/input b/amend/tests/007-lex-real-script/input
new file mode 100644
index 0000000..f3f1fd9
--- /dev/null
+++ b/amend/tests/007-lex-real-script/input
@@ -0,0 +1,10 @@
+assert hash_dir("SYS:") == "112345oldhashvalue1234123"
+mark SYS: dirty
+copy_dir "PKG:android-files" SYS:
+assert hash_dir("SYS:") == "667890newhashvalue6678909"
+mark SYS: clean
+done
+assert hash_dir("SYS:", "blah") == "112345oldhashvalue1234123"
+assert "true" == "false"
+assert one("abc", two("def")) == "five"
+assert hash_dir("SYS:") == "667890newhashvalue6678909" || hash_dir("SYS:") == "667890newhashvalue6678909"
diff --git a/amend/tests/007-lex-real-script/run b/amend/tests/007-lex-real-script/run
new file mode 100644
index 0000000..35c4a4f
--- /dev/null
+++ b/amend/tests/007-lex-real-script/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+amend --debug-lex input
diff --git a/amend/tests/008-parse-real-script/expected.txt b/amend/tests/008-parse-real-script/expected.txt
new file mode 100644
index 0000000..dabf6d4
--- /dev/null
+++ b/amend/tests/008-parse-real-script/expected.txt
@@ -0,0 +1,74 @@
+command "assert" {
+    STRING EQ {
+        FUNCTION hash_dir (
+            "SYS:"
+        )
+        "112345oldhashvalue1234123"
+    }
+}
+command "mark" {
+    "SYS:"
+    "dirty"
+}
+command "copy_dir" {
+    "PKG:android-files"
+    "SYS:"
+}
+command "assert" {
+    STRING EQ {
+        FUNCTION hash_dir (
+            "SYS:"
+        )
+        "667890newhashvalue6678909"
+    }
+}
+command "mark" {
+    "SYS:"
+    "clean"
+}
+command "done" {
+}
+command "assert" {
+    STRING EQ {
+        FUNCTION hash_dir (
+            "SYS:"
+            "blah"
+        )
+        "112345oldhashvalue1234123"
+    }
+}
+command "assert" {
+    STRING EQ {
+        "true"
+        "false"
+    }
+}
+command "assert" {
+    STRING NE {
+        FUNCTION matches (
+            FUNCTION hash_dir (
+                "SYS:"
+            )
+            "667890newhashvalue6678909"
+            "999999newhashvalue6678909"
+        )
+        ""
+    }
+}
+command "assert" {
+    BOOLEAN OR {
+        STRING EQ {
+            FUNCTION hash_dir (
+                "SYS:"
+            )
+            "667890newhashvalue6678909"
+        }
+        STRING EQ {
+            FUNCTION hash_dir (
+                "SYS:"
+            )
+            "999999newhashvalue6678909"
+        }
+    }
+}
+amend: Parse successful.
diff --git a/amend/tests/008-parse-real-script/info.txt b/amend/tests/008-parse-real-script/info.txt
new file mode 100644
index 0000000..5e321f5
--- /dev/null
+++ b/amend/tests/008-parse-real-script/info.txt
@@ -0,0 +1 @@
+An input script similar to one that will actually be used in practice.
diff --git a/amend/tests/008-parse-real-script/input b/amend/tests/008-parse-real-script/input
new file mode 100644
index 0000000..b073306
--- /dev/null
+++ b/amend/tests/008-parse-real-script/input
@@ -0,0 +1,10 @@
+assert hash_dir("SYS:") == "112345oldhashvalue1234123"
+mark SYS: dirty
+copy_dir "PKG:android-files" SYS:
+assert hash_dir("SYS:") == "667890newhashvalue6678909"
+mark SYS: clean
+done
+assert hash_dir("SYS:", "blah") == "112345oldhashvalue1234123"
+assert "true" == "false"
+assert matches(hash_dir("SYS:"), "667890newhashvalue6678909", "999999newhashvalue6678909") != ""
+assert hash_dir("SYS:") == "667890newhashvalue6678909" || hash_dir("SYS:") == "999999newhashvalue6678909"
diff --git a/amend/tests/008-parse-real-script/run b/amend/tests/008-parse-real-script/run
new file mode 100644
index 0000000..9544e1b
--- /dev/null
+++ b/amend/tests/008-parse-real-script/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+amend --debug-ast input
diff --git a/amend/tests/XXX-long-token/SKIP b/amend/tests/XXX-long-token/SKIP
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/amend/tests/XXX-long-token/SKIP
diff --git a/amend/tests/XXX-stack-overflow/SKIP b/amend/tests/XXX-stack-overflow/SKIP
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/amend/tests/XXX-stack-overflow/SKIP
diff --git a/amend/tests/one-test b/amend/tests/one-test
new file mode 100755
index 0000000..9cebd3f
--- /dev/null
+++ b/amend/tests/one-test
@@ -0,0 +1,150 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Set up prog to be the path of this script, including following symlinks,
+# and set up progdir to be the fully-qualified pathname of its directory.
+prog="$0"
+while [ -h "${prog}" ]; do
+    newProg=`/bin/ls -ld "${prog}"`
+    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
+    if expr "x${newProg}" : 'x/' >/dev/null; then
+        prog="${newProg}"
+    else
+        progdir=`dirname "${prog}"`
+        prog="${progdir}/${newProg}"
+    fi
+done
+oldwd=`pwd`
+progdir=`dirname "${prog}"`
+cd "${progdir}"
+progdir=`pwd`
+prog="${progdir}"/`basename "${prog}"`
+
+info="info.txt"
+run="run"
+expected="expected.txt"
+output="out.txt"
+skip="SKIP"
+
+dev_mode="no"
+if [ "x$1" = "x--dev" ]; then
+    dev_mode="yes"
+    shift
+fi
+
+update_mode="no"
+if [ "x$1" = "x--update" ]; then
+    update_mode="yes"
+    shift
+fi
+
+usage="no"
+if [ "x$1" = "x--help" ]; then
+    usage="yes"
+else
+    if [ "x$1" = "x" ]; then
+        testdir=`basename "$oldwd"`
+    else
+        testdir="$1"
+    fi
+
+    if [ '!' -d "$testdir" ]; then
+        td2=`echo ${testdir}-*`
+        if [ '!' -d "$td2" ]; then
+            echo "${testdir}: no such test directory" 1>&2
+            usage="yes"
+        fi
+        testdir="$td2"
+    fi
+fi
+
+if [ "$usage" = "yes" ]; then
+    prog=`basename $prog`
+    (
+        echo "usage:"
+        echo "  $prog --help             Print this message."
+        echo "  $prog testname           Run test normally."
+        echo "  $prog --dev testname     Development mode (dump to stdout)."
+        echo "  $prog --update testname  Update mode (replace expected.txt)."
+        echo "  Omitting the test name uses the current directory as the test."
+    ) 1>&2
+    exit 1
+fi
+
+td_info="$testdir"/"$info"
+td_run="$testdir"/"$run"
+td_expected="$testdir"/"$expected"
+td_skip="$testdir"/"$skip"
+
+if [ -r "$td_skip" ]; then
+    exit 2
+fi
+
+tmpdir=/tmp/test-$$
+
+if [ '!' '(' -r "$td_info" -a -r "$td_run" -a -r "$td_expected" ')' ]; then
+    echo "${testdir}: missing files" 1>&2
+    exit 1
+fi
+
+# copy the test to a temp dir and run it
+
+echo "${testdir}: running..." 1>&2
+
+rm -rf "$tmpdir"
+cp -Rp "$testdir" "$tmpdir"
+cd "$tmpdir"
+chmod 755 "$run"
+
+#PATH="${progdir}/../build/bin:${PATH}"
+
+good="no"
+if [ "$dev_mode" = "yes" ]; then
+    "./$run" 2>&1
+    echo "exit status: $?" 1>&2
+    good="yes"
+elif [ "$update_mode" = "yes" ]; then
+    "./$run" >"${progdir}/$td_expected" 2>&1
+    good="yes"
+else
+    "./$run" >"$output" 2>&1
+    cmp -s "$expected" "$output"
+    if [ "$?" = "0" ]; then
+        # output == expected
+        good="yes"
+        echo "$testdir"': succeeded!' 1>&2
+    fi
+fi
+
+if [ "$good" = "yes" ]; then
+    cd "$oldwd"
+    rm -rf "$tmpdir"
+    exit 0
+fi
+
+(
+    echo "${testdir}: FAILED!"
+    echo ' '
+    echo '#################### info'
+    cat "$info" | sed 's/^/# /g'
+    echo '#################### diffs'
+    diff -u "$expected" "$output"
+    echo '####################'
+    echo ' '
+    echo "files left in $tmpdir"
+) 1>&2
+
+exit 1
diff --git a/amend/tests/run-all-tests b/amend/tests/run-all-tests
new file mode 100755
index 0000000..c696bbd
--- /dev/null
+++ b/amend/tests/run-all-tests
@@ -0,0 +1,69 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Set up prog to be the path of this script, including following symlinks,
+# and set up progdir to be the fully-qualified pathname of its directory.
+prog="$0"
+while [ -h "${prog}" ]; do
+    newProg=`/bin/ls -ld "${prog}"`
+    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
+    if expr "x${newProg}" : 'x/' >/dev/null; then
+        prog="${newProg}"
+    else
+        progdir=`dirname "${prog}"`
+        prog="${progdir}/${newProg}"
+    fi
+done
+oldwd=`pwd`
+progdir=`dirname "${prog}"`
+cd "${progdir}"
+progdir=`pwd`
+prog="${progdir}"/`basename "${prog}"`
+
+passed=0
+skipped=0
+skipNames=""
+failed=0
+failNames=""
+
+for i in *; do
+    if [ -d "$i" -a -r "$i" ]; then
+        ./one-test "$i"
+        status=$?
+        if [ "$status" = "0" ]; then
+            ((passed += 1))
+        elif [ "$status" = "2" ]; then
+            ((skipped += 1))
+            skipNames="$skipNames $i"
+        else
+            ((failed += 1))
+            failNames="$failNames $i"
+        fi
+    fi
+done
+
+echo "passed:  $passed test(s)"
+echo "skipped: $skipped test(s)"
+
+for i in $skipNames; do
+    echo "skipped: $i"
+done
+
+echo "failed:  $failed test(s)"
+    
+for i in $failNames; do
+    echo "failed: $i"
+done