diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-30 16:07:09 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-30 16:07:09 -0400 |
commit | 7f55a9a3bbec144718a3df24d30fc0a98534667d (patch) | |
tree | a31c8cb8c169c9f70c5c93759d578b15a7ebc489 | |
parent | e69de4dc0b8544c0e72703f2f13a541b23592d91 (diff) | |
download | spmc-7f55a9a3bbec144718a3df24d30fc0a98534667d.tar.gz |
Add quick shell() test
-rw-r--r-- | tests/test_shell_shell.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_shell_shell.c b/tests/test_shell_shell.c new file mode 100644 index 0000000..ade16a7 --- /dev/null +++ b/tests/test_shell_shell.c @@ -0,0 +1,24 @@ +#include "spm.h" +#include "shell.h" +#include "framework.h" + +const char *testFmt = "returned '%s', expected '%s'\n"; +struct TestCase testCase[] = { + {.arg[0].unsigned_integer = SHELL_OUTPUT|SHELL_BENCHMARK, .arg[1].sptr = "echo hello; sleep 3", .arg[2].floating = 3, .arg[3].sptr = "hello"}, +}; +size_t numCases = sizeof(testCase) / sizeof(struct TestCase); + +int main(int argc, char *argv[]) { + for (size_t i = 0; i < numCases; i++) { + char elapsed[100] = {0,}; + Process *result = NULL; + + shell(&result, testCase[i].arg[0].unsigned_integer, testCase[i].arg[1].sptr); + sprintf(elapsed, "%0.8lf", result->time_elapsed); + strip(result->output); + + myassert(strcmp(result->output, testCase[i].arg[3].sptr) == 0, testFmt, result->output, testCase[i].arg[3].sptr); + myassert(fabs(result->time_elapsed) >= fabs((double)testCase[i].arg[2].floating), testFmt, elapsed, "non-zero elapsed time"); + } + return 0; +}
\ No newline at end of file |