diff options
Diffstat (limited to 'src/test.cc')
-rw-r--r-- | src/test.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/test.cc b/src/test.cc index 2eab91d43bb4..c8e3292e3aee 100644 --- a/src/test.cc +++ b/src/test.cc @@ -23,7 +23,21 @@ struct MySink : DumpSink virtual void operator () (const unsigned char * data, unsigned int len) { /* Don't use cout, it's slow as hell! */ - write(STDOUT_FILENO, (char *) data, len); + if (write(STDOUT_FILENO, (char *) data, len) != (ssize_t) len) + throw SysError("writing to stdout"); + } +}; + + +struct MySource : RestoreSource +{ + virtual void operator () (const unsigned char * data, unsigned int len) + { + ssize_t res = read(STDIN_FILENO, (char *) data, len); + if (res == -1) + throw SysError("reading from stdin"); + if (res != (ssize_t) len) + throw Error("not enough data available on stdin"); } }; @@ -53,6 +67,14 @@ void runTests() cout << (string) hashPath("scratch") << endl; #endif + /* Restoring. */ +#if 1 + MySource source; + restorePath("outdir", source); + cout << (string) hashPath("outdir") << endl; + return; +#endif + /* Set up the test environment. */ mkdir("scratch", 0777); |