-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.c
49 lines (39 loc) · 1.09 KB
/
tests.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cotenv.h"
void create_temp_env_file(const char *filename) {
FILE *file = fopen(filename, "w");
if (!file) {
cotenv_failed_to_create_file(filename);
exit(EXIT_FAILURE);
}
fprintf(file, "HELLO_WORLD=HelloWorld\n");
fprintf(file, "MEANING_OF_LIFE=42\n");
fprintf(file, "# This is an usefull commment\n");
fprintf(file, "NAME_OF_GIRLFRIEND=\n");
fclose(file);
}
void test(const char *test, const char *expected) {
if (test && strcmp(test, expected) == 0) {
printf("Test passed: %s\n", test);
} else {
printf("Test failed: %s\n", test);
}
}
void run_tests() {
const char *test_file = "test.env";
create_temp_env_file(test_file);
load_cotenv(test_file);
const char *hello_world = getenv("HELLO_WORLD");
const char *meaning_of_life = getenv("MEANING_OF_LIFE");
const char *name_of_girlfriend = getenv("NAME_OF_GIRLFRIEND");
test(hello_world, "HelloWorld");
test(meaning_of_life, "42");
test(name_of_girlfriend,"");
remove(test_file);
}
int main() {
run_tests();
return EXIT_SUCCESS;
}