#!/usr/bin/env bash set -uo pipefail declare -i FAILED=0 declare -i SUCCEDED=0 declare -i TODTODO=0 declare -i RAN=0 NAME="" report_header() { echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" echo $NAME echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++ test input:" } failed_report() { NAME="failed: $NAME" report_header cat /tmp/input.minishell echo "++++ Got output:" cat /tmp/got.minishell echo "++++ But expected:" cat /tmp/expected.minishell echo "++++ Diff:" echo "(red is got, green is expected)" diff --color=always /tmp/got.minishell /tmp/expected.minishell echo "++++ Run this to debug:" cat < /tmp/input.minishell > /tmp/input.failed.$FAILED.minishell echo "cat /tmp/input.failed.$FAILED.minishell | ./minishell" } todo_report() { NAME="todo: $NAME" report_header cat /tmp/input.minishell echo "++++ Got output:" cat /tmp/got.minishell echo "++++ But test was marked as todo." echo "++++ Run this to debug:" cat < /tmp/input.minishell > /tmp/input.todo.$TODO.minishell echo "cat /tmp/input.todo.$TODO.minishell | ./minishell" } failed() { echo -n "F" FAILED+=1 failed_report >> report.txt } succeded() { echo -n "." SUCCEDED+=1 } assert() { diff -q /tmp/got.minishell /tmp/expected.minishell > /dev/null && succeded || failed } when_run() { cat > /tmp/input.minishell ./minishell &> /tmp/got.minishell < /tmp/input.minishell RAN+=1 NAME=$1 } expecting() { cat > /tmp/expected.minishell assert } todo() { echo -n "t" TODO+=1 todo_report >> report.txt } setup() { rm -f report.txt } finalize() { echo echo "$RAN tests ran. $SUCCEDED succeded, $FAILED failed, $TODO todo." if [ $SUCCEDED -eq $RAN ]; then echo "All integration tests passed!" else echo "cat report.txt" echo "to see details of failed/todo tests" fi exit $FAILED } setup when_run <outfile EOF expecting < out EOF expecting <outfile there < infile < infile2 >> append EOF expecting <> append | echo < infile bye && echo hello > outfile) EOF expecting <