aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md35
-rw-r--r--lorem.txt9
-rw-r--r--minishell_test.config21
-rwxr-xr-xtest.sh83
4 files changed, 148 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ff7e0e8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,35 @@
+# minishell test
+
+Test for the minishell project of school 42.
+
+# Usage
+
+## Test compatibility
+
+Your executable **must** support the `-c` option which allow to pass command as string.
+
+example:
+
+```
+> bash -c 'echo bonjour je suis'
+bonjour je suis
+> ./minishell -c 'echo bonjour je suis'
+bonjour je suis
+
+> bash -c 'ls'
+README.md test.sh
+> ./minishell -c 'ls'
+README.md test.sh
+```
+
+The reasons for this is are:
+1. we're free to set the prompt to whatever we want
+2. termcaps would be a nightmare to test
+
+## Run
+
+`> ./test.sh`
+
+# Configuration
+
+The default configuration can be changed in the minishell\_test.config file.
diff --git a/lorem.txt b/lorem.txt
new file mode 100644
index 0000000..d3d78b8
--- /dev/null
+++ b/lorem.txt
@@ -0,0 +1,9 @@
+Mollitia asperiores assumenda excepturi et ipsa. Nihil corporis facere aut a rem consequatur. Quas molestiae corporis et quibusdam maiores. Molestiae sed unde aut at sed.
+
+Deserunt quidem quidem aspernatur pariatur vel illum voluptatum. Culpa unde dolor aspernatur sit. Mollitia tenetur sed eaque autem placeat a aut in. Ipsam ea consequuntur omnis.
+
+Non et qui vel corrupti similique eum aut voluptatibus. Iste consequatur voluptatum et omnis debitis. Sit quia neque nihil consequatur sint. Velit libero ut aut et et rerum.
+
+Placeat cumque incidunt non repellat sunt perspiciatis ullam. Repellendus repudiandae nostrum quia quis corrupti. Rerum veniam earum cumque pariatur accusantium voluptatum omnis. Alias ut et et adipisci. Tempore omnis numquam ullam et animi et eveniet.
+
+Dolor itaque distinctio in. Magnam rerum quia est laboriosam repellat perspiciatis eos. Consequuntur quae corrupti atque. Numquam enim ut ut. Perspiciatis ut maxime et libero quo voluptas consequatur illum. Pariatur porro dolor cumque molestiae harum.
diff --git a/minishell_test.config b/minishell_test.config
new file mode 100644
index 0000000..3795ac7
--- /dev/null
+++ b/minishell_test.config
@@ -0,0 +1,21 @@
+# Minishell config file
+
+# minishell dir path
+minishell_path=../minishell
+
+# minishell executable
+minishell_exec=minishell
+
+# lorem (long text) path
+lorem_path=lorem.txt
+
+# path to reference shell (shell which will be compared minishell)
+# has to support the -c option (sh, bash and zsh support it)
+reference_shell_path=/bin/bash
+
+# string marker which show the test result
+pass_marker=.
+fail_marker=!
+
+# log file path
+log_file=result.log
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..4d37ef5
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# test.sh :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/05/01 10:54:53 by charles #+# #+# #
+# Updated: 2020/05/01 10:54:53 by charles ### ########.fr #
+# #
+# **************************************************************************** #
+
+case $# in
+ 0) config_file=minishell_test.config;;
+ 1) config_file=$1;;
+ *) echo "Usage: $0 [config file]"; exit 1;;
+esac
+
+config_extract() {
+ grep $1 $config_file | cut -d '=' -f 2
+}
+
+minishell_path=`config_extract minishell_path`
+minishell_exec=`config_extract minishell_exec`
+minishell_exec_path=$minishell_path/$minishell_exec
+reference_shell_path=`config_extract reference_shell_path`
+lorem_path=`config_extract lorem_path`
+lorem=`cat $lorem_path`
+pass_marker=`config_extract pass_marker`
+fail_marker=`config_extract fail_marker`
+log_file=`config_extract log_file`
+
+# echo $minishell_path
+# echo $minishell_exec
+# echo $minishell_exec_path
+# echo $lorem
+
+if [ ! -f $minishell_exec_path ]; then
+ echo "Error: $minishell_exec_path does not exist"
+ exit 1
+fi
+
+red() { echo -n "`tput setaf 1`$1`tput sgr 0`"; }
+green() { echo -n "`tput setaf 2`$1`tput sgr 0`"; }
+put_pass_marker () { green $pass_marker; }
+put_fail_marker () { red $fail_marker; }
+
+append_fail () {
+ tested=$1
+ expected=$2
+ expected_status=$3
+ actual=$4
+ actual_status=$5
+ echo "for $1"
+}
+
+expect() {
+ expected=`$referecence_shell_path -c $1`
+ expected_status=$?
+ actual=`$minishell_exec_path -c $1`
+ actual_status=$?
+ ([ $expected = $actual ] && [ $expected_status -eq $actual_status ] && put_pass_marker)
+ || (put_fail_marker &&
+ echo <<EOF
+for $1:
+expected: $expected
+actual: $actual
+status: expected: $expected_status actual: $actual_status
+
+EOF
+}
+
+###############################################################################
+# Builtin
+###############################################################################
+
+expect 'echo bonjour'
+expect 'echo bonjour je suis'
+expect "echo $lorem"
+expect "echo $lorem $lorem $lorem $lorem"
+