mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Expansion: one little problem remaining with * expansion and .
This commit is contained in:
parent
2da7f03a66
commit
da06c0d4e0
4 changed files with 42 additions and 41 deletions
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* wordlist_quicksort.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/08 17:29:05 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/19 16:29:58 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/03/20 09:41:04 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ static int wordlist_quicksort_partition(t_wordlist *list, int start, int end)
|
|||
pivot = wordlist_get_elem(list, end);
|
||||
while (j < end)
|
||||
{
|
||||
if (ft_strcmp(list_j->word->word, pivot->word->word) > 0)
|
||||
if (ft_strcmp(list_j->word->word, pivot->word->word) < 0)
|
||||
{
|
||||
ft_swap_wordlist_contents(list_i, list_j);
|
||||
i++;
|
||||
|
|
|
|||
0
tests/expand_test/.plop
Normal file
0
tests/expand_test/.plop
Normal file
1
tests/expand_test/port/ls
Executable file
1
tests/expand_test/port/ls
Executable file
|
|
@ -0,0 +1 @@
|
|||
echo hello
|
||||
|
|
@ -6,12 +6,14 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/19 17:52/50 by khais #+# #+# */
|
||||
/* Updated: 2025/03/19 17:52:50 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/20 10:36:23 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "testutil.h"
|
||||
#include "../src/subst/replace_substr.h"
|
||||
#include "../src/subst/subst.h"
|
||||
|
|
@ -19,7 +21,6 @@
|
|||
#include "../src/env/env_manip.h"
|
||||
#include "../src/parser/wordsplit/wordsplit.h"
|
||||
|
||||
|
||||
static t_worddesc *create_single_word(char *str)
|
||||
{
|
||||
t_wordlist *words = minishell_wordsplit(str);
|
||||
|
|
@ -95,17 +96,17 @@ static void test_cmd_path_expansion(void)
|
|||
char *cmdpath;
|
||||
|
||||
key = ft_strdup("PATH");
|
||||
value = ft_strdup("/usr/bin");
|
||||
value = ft_strdup("./port:/usr/bin");
|
||||
app = ft_calloc(1, sizeof(t_minishell));
|
||||
app->env = env_set_entry(&(app->env), key, value);
|
||||
cmdpath = get_cmdpath("ls", app);
|
||||
/* assert_strequal("/usr/bin/ls", cmdpath); */ // FIXME: does not work on nixos
|
||||
assert_strequal("./port/ls", cmdpath);
|
||||
free(cmdpath);
|
||||
value = ft_strdup(":/usr/bin");
|
||||
key = ft_strdup("PATH");
|
||||
app->env = env_set_entry(&(app->env), key, value);
|
||||
cmdpath = get_cmdpath("ls", app);
|
||||
/* assert_strequal("./ls", cmdpath); */ // FIXME: is not portable
|
||||
assert_strequal("./ls", cmdpath);
|
||||
free(cmdpath);
|
||||
cmdpath = get_cmdpath("peekaboo", app);
|
||||
assert(cmdpath == NULL);
|
||||
|
|
@ -121,61 +122,58 @@ static void test_filename_star_expansion(void)
|
|||
t_wordlist *expanded;
|
||||
t_wordlist *tmp;
|
||||
|
||||
return ;
|
||||
//test1
|
||||
//test1 Everything except . and ..
|
||||
ft_printf("test_filename_star_expansion\n");
|
||||
filepattern = create_single_word("*");
|
||||
expanded = expand_star(filepattern);
|
||||
tmp = expanded;
|
||||
assert_strequal("blabla", tmp->word->word);
|
||||
assert_strequal("aba", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("abcda", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("aiia", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("axr", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("directory", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("exp", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("expansion.c", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("flagadaPATH", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("ls", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("Makefile", tmp->word->word);
|
||||
assert_strequal("port", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("metacharacters.c", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("parse_pipelines.c", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("parse_simple_cmds.c", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("test_env_manip.c", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("testutil.c", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("testutil.h", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(tmp);
|
||||
assert_strequal("word_splitting.c", tmp->word->word);
|
||||
assert_strequal("yuhbqa", tmp->word->word);
|
||||
tmp = tmp->next;
|
||||
assert(!tmp);
|
||||
wordlist_destroy(expanded);
|
||||
worddesc_destroy(filepattern);
|
||||
//test2
|
||||
filepattern = create_single_word("**bla'b'*la*");
|
||||
filepattern = create_single_word("**a*'b'*a*");
|
||||
expanded = expand_star(filepattern);
|
||||
assert(wordlist_size(expanded) == 1);
|
||||
assert_strequal("blabla", expanded->word->word);
|
||||
assert(wordlist_size(expanded) == 2);
|
||||
assert_strequal("aba", expanded->word->word);
|
||||
assert_strequal("abcda", expanded->next->word->word);
|
||||
worddesc_destroy(filepattern);
|
||||
wordlist_destroy(expanded);
|
||||
//test zero résultat
|
||||
//test ., .. and .plop
|
||||
filepattern = create_single_word(".*");
|
||||
expanded = expand_star(filepattern);
|
||||
//assert(wordlist_size(expanded) == 3);
|
||||
//assert_strequal(".", expanded->word->word);
|
||||
//assert_strequal("..", expanded->next->word->word);
|
||||
//assert_strequal(".plop", expanded->next->next->word->word);
|
||||
worddesc_destroy(filepattern);
|
||||
wordlist_destroy(expanded);
|
||||
//test zero result
|
||||
filepattern = create_single_word("e*x***p*b");
|
||||
expanded = expand_star(filepattern);
|
||||
worddesc_destroy(filepattern);
|
||||
|
|
@ -206,6 +204,8 @@ void simple_sub_test(void)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
if (chdir("./expand_test") == -1)
|
||||
assert("chdir failure" && false);
|
||||
simple_sub_test();
|
||||
test_insert_instr();
|
||||
test_env_variable_expansion();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue