envp_get_key: add tests

This commit is contained in:
Khaïs COLIN 2025-02-18 15:07:05 +01:00
parent aad17031a8
commit 9ac8588518
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 32 additions and 0 deletions

View file

@ -1,4 +1,5 @@
rawtests = \
env_manip \
metacharacters \
tests = $(addprefix test_,$(rawtests))

31
tests/env_manip.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env_manip.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/18 15:11:14 by khais #+# #+# */
/* Updated: 2025/02/18 15:25:35 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "../src/env_manip.h"
#include "libft.h"
#include <assert.h>
static void test_envp_get_key(char *line, char *expected_key)
{
char *value = envp_get_key(line);
ft_dprintf(STDERR_FILENO, "for envp value '%s', expecting key to eq '%s', and got '%s'\n", line, expected_key, value);
assert(expected_key == value || ft_strcmp(expected_key, value) == 0);
free(value);
}
int main(void) {
test_envp_get_key("SHELL=/bin/fish", "SHELL");
test_envp_get_key("=/bin/fish", "");
test_envp_get_key(NULL, NULL);
test_envp_get_key("", NULL);
return (0);
}