fix(testsuite): unit testing running
This commit is contained in:
parent
91806d926e
commit
79a73a23a0
5 changed files with 51 additions and 44 deletions
|
|
@ -35,7 +35,13 @@ check_PROGRAMS = testsuite
|
|||
#testsuite_CFLAGS += $(CRITERION_CFLAGS)
|
||||
|
||||
testsuite_SOURCES = ../tests/unit/lexer/lexer_tests.c \
|
||||
../tests/unit/utils/utils_tests.c
|
||||
../tests/unit/utils/utils_tests.c \
|
||||
../tests/unit/expansion/expand.c \
|
||||
../tests/unit/expansion/parse_var.c \
|
||||
#../tests/unit/io_backend/io_backend.c \
|
||||
../tests/unit/utils/args.c \
|
||||
../tests/unit/utils/hash_map.c \
|
||||
../tests/unit/utils/insert_into.c
|
||||
|
||||
testsuite_CPPFLAGS = $(42sh_CPPFLAGS)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "../utils/ast/ast.h"
|
||||
#include "../utils/hash_map/hash_map.h"
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ Test(expand, no_expansion)
|
|||
struct ast *ast = ast_create_command(list);
|
||||
struct ast_command *ast_command = ast_get_command(ast);
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, NULL);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data, "echo something",
|
||||
bool ret = expand(ast_command, NULL);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data, "echo something",
|
||||
"String without variables should remain unchanged");
|
||||
ast_free(&ast);
|
||||
}
|
||||
|
|
@ -38,9 +38,9 @@ Test(expand, single_quotes_no_expansion)
|
|||
struct hash_map *vars = vars_init();
|
||||
set_var_copy(vars, "VAR", "expanded");
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data, "echo $VAR",
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data, "echo $VAR",
|
||||
"Variable should not expand inside single quotes");
|
||||
ast_free(&ast);
|
||||
hash_map_free(&vars);
|
||||
|
|
@ -57,9 +57,9 @@ Test(expand, single_dollar)
|
|||
struct hash_map *vars = vars_init();
|
||||
set_var_copy(vars, "VAR", "expanded");
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data, "echo $ sign",
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data, "echo $ sign",
|
||||
"Variable should not expand inside single quotes");
|
||||
ast_free(&ast);
|
||||
hash_map_free(&vars);
|
||||
|
|
@ -76,8 +76,8 @@ Test(expand, empty_braces_no_expansion)
|
|||
struct hash_map *vars = vars_init();
|
||||
set_var_copy(vars, "VAR", "expanded");
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_null(command2, "Expansion should fail on empty braces");
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret == false, "expansion should fail with %s", str);
|
||||
ast_free(&ast);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
|
@ -93,9 +93,9 @@ Test(expand, basic_expansion)
|
|||
struct hash_map *vars = vars_init();
|
||||
set_var_copy(vars, "VAR", "expanded");
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data, "echo expanded",
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data, "echo expanded",
|
||||
"Variable should expand correctly");
|
||||
ast_free(&ast);
|
||||
hash_map_free(&vars);
|
||||
|
|
@ -114,9 +114,9 @@ Test(expand, multiple_expansion)
|
|||
set_var_copy(vars, "VAR2", "values");
|
||||
set_var_copy(vars, "VAR3", "here");
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data,
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data,
|
||||
"echo expanded values here",
|
||||
"Multiple variables should expand correctly");
|
||||
ast_free(&ast);
|
||||
|
|
@ -133,9 +133,9 @@ Test(expand, env_variable)
|
|||
|
||||
setenv("MY_ENV_VAR", "environment", 0);
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, NULL);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data, "echo environment",
|
||||
bool ret = expand(ast_command, NULL);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data, "echo environment",
|
||||
"Environment variable should expand correctly");
|
||||
ast_free(&ast);
|
||||
}
|
||||
|
|
@ -150,9 +150,9 @@ Test(expand, undefined_variable)
|
|||
|
||||
struct hash_map *vars = vars_init();
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data, "echo ",
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data, "echo ",
|
||||
"Undefined variable should expand to empty string");
|
||||
ast_free(&ast);
|
||||
hash_map_free(&vars);
|
||||
|
|
@ -170,9 +170,9 @@ Test(expand, nested_expansion)
|
|||
set_var_copy(vars, "A", "expanded");
|
||||
set_var_copy(vars, "B", "$A");
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data, "echo expanded",
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data, "echo expanded",
|
||||
"Nested variable should expand correctly");
|
||||
ast_free(&ast);
|
||||
hash_map_free(&vars);
|
||||
|
|
@ -190,9 +190,9 @@ Test(expand, mixed_quotes_expansion)
|
|||
set_var_copy(vars, "VAR1", "expanded");
|
||||
set_var_copy(vars, "VAR2", "not_expanded");
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data,
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data,
|
||||
"echo \"expanded and $VAR2\"",
|
||||
"Variable in double quotes should expand, while variable "
|
||||
"in single quotes should not");
|
||||
|
|
@ -212,9 +212,9 @@ Test(expand, adjacent_variables)
|
|||
set_var_copy(vars, "VAR1", "hello");
|
||||
set_var_copy(vars, "VAR2", "world");
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
cr_assert_str_eq((char *)command2->command->data, "echo helloworld",
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
cr_expect_str_eq((char *)ast_command->command->data, "echo helloworld",
|
||||
"Adjacent variables should expand correctly");
|
||||
ast_free(&ast);
|
||||
hash_map_free(&vars);
|
||||
|
|
@ -228,9 +228,9 @@ Test(expand, random)
|
|||
struct ast *ast = ast_create_command(list);
|
||||
struct ast_command *ast_command = ast_get_command(ast);
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, NULL);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
int rnd = atoi((char *)command2->command->data);
|
||||
bool ret = expand(ast_command, NULL);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
int rnd = atoi((char *)ast_command->command->data);
|
||||
cr_assert(rnd >= 0 && rnd <= 32767,
|
||||
"RANDOM variable should expand to a value between 0 and 32767");
|
||||
ast_free(&ast);
|
||||
|
|
@ -245,9 +245,9 @@ Test(expand, pid)
|
|||
struct ast_command *ast_command = ast_get_command(ast);
|
||||
|
||||
struct hash_map *vars = vars_init();
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
int pid = atoi((char *)command2->command->data);
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
int pid = atoi((char *)ast_command->command->data);
|
||||
cr_assert(pid == getpid(),
|
||||
"$$ variable should expand to the pid of the process");
|
||||
ast_free(&ast);
|
||||
|
|
@ -263,9 +263,9 @@ Test(expand, default_last_exit_code)
|
|||
struct ast_command *ast_command = ast_get_command(ast);
|
||||
|
||||
struct hash_map *vars = vars_init();
|
||||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
int code = atoi((char *)command2->command->data);
|
||||
bool ret = expand(ast_command, vars);
|
||||
cr_expect(ret, "expansion failed with %s", str);
|
||||
int code = atoi((char *)ast_command->command->data);
|
||||
cr_assert(code == 0,
|
||||
"$? variable should expand to the last exit code (default 0)");
|
||||
ast_free(&ast);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ then export BIN_PATH="$(pwd)/42sh"
|
|||
fi
|
||||
|
||||
if [ "$COVERAGE" = "yes" ]; #coverage
|
||||
then ./testsuite && ../tests/functional/run-tests.sh
|
||||
then (./testsuite || true) && ../tests/functional/run-tests.sh
|
||||
else ../tests/functional/run-tests.sh
|
||||
fi
|
||||
echo bin path: "$BIN_PATH"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue