mirror of
https://github.com/zoriya/ash.git
synced 2026-06-07 04:04:46 +00:00
added arguments and tests
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@
|
||||
#include <criterion/redirect.h>
|
||||
#include "shell.h"
|
||||
|
||||
void eval(char *cmd, char **argv, env_t* env);
|
||||
char *eval(char *cmd, char **argv, env_t* env);
|
||||
|
||||
extern char **environ;
|
||||
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** ash
|
||||
** File description:
|
||||
** test source function
|
||||
*/
|
||||
|
||||
#include <criterion/criterion.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "shell.h"
|
||||
#include "builtin.h"
|
||||
|
||||
Test(parse_source_cmd, no_args)
|
||||
{
|
||||
char *cmd = strdup("echo wow");
|
||||
char **argv = get_argv(strdup("source source_file"));
|
||||
int argv_len = 0;
|
||||
char *res = NULL;
|
||||
|
||||
for (; argv[argv_len]; argv_len++);
|
||||
res = parse_source_cmd(cmd, argv, argv_len);
|
||||
cr_assert_str_eq(res, "echo wow");
|
||||
}
|
||||
|
||||
Test(parse_source_cmd, one_arg)
|
||||
{
|
||||
char *cmd = strdup("echo $1");
|
||||
char **argv = get_argv(strdup("source source_file wow"));
|
||||
int argv_len = 0;
|
||||
char *res = NULL;
|
||||
|
||||
for (; argv[argv_len]; argv_len++);
|
||||
res = parse_source_cmd(cmd, argv, argv_len);
|
||||
cr_assert_str_eq(res, "echo wow");
|
||||
}
|
||||
|
||||
Test(parse_source_cmd, two_args)
|
||||
{
|
||||
char *cmd = strdup("$2 $1");
|
||||
char **argv = get_argv(strdup("source source_file wow echo"));
|
||||
int argv_len = 0;
|
||||
char *res = NULL;
|
||||
|
||||
for (; argv[argv_len]; argv_len++);
|
||||
res = parse_source_cmd(cmd, argv, argv_len);
|
||||
cr_assert_str_eq(res, "echo wow");
|
||||
}
|
||||
|
||||
Test(parse_source_cmd, args_out_of_range)
|
||||
{
|
||||
char *cmd = strdup("echo wow$1");
|
||||
char **argv = get_argv(strdup("source source_file"));
|
||||
int argv_len = 0;
|
||||
char *res = NULL;
|
||||
|
||||
for (; argv[argv_len]; argv_len++);
|
||||
res = parse_source_cmd(cmd, argv, argv_len);
|
||||
cr_assert_str_eq(res, "echo wow");
|
||||
}
|
||||
|
||||
Test(parse_source_cmd, args_index_0)
|
||||
{
|
||||
char *cmd = strdup("echo shell is: $0");
|
||||
char **argv = get_argv(strdup("source source_file"));
|
||||
int argv_len = 0;
|
||||
char *res = NULL;
|
||||
|
||||
for (; argv[argv_len]; argv_len++);
|
||||
res = parse_source_cmd(cmd, argv, argv_len);
|
||||
cr_assert_str_eq(res, "echo shell is: 42sh");
|
||||
}
|
||||
|
||||
Test(parse_source_cmd, args_inside_cmd)
|
||||
{
|
||||
char *cmd = strdup("e$1o wow");
|
||||
char **argv = get_argv(strdup("source source_file ch"));
|
||||
int argv_len = 0;
|
||||
char *res = NULL;
|
||||
|
||||
for (; argv[argv_len]; argv_len++);
|
||||
res = parse_source_cmd(cmd, argv, argv_len);
|
||||
cr_assert_str_eq(res, "echo wow");
|
||||
}
|
||||
|
||||
Test(parse_source_cmd, invalid_arg)
|
||||
{
|
||||
char *cmd = strdup("e$o wow");
|
||||
char **argv = get_argv(strdup("source source_file ch"));
|
||||
int argv_len = 0;
|
||||
char *res = NULL;
|
||||
|
||||
for (; argv[argv_len]; argv_len++);
|
||||
res = parse_source_cmd(cmd, argv, argv_len);
|
||||
cr_assert_str_eq(res, "e wow");
|
||||
}
|
||||
|
||||
Test(parse_source_cmd, empty_str)
|
||||
{
|
||||
char *cmd = strdup("");
|
||||
char **argv = get_argv(strdup("source source_file ch"));
|
||||
int argv_len = 0;
|
||||
char *res = NULL;
|
||||
|
||||
for (; argv[argv_len]; argv_len++);
|
||||
res = parse_source_cmd(cmd, argv, argv_len);
|
||||
cr_assert_str_eq(res, "");
|
||||
}
|
||||
Reference in New Issue
Block a user