aboutsummaryrefslogtreecommitdiff
path: root/src/test.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-06-16 13:33:38 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-06-16 13:33:38 +0000
commit822794001cb4260b8c04a7bd2d50d890edae709a (patch)
treec4c3a86f638422c8d756752050ebcbb45eba2ee7 /src/test.cc
parentb9f09b3268bf0c3d9ecd512dd3a0aa1247550cc2 (diff)
* Started implementing the new evaluation model.
* Lots of refactorings. * Unit tests.
Diffstat (limited to 'src/test.cc')
-rw-r--r--src/test.cc82
1 files changed, 74 insertions, 8 deletions
diff --git a/src/test.cc b/src/test.cc
index cce226ba9..79468182e 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -1,16 +1,82 @@
#include <iostream>
+#include <sys/stat.h>
+#include <sys/types.h>
+
#include "hash.hh"
+#include "util.hh"
+#include "eval.hh"
+#include "values.hh"
+#include "globals.hh"
-int main(int argc, char * * argv)
+
+void evalTest(Expr e)
{
- Hash h = hashFile("/etc/passwd");
-
- cout << (string) h << endl;
+ EvalResult r = evalValue(e);
+
+ char * s = ATwriteToString(r.e);
+ cout << (string) r.h << ": " << s << endl;
+}
+
+
+void runTests()
+{
+ /* Hashing. */
+ string s = "0b0ffd0538622bfe20b92c4aa57254d9";
+ Hash h = parseHash(s);
+ if ((string) h != s) abort();
+
+ try {
+ h = parseHash("blah blah");
+ abort();
+ } catch (BadRefError err) { };
+
+ try {
+ h = parseHash("0b0ffd0538622bfe20b92c4aa57254d99");
+ abort();
+ } catch (BadRefError err) { };
+
+
+ /* Set up the test environment. */
+
+ mkdir("scratch", 0777);
- h = parseHash("0b0ffd0538622bfe20b92c4aa57254d9");
-
- cout << (string) h << endl;
+ string testDir = absPath("scratch");
+ cout << testDir << endl;
+
+ nixValues = testDir;
+ nixLogDir = testDir;
+ nixDB = testDir + "/db";
+
+ initDB();
+
+ /* Expression evaluation. */
+
+ evalTest(ATmake("Str(\"Hello World\")"));
+ evalTest(ATmake("Bool(True)"));
+ evalTest(ATmake("Bool(False)"));
+
+ Hash builder1 = addValue("./test-builder-1.sh");
+
+ evalTest(ATmake("Exec(Str(<str>), External(<str>), [])",
+ thisSystem.c_str(), ((string) builder1).c_str()));
+
+ Hash builder2 = addValue("./test-builder-2.sh");
+
+ evalTest(ATmake("Exec(Str(<str>), External(<str>), [])",
+ thisSystem.c_str(), ((string) builder2).c_str()));
+}
+
+
+int main(int argc, char * * argv)
+{
+ ATerm bottomOfStack;
+ ATinit(argc, argv, &bottomOfStack);
- return 0;
+ try {
+ runTests();
+ } catch (exception & e) {
+ cerr << "error: " << e.what() << endl;
+ return 1;
+ }
}