2003-06-15 16:41:32 +03:00
|
|
|
#include <iostream>
|
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2003-06-15 16:41:32 +03:00
|
|
|
#include "hash.hh"
|
2003-06-20 13:40:25 +03:00
|
|
|
#include "archive.hh"
|
2003-06-16 16:33:38 +03:00
|
|
|
#include "util.hh"
|
2003-07-20 22:29:38 +03:00
|
|
|
#include "normalise.hh"
|
2003-06-16 16:33:38 +03:00
|
|
|
#include "globals.hh"
|
2003-06-15 16:41:32 +03:00
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
void realise(Path nePath)
|
2003-06-15 16:41:32 +03:00
|
|
|
{
|
2003-10-08 18:06:59 +03:00
|
|
|
Nest nest(lvlDebug, format("TEST: realising `%1%'") % nePath);
|
|
|
|
realiseClosure(normaliseNixExpr(nePath));
|
2003-06-16 16:33:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-16 18:59:23 +03:00
|
|
|
struct MySink : DumpSink
|
|
|
|
{
|
|
|
|
virtual void operator () (const unsigned char * data, unsigned int len)
|
|
|
|
{
|
2003-06-18 17:34:43 +03:00
|
|
|
/* Don't use cout, it's slow as hell! */
|
2003-07-21 00:11:43 +03:00
|
|
|
writeFull(STDOUT_FILENO, data, len);
|
2003-06-23 16:27:59 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct MySource : RestoreSource
|
|
|
|
{
|
2003-07-21 00:11:43 +03:00
|
|
|
virtual void operator () (unsigned char * data, unsigned int len)
|
2003-06-23 16:27:59 +03:00
|
|
|
{
|
2003-07-21 00:11:43 +03:00
|
|
|
readFull(STDIN_FILENO, data, len);
|
2003-06-16 18:59:23 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
void runTests()
|
|
|
|
{
|
2003-07-31 16:47:13 +03:00
|
|
|
verbosity = (Verbosity) 100;
|
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
/* Hashing. */
|
|
|
|
string s = "0b0ffd0538622bfe20b92c4aa57254d9";
|
|
|
|
Hash h = parseHash(s);
|
|
|
|
if ((string) h != s) abort();
|
|
|
|
|
|
|
|
try {
|
|
|
|
h = parseHash("blah blah");
|
|
|
|
abort();
|
2003-10-08 18:06:59 +03:00
|
|
|
} catch (Error err) { };
|
2003-06-16 16:33:38 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
h = parseHash("0b0ffd0538622bfe20b92c4aa57254d99");
|
|
|
|
abort();
|
2003-10-08 18:06:59 +03:00
|
|
|
} catch (Error err) { };
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-07-08 22:58:41 +03:00
|
|
|
/* Path canonicalisation. */
|
|
|
|
cout << canonPath("/./../././//") << endl;
|
|
|
|
cout << canonPath("/foo/bar") << endl;
|
|
|
|
cout << canonPath("///foo/////bar//") << endl;
|
|
|
|
cout << canonPath("/././/foo/////bar//.") << endl;
|
|
|
|
cout << canonPath("/foo////bar//..///x/") << endl;
|
|
|
|
cout << canonPath("/foo////bar//..//..//x/y/../z/") << endl;
|
|
|
|
cout << canonPath("/foo/bar/../../../..///") << endl;
|
|
|
|
|
2003-06-16 18:59:23 +03:00
|
|
|
/* Dumping. */
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
MySink sink;
|
|
|
|
dumpPath("scratch", sink);
|
|
|
|
cout << (string) hashPath("scratch") << endl;
|
|
|
|
#endif
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-06-23 16:27:59 +03:00
|
|
|
/* Restoring. */
|
2003-06-23 17:40:49 +03:00
|
|
|
#if 0
|
2003-06-23 16:27:59 +03:00
|
|
|
MySource source;
|
|
|
|
restorePath("outdir", source);
|
|
|
|
cout << (string) hashPath("outdir") << endl;
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
/* Set up the test environment. */
|
|
|
|
|
|
|
|
mkdir("scratch", 0777);
|
2003-07-31 16:47:13 +03:00
|
|
|
mkdir("scratch/db", 0777);
|
2003-06-15 16:41:32 +03:00
|
|
|
|
2003-06-16 16:33:38 +03:00
|
|
|
string testDir = absPath("scratch");
|
|
|
|
cout << testDir << endl;
|
|
|
|
|
2003-06-27 16:55:12 +03:00
|
|
|
nixStore = testDir;
|
2003-06-16 16:33:38 +03:00
|
|
|
nixLogDir = testDir;
|
2003-07-31 16:47:13 +03:00
|
|
|
nixDBPath = testDir + "/db";
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-07-31 16:47:13 +03:00
|
|
|
openDB();
|
2003-06-16 16:33:38 +03:00
|
|
|
initDB();
|
|
|
|
|
|
|
|
/* Expression evaluation. */
|
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
Path builder1fn;
|
|
|
|
builder1fn = addToStore("./test-builder-1.sh");
|
2003-06-27 16:55:12 +03:00
|
|
|
|
2003-07-20 22:29:38 +03:00
|
|
|
ATerm fs1 = ATmake(
|
2003-10-08 18:06:59 +03:00
|
|
|
"Closure([<str>], [(<str>, [])])",
|
2003-10-07 15:27:49 +03:00
|
|
|
builder1fn.c_str(),
|
2003-10-08 18:06:59 +03:00
|
|
|
builder1fn.c_str());
|
|
|
|
Path fs1ne = writeTerm(fs1, "-c");
|
2003-07-15 19:28:54 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
realise(fs1ne);
|
|
|
|
realise(fs1ne);
|
2003-07-15 19:28:54 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
string out1h = hashString("foo"); /* !!! bad */
|
|
|
|
Path out1fn = nixStore + "/" + (string) out1h + "-hello.txt";
|
2003-07-20 22:29:38 +03:00
|
|
|
ATerm fs3 = ATmake(
|
2003-10-08 18:06:59 +03:00
|
|
|
"Derive([<str>], [<str>], <str>, <str>, [], [(\"out\", <str>)])",
|
2003-07-15 19:28:54 +03:00
|
|
|
out1fn.c_str(),
|
2003-10-08 18:06:59 +03:00
|
|
|
fs1ne.c_str(),
|
2003-07-15 19:28:54 +03:00
|
|
|
thisSystem.c_str(),
|
2003-10-08 18:06:59 +03:00
|
|
|
builder1fn.c_str(),
|
2003-07-15 19:28:54 +03:00
|
|
|
out1fn.c_str());
|
|
|
|
debug(printTerm(fs3));
|
2003-10-08 18:06:59 +03:00
|
|
|
Path fs3ne = writeTerm(fs3, "-d");
|
2003-07-15 19:28:54 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
realise(fs3ne);
|
|
|
|
realise(fs3ne);
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2003-07-16 00:24:05 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
Path builder4fn = addToStore("./test-builder-2.sh");
|
2003-07-16 00:24:05 +03:00
|
|
|
|
2003-07-20 22:29:38 +03:00
|
|
|
ATerm fs4 = ATmake(
|
2003-10-08 18:06:59 +03:00
|
|
|
"Closure([<str>], [(<str>, [])])",
|
2003-07-16 00:24:05 +03:00
|
|
|
builder4fn.c_str(),
|
2003-10-08 18:06:59 +03:00
|
|
|
builder4fn.c_str());
|
|
|
|
Path fs4ne = writeTerm(fs4, "-c");
|
2003-07-16 00:24:05 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
realise(fs4ne);
|
2003-07-16 00:24:05 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
string out5h = hashString("bar"); /* !!! bad */
|
|
|
|
Path out5fn = nixStore + "/" + (string) out5h + "-hello2";
|
2003-07-20 22:29:38 +03:00
|
|
|
ATerm fs5 = ATmake(
|
2003-10-08 18:06:59 +03:00
|
|
|
"Derive([<str>], [<str>], <str>, <str>, [], [(\"out\", <str>), (\"builder\", <str>)])",
|
2003-07-16 00:24:05 +03:00
|
|
|
out5fn.c_str(),
|
2003-10-08 18:06:59 +03:00
|
|
|
fs4ne.c_str(),
|
2003-07-16 00:24:05 +03:00
|
|
|
thisSystem.c_str(),
|
2003-10-08 18:06:59 +03:00
|
|
|
builder4fn.c_str(),
|
2003-07-16 00:24:05 +03:00
|
|
|
out5fn.c_str(),
|
2003-10-08 18:06:59 +03:00
|
|
|
builder4fn.c_str());
|
2003-07-16 00:24:05 +03:00
|
|
|
debug(printTerm(fs5));
|
2003-10-08 18:06:59 +03:00
|
|
|
Path fs5ne = writeTerm(fs5, "-d");
|
2003-07-16 00:24:05 +03:00
|
|
|
|
2003-10-08 18:06:59 +03:00
|
|
|
realise(fs5ne);
|
|
|
|
realise(fs5ne);
|
2003-06-16 16:33:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-07 12:25:26 +03:00
|
|
|
void run(Strings args)
|
2003-06-16 16:33:38 +03:00
|
|
|
{
|
2003-07-07 12:25:26 +03:00
|
|
|
runTests();
|
2003-06-15 16:41:32 +03:00
|
|
|
}
|
2003-07-07 12:25:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
string programId = "test";
|