aboutsummaryrefslogtreecommitdiff
path: root/tests/test_shell_shell.c
blob: 5c04c0d9c546c6449f98b6b53f26016204b9e1a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "spm.h"
#include "shell.h"
#include "framework.h"

const char *testFmt = "returned '%s', expected '%s'\n";
struct TestCase testCase[] = {
        {.arg[0].unsigned_int = SHELL_OUTPUT | SHELL_BENCHMARK, .arg[1].sptr = "echo hello; sleep 1", .arg[2].floating = 1, .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_int, 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;
}