blob: 79468182ea3c4f5087d77e2d9b083cc70f0c6943 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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"
void evalTest(Expr e)
{
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);
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);
try {
runTests();
} catch (exception & e) {
cerr << "error: " << e.what() << endl;
return 1;
}
}
|