-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_test.c
More file actions
45 lines (37 loc) · 1.14 KB
/
os_test.c
File metadata and controls
45 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "os.c"
#include "test.c"
static MunitResult test_os_exec_output(const MunitParameter params[], void *data) {
// Info message from stdout
{
os_exec_output("echo 'hello'", "world");
assert_string_equal("hello world\n", g_msg);
assert(g_msg_type == MSG_TYPE_INFO);
}
// Error message from invalid command
{
os_exec_output("echozzz", "");
test_assert_string_contains(g_msg, "command not found");
assert(g_msg_type == MSG_TYPE_ERROR);
}
// Error message from stderr
{
return MUNIT_SKIP; // TODO
os_exec_output("echo 'hello' >&2", "");
// assert_string_equal("hello\n", g_msg);
// assert(g_msg_type == MSG_TYPE_ERROR);
}
// Working directory is updated if cd in command
{
assert_string_equal(".", g_cwd);
os_exec_output("cd /tmp", "");
test_assert_string_contains(g_cwd, "/tmp");
char cwd[500];
assert(getcwd(cwd, sizeof(cwd)));
test_assert_string_contains(cwd, "/tmp");
}
return MUNIT_OK;
}
MunitTest os_tests[] = {
{"/exec_output", test_os_exec_output, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
};