diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2020-03-30 16:22:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-30 16:22:24 -0400 |
commit | 70b7285967f9d5e6f8a8c4624b69ebf1adedca76 (patch) | |
tree | a31c8cb8c169c9f70c5c93759d578b15a7ebc489 /tests/test_shell_shell.c | |
parent | 81a87ac139e26b1746c0370a4453bf5938e8eba9 (diff) | |
parent | 7f55a9a3bbec144718a3df24d30fc0a98534667d (diff) | |
download | spmc-70b7285967f9d5e6f8a8c4624b69ebf1adedca76.tar.gz |
Merge pull request #8 from jhunkeler/shell-test
Add shell test
Diffstat (limited to 'tests/test_shell_shell.c')
-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 |