-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_export.c
126 lines (105 loc) · 3.24 KB
/
test_export.c
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/26 13:25:49 by yde-goes #+# #+# */
/* Updated: 2023/01/03 11:44:27 by mdias-ma ### ########.fr */
/* */
/* ************************************************************************** */
#include <criterion/criterion.h>
#include <criterion/new/assert.h>
#include <criterion/redirect.h>
#include "builtins.h"
void redirect_all_std(void)
{
extern char **environ;
init_environ(environ);
cr_redirect_stdout();
}
void teardown(void)
{
free_environ();
}
Test(builtin_export, export_only, .init = redirect_all_std, .fini = teardown)
{
char *input[] = {"export", NULL};
int expected;
int result;
expected = 0;
result = ft_export(input);
fflush(stdout);
cr_assert(eq(i32, result, expected));
}
Test(builtin_export, wrong_name_nbr, .init = redirect_all_std, .fini = teardown)
{
char *input[] = {"export", "1magic_br=42", NULL};
int expected;
int result;
expected = 1;
result = ft_export(input);
fflush(stdout);
cr_assert(eq(i32, result, expected));
}
Test(builtin_export, wrong_name_space, .init = redirect_all_std, .fini = teardown)
{
char *input[] = {"export", "magic nbr=42", NULL};
int expected;
int result;
expected = 1;
result = ft_export(input);
fflush(stdout);
cr_assert(eq(i32, result, expected));
}
Test(builtin_export, key_without_value, .init = redirect_all_std, .fini = teardown)
{
char *input[] = {"export", "magic", NULL};
int expected;
int result;
expected = 0;
result = ft_export(input);
fflush(stdout);
cr_assert(eq(i32, result, expected));
}
Test(builtin_export, key_with_value, .init = redirect_all_std, .fini = teardown)
{
char *input[] = {"export", "_magic_nbr=42", NULL};
int expected;
int result;
expected = 0;
result = ft_export(input);
fflush(stdout);
cr_assert(eq(i32, result, expected));
}
Test(builtin_export, value_with_hyphen, .init = redirect_all_std, .fini = teardown)
{
char *input[] = {"export", "_magic_nbr=42-forty", NULL};
int expected;
int result;
expected = 0;
result = ft_export(input);
fflush(stdout);
cr_assert(eq(i32, result, expected));
}
Test(builtin_export, multiple_export, .init = redirect_all_std, .fini = teardown)
{
char *input[] = {"export", "_magic_nbr=42", "test", "test42=forty-two", NULL};
int expected;
int result;
expected = 0;
result = ft_export(input);
fflush(stdout);
cr_assert(eq(i32, result, expected));
}
Test(builtin_export, invalid_char, .init = redirect_all_std, .fini = teardown)
{
char *input[] = {"export", "==test", NULL};
int expected;
int result;
expected = 1;
result = ft_export(input);
fflush(stdout);
cr_assert(eq(i32, result, expected));
}