echo: manage backslashes

This commit is contained in:
arthur
2020-05-21 13:36:53 +02:00
parent f7f39c0b24
commit e569815146
3 changed files with 48 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
/*
** EPITECH PROJECT, 2020
** test_echo.c
** File description:
** techo
*/
#include <criterion/redirect.h>
#include <criterion/criterion.h>
#include "builtin.h"
Test(echo, normal_message, .init = cr_redirect_stdout)
{
env_t env = {};
char *av[] = {"echo", "hello", NULL};
builtin_echo(av, &env);
cr_assert_stdout_eq_str("hello\n");
}
Test(echo, with_simple_backslash, .init = cr_redirect_stdout)
{
env_t env = {};
char *av[] = {"echo", "\\n", NULL};
builtin_echo(av, &env);
cr_assert_stdout_eq_str("n\n");
}
Test(echo, with_double_backslash, .init = cr_redirect_stdout)
{
env_t env = {};
char *av[] = {"echo", "\\\\n", NULL};
builtin_echo(av, &env);
cr_assert_stdout_eq_str("\\n\n");
}
Test(echo, multiple_args, .init = cr_redirect_stdout)
{
env_t env = {};
char *av[] = {"echo", "Hello", "I\'m", "Marvin", NULL};
builtin_echo(av, &env);
cr_assert_stdout_eq_str("Hello I\'m Marvin\n");
}