View difference between Paste ID: qBZ9CMnx and NY1QsW6N
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <check.h>
4
5
void test_cat();
6
7
#define TEST_CAT(STRING)                                                                    \
8
    {                                                                                       \
9
        system("./s21_"STRING" >1");                                                        \
10
        system(STRING" >2");                                                                \
11
        system("xxd 1 >1.hex");                                                             \
12
        system("xxd 2 >2.hex");                                                             \
13
        ck_assert_msg(system("diff -s 1.hex 2.hex >result") == 0, "Failed on: '"STRING"'"); \
14
    }
15
16
17
START_TEST(s21_cat_test) {
18
    TEST_CAT("cat test.txt");
19
    TEST_CAT("cat -n test.txt");
20
    TEST_CAT("cat -n test.txt test_cat.c");
21
    TEST_CAT("cat -v test.txt");
22
    TEST_CAT("cat -t test.txt");
23
    TEST_CAT("cat -b test.txt");
24
    TEST_CAT("cat -e test.txt");
25
    TEST_CAT("cat -s test.txt");
26
    TEST_CAT("cat -z test.txt");
27
    TEST_CAT("cat -s test.txt1 test_cat.c");
28
}
29
END_TEST
30
31
START_TEST(s21_cat_test_multi_p1) {
32
    TEST_CAT("cat -benst test.txt");
33
    TEST_CAT("cat -bents test.txt");
34
    TEST_CAT("cat -besnt test.txt");
35
    TEST_CAT("cat -bestn test.txt");
36
    TEST_CAT("cat -betns test.txt");
37
    TEST_CAT("cat -betsn test.txt");
38
    TEST_CAT("cat -bnest test.txt");
39
    TEST_CAT("cat -bnets test.txt");
40
    TEST_CAT("cat -bnset test.txt");
41
    TEST_CAT("cat -bnste test.txt");
42
    TEST_CAT("cat -bntes test.txt");
43
    TEST_CAT("cat -bntse test.txt");
44
    TEST_CAT("cat -bsent test.txt");
45
    TEST_CAT("cat -bsetn test.txt");
46
    TEST_CAT("cat -bsnet test.txt");
47
    TEST_CAT("cat -bsnte test.txt");
48
    TEST_CAT("cat -bsten test.txt");
49
    TEST_CAT("cat -bstne test.txt");
50
    TEST_CAT("cat -btens test.txt");
51
    TEST_CAT("cat -btesn test.txt");
52
    TEST_CAT("cat -btnes test.txt");
53
    TEST_CAT("cat -btnse test.txt");
54
    TEST_CAT("cat -btsen test.txt");
55
    TEST_CAT("cat -btsne test.txt");
56
}
57
END_TEST
58
59
START_TEST(s21_cat_test_multi_p2) {
60
    TEST_CAT("cat -ebnst test.txt");
61
    TEST_CAT("cat -ebnts test.txt");
62
    TEST_CAT("cat -ebsnt test.txt");
63
    TEST_CAT("cat -ebstn test.txt");
64
    TEST_CAT("cat -ebtns test.txt");
65
    TEST_CAT("cat -ebtsn test.txt");
66
    TEST_CAT("cat -enbst test.txt");
67
    TEST_CAT("cat -enbts test.txt");
68
    TEST_CAT("cat -ensbt test.txt");
69
    TEST_CAT("cat -enstb test.txt");
70
    TEST_CAT("cat -entbs test.txt");
71
    TEST_CAT("cat -entsb test.txt");
72
    TEST_CAT("cat -esbnt test.txt");
73
    TEST_CAT("cat -esbtn test.txt");
74
    TEST_CAT("cat -esnbt test.txt");
75
    TEST_CAT("cat -esntb test.txt");
76
    TEST_CAT("cat -estbn test.txt");
77
    TEST_CAT("cat -estnb test.txt");
78
    TEST_CAT("cat -etbns test.txt");
79
    TEST_CAT("cat -etbsn test.txt");
80
    TEST_CAT("cat -etnbs test.txt");
81
    TEST_CAT("cat -etnsb test.txt");
82
    TEST_CAT("cat -etsbn test.txt");
83
    TEST_CAT("cat -etsnb test.txt");
84
}
85
END_TEST
86
87
START_TEST(s21_cat_test_multi_p3) {
88
    TEST_CAT("cat -nbest test.txt");
89
    TEST_CAT("cat -nbets test.txt");
90
    TEST_CAT("cat -nbset test.txt");
91
    TEST_CAT("cat -nbste test.txt");
92
    TEST_CAT("cat -nbtes test.txt");
93
    TEST_CAT("cat -nbtse test.txt");
94
    TEST_CAT("cat -nebst test.txt");
95
    TEST_CAT("cat -nebts test.txt");
96
    TEST_CAT("cat -nesbt test.txt");
97
    TEST_CAT("cat -nestb test.txt");
98
    TEST_CAT("cat -netbs test.txt");
99
    TEST_CAT("cat -netsb test.txt");
100
    TEST_CAT("cat -nsbet test.txt");
101
    TEST_CAT("cat -nsbte test.txt");
102
    TEST_CAT("cat -nsebt test.txt");
103
    TEST_CAT("cat -nsetb test.txt");
104
    TEST_CAT("cat -nstbe test.txt");
105
    TEST_CAT("cat -nsteb test.txt");
106
    TEST_CAT("cat -ntbes test.txt");
107
    TEST_CAT("cat -ntbse test.txt");
108
    TEST_CAT("cat -ntebs test.txt");
109
    TEST_CAT("cat -ntesb test.txt");
110
    TEST_CAT("cat -ntsbe test.txt");
111
    TEST_CAT("cat -ntseb test.txt");
112
}
113
END_TEST
114
115
START_TEST(s21_cat_test_multi_p4) {
116
    TEST_CAT("cat -sbent test.txt");
117
    TEST_CAT("cat -sbetn test.txt");
118
    TEST_CAT("cat -sbnet test.txt");
119
    TEST_CAT("cat -sbnte test.txt");
120
    TEST_CAT("cat -sbten test.txt");
121
    TEST_CAT("cat -sbtne test.txt");
122
    TEST_CAT("cat -sebnt test.txt");
123
    TEST_CAT("cat -sebtn test.txt");
124
    TEST_CAT("cat -senbt test.txt");
125
    TEST_CAT("cat -sentb test.txt");
126
    TEST_CAT("cat -setbn test.txt");
127
    TEST_CAT("cat -setnb test.txt");
128
    TEST_CAT("cat -snbet test.txt");
129
    TEST_CAT("cat -snbte test.txt");
130
    TEST_CAT("cat -snebt test.txt");
131
    TEST_CAT("cat -snetb test.txt");
132
    TEST_CAT("cat -sntbe test.txt");
133
    TEST_CAT("cat -snteb test.txt");
134
    TEST_CAT("cat -stben test.txt");
135
    TEST_CAT("cat -stbne test.txt");
136
    TEST_CAT("cat -stebn test.txt");
137
    TEST_CAT("cat -stenb test.txt");
138
    TEST_CAT("cat -stnbe test.txt");
139
    TEST_CAT("cat -stneb test.txt");}
140
END_TEST
141
142
START_TEST(s21_cat_test_multi_p5) {
143
    TEST_CAT("cat -tbens test.txt");
144
    TEST_CAT("cat -tbesn test.txt");
145
    TEST_CAT("cat -tbnes test.txt");
146
    TEST_CAT("cat -tbnse test.txt");
147
    TEST_CAT("cat -tbsen test.txt");
148
    TEST_CAT("cat -tbsne test.txt");
149
    TEST_CAT("cat -tebns test.txt");
150
    TEST_CAT("cat -tebsn test.txt");
151
    TEST_CAT("cat -tenbs test.txt");
152
    TEST_CAT("cat -tensb test.txt");
153
    TEST_CAT("cat -tesbn test.txt");
154
    TEST_CAT("cat -tesnb test.txt");
155
    TEST_CAT("cat -tnbes test.txt");
156
    TEST_CAT("cat -tnbse test.txt");
157
    TEST_CAT("cat -tnebs test.txt");
158
    TEST_CAT("cat -tnesb test.txt");
159
    TEST_CAT("cat -tnsbe test.txt");
160
    TEST_CAT("cat -tnseb test.txt");
161
    TEST_CAT("cat -tsben test.txt");
162
    TEST_CAT("cat -tsbne test.txt");
163
    TEST_CAT("cat -tsebn test.txt");
164
    TEST_CAT("cat -tsenb test.txt");
165
    TEST_CAT("cat -tsnbe test.txt");
166
    TEST_CAT("cat -tsneb test.txt");
167
}
168
END_TEST
169
170
START_TEST(s21_cat_test_gnu) {
171
#if defined(__linux__)
172
    TEST_CAT("cat --number-nonblank test.txt");
173
    TEST_CAT("cat --number test.txt");
174
    TEST_CAT("cat --squeeze-blank test.txt");
175
    TEST_CAT("cat -T test.txt");
176
    TEST_CAT("cat -E test.txt");
177
#endif
178
}
179
END_TEST
180
181
START_TEST(s21_cat_test_bin) {
182
    TEST_CAT("cat s21_cat");
183
    TEST_CAT("cat -n s21_cat");
184
    TEST_CAT("cat -v s21_cat");
185
    TEST_CAT("cat -t s21_cat");
186
    TEST_CAT("cat -b s21_cat");
187
    TEST_CAT("cat -e s21_cat");
188
    TEST_CAT("cat -s s21_cat");
189
}
190
END_TEST
191
192
int main(void) {
193
    test_cat();
194
    Suite *s1 = suite_create("cat_tests");
195
    SRunner *sr = srunner_create(s1);
196
    int nf;
197
198
    TCase *tc1_1 = tcase_create("s21_cat_test");
199
    tcase_add_test(tc1_1, s21_cat_test);
200
    suite_add_tcase(s1, tc1_1);
201
202
    TCase *tc2_1 = tcase_create("s21_cat_test_multi_p1");
203
    tcase_add_test(tc2_1, s21_cat_test_multi_p1);
204
    suite_add_tcase(s1, tc2_1);
205
206
    TCase *tc3_1 = tcase_create("s21_cat_test_multi_p2");
207
    tcase_add_test(tc3_1, s21_cat_test_multi_p2);
208
    suite_add_tcase(s1, tc3_1);
209
210
    TCase *tc4_1 = tcase_create("s21_cat_test_multi_p3");
211
    tcase_add_test(tc4_1, s21_cat_test_multi_p3);
212
    suite_add_tcase(s1, tc4_1);
213
214
    TCase *tc5_1 = tcase_create("s21_cat_test_multi_p4");
215
    tcase_add_test(tc5_1, s21_cat_test_multi_p4);
216
    suite_add_tcase(s1, tc5_1);
217
218
    TCase *tc6_1 = tcase_create("s21_cat_test_multi_p5");
219
    tcase_add_test(tc6_1, s21_cat_test_multi_p5);
220
    suite_add_tcase(s1, tc6_1);
221
222
    TCase *tc7_1 = tcase_create("s21_cat_test_gnu");
223
    tcase_add_test(tc7_1, s21_cat_test_gnu);
224
    suite_add_tcase(s1, tc7_1);
225
226
    TCase *tc8_1 = tcase_create("s21_cat_test_bin");
227
    tcase_add_test(tc8_1, s21_cat_test_bin);
228
    suite_add_tcase(s1, tc8_1);
229
230
    srunner_run_all(sr, CK_VERBOSE);
231
    nf = srunner_ntests_failed(sr);
232
    srunner_free(sr);
233
234
    return nf == 0 ? 0 : 1;
235
}
236
237
void test_cat() {
238
    printf("----- Cat testing -----\n");
239
}
240