-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdout.c
More file actions
63 lines (57 loc) · 1.37 KB
/
stdout.c
File metadata and controls
63 lines (57 loc) · 1.37 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// NOTE: The location of this include might differ in your code depending on location
// For example, it could be: #include "caught.h"
#include "../src/caught.h"
TEST("stdout - hello world")
{
MOCK_STDOUT();
puts("Hello, world!");
char *out = RESTORE_STDOUT();
EXPECT_STR(out, ==, "Hello, world!\n");
free(out);
}
TEST("stdout - a lot of text")
{
MOCK_STDOUT();
puts("The answer to life,");
puts("the universe,");
puts("and everything,");
puts("is 42.");
char *out = RESTORE_STDOUT();
EXPECT_STR(out, ==, "The answer to life,\nthe universe,\nand everything,\nis 42.\n");
free(out);
}
TEST("stdout - with generic expect")
{
MOCK_STDOUT();
puts("This is fun!");
EXPECT_INT(1 + 1, ==, 2);
char *out = RESTORE_STDOUT();
EXPECT_STR(out, ==, "This is fun!\n");
free(out);
}
TEST("stdout - no output")
{
MOCK_STDOUT();
char *out = RESTORE_STDOUT();
EXPECT_STR(out, ==, "");
free(out);
}
TEST("stdout - no newline")
{
MOCK_STDOUT();
printf("wow this is a cool string yes it is");
char *out = RESTORE_STDOUT();
EXPECT_STR(out, ==, "wow this is a cool string yes it is");
free(out);
}
TEST("stdout - with expect exit")
{
MOCK_STDOUT();
EXPECT_EXIT(1, {
puts("Hello!");
exit(1);
});
char *out = RESTORE_STDOUT();
EXPECT_STR(out, ==, "Hello!\n");
free(out);
}