maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
env_test.c File Reference
#include <assert.h>
#include "libft.h"
#include "env.h"
#include "shell.h"
#include <stdio.h>
Include dependency graph for env_test.c:

Go to the source code of this file.

Functions

void env_tests (t_ms_data *data, char **envp)
 
void test_init_env (t_ms_data *data, char **envp)
 
void test_get_env (t_ms_data *data, char **envp)
 
void test_set_env (t_ms_data *data, char **envp)
 
void test_unset_env (t_ms_data *data)
 

Function Documentation

◆ env_tests()

void env_tests ( t_ms_data data,
char **  envp 
)

Definition at line 25 of file env_test.c.

26{
27 ft_printf("\nENV TESTS\n");
28 test_init_env(data, envp);
29 test_get_env(data, envp);
30 test_set_env(data, envp);
31 test_unset_env(data);
32 free_env(data->envp);
33}
void free_env(t_env *envp)
Definition utils.c:73
void test_set_env(t_ms_data *data, char **envp)
Definition env_test.c:72
void test_get_env(t_ms_data *data, char **envp)
Definition env_test.c:57
void test_unset_env(t_ms_data *data)
Definition env_test.c:88
void test_init_env(t_ms_data *data, char **envp)
Definition env_test.c:35
int ft_printf(const char *format,...)
Definition ft_printf.c:37
t_env * envp
Definition shell.h:24

References s_ms_data::envp, free_env(), ft_printf(), test_get_env(), test_init_env(), test_set_env(), and test_unset_env().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_get_env()

void test_get_env ( t_ms_data data,
char **  envp 
)

Definition at line 57 of file env_test.c.

58{
59 char *value;
60
61 data->envp = NULL;
62 init_env(&data->envp, envp);
63 value = get_env(data->envp, "LOGNAME");
64 assert(value != NULL);
65 assert(ft_strcmp(value, getenv("LOGNAME")) == 0);
66 ft_printf("\033[0m");
67 ft_printf("\033[0;32m");
68 ft_printf("get_env -> OK\n");
69 ft_printf("\033[0m");
70}
void init_env(t_env **data_envp, char **envp)
Definition env.c:24
char * get_env(t_env *envp, const char *key)
Definition env.c:59
int ft_strcmp(const char *s1, const char *s2)
Definition ft_strcmp.c:24

References s_ms_data::envp, ft_printf(), ft_strcmp(), get_env(), and init_env().

Referenced by env_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_init_env()

void test_init_env ( t_ms_data data,
char **  envp 
)

Definition at line 35 of file env_test.c.

36{
37 char **test_envp;
38 int envp_count;
39 int test_envp_count;
40
41 data->envp = NULL;
42 init_env(&data->envp, envp);
43 test_envp = env_to_array(data->envp);
44 envp_count = 0;
45 while (envp[envp_count])
46 envp_count++;
47 test_envp_count = 0;
48 while (test_envp[test_envp_count])
49 test_envp_count++;
50 assert(envp_count == test_envp_count);
51 ft_printf("\033[0m");
52 ft_printf("\033[0;32m");
53 ft_printf("init_env -> OK\n");
54 ft_printf("\033[0m");
55}
char ** env_to_array(t_env *envp)
Definition utils.c:23

References env_to_array(), s_ms_data::envp, ft_printf(), and init_env().

Referenced by env_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_set_env()

void test_set_env ( t_ms_data data,
char **  envp 
)

Definition at line 72 of file env_test.c.

73{
74 char *value;
75
76 data->envp = NULL;
77 init_env(&data->envp, envp);
78 set_env(&data->envp, "TEST", "test");
79 value = get_env(data->envp, "TEST");
80 assert(value != NULL);
81 assert(ft_strcmp(value, "test") == 0);
82 ft_printf("\033[0m");
83 ft_printf("\033[0;32m");
84 ft_printf("set_env -> OK\n");
85 ft_printf("\033[0m");
86}
void set_env(t_env **env, const char *key, const char *value)
Definition env.c:73

References s_ms_data::envp, ft_printf(), ft_strcmp(), get_env(), init_env(), and set_env().

Referenced by env_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_unset_env()

void test_unset_env ( t_ms_data data)

Definition at line 88 of file env_test.c.

89{
90 char *value;
91
92 set_env(&data->envp, "TEST", "test");
93 value = get_env(data->envp, "TEST");
94 assert(value != NULL);
95 assert(ft_strcmp(value, "test") == 0);
96 unset_env(&data->envp, "TEST");
97 value = get_env(data->envp, "TEST");
98 assert(value == NULL);
99 ft_printf("\033[0m");
100 ft_printf("\033[0;32m");
101 ft_printf("unset_env -> OK\n");
102 ft_printf("\033[0m");
103}
int unset_env(t_env **env, const char *name)
Definition env.c:96

References s_ms_data::envp, ft_printf(), ft_strcmp(), get_env(), set_env(), and unset_env().

Referenced by env_tests().

Here is the call graph for this function:
Here is the caller graph for this function: