#!/usr/bin/env bash if [ ! -d "$1" ]; then echo "No folder to test provided" echo "Usage: ./tester.sh [path_to_nm] [-flags]" echo "folder_to_test: folder containing the binaries to test" echo "path_to_nm: path to the nm executable, default ./ft_nm" echo "flags: flags to pass to the nm executable, default none" exit 1 fi if [[ $2 == -* ]]; then NM=./ft_nm FLAGS=$2 else if [ -z "$2" ]; then NM=./ft_nm else NM=$2 fi fi if [[ -z $FLAGS && $3 == -* ]]; then FLAGS=$3 fi TESTS_DIR=$1 TESTS=$(find "$TESTS_DIR" -maxdepth 1 -type f -printf '%f ') SUCCESS=0 FAIL=0 rm -rf "$TESTS_DIR/logs" mkdir -pv "$TESTS_DIR/logs/diff" mkdir -pv "$TESTS_DIR/logs/my_output" mkdir -pv "$TESTS_DIR/logs/system_output" for test in $TESTS; do $NM $FLAGS $TESTS_DIR/$test 2>&1 | nl >$TESTS_DIR/logs/my_output/$test.log nm $FLAGS $TESTS_DIR/$test 2>&1 | nl >$TESTS_DIR/logs/system_output/$test.log sdiff -s $TESTS_DIR/logs/my_output/$test.log $TESTS_DIR/logs/system_output/$test.log >$TESTS_DIR/logs/diff/$test.diff if [[ $(wc -l $TESTS_DIR/logs/diff/$test.diff | cut -d ' ' -f 1) -gt 0 ]]; then printf '|%-123s|\n' ' ' | tr ' ' '=' printf "| $test: ❌%-*s |\n" $((123 - 6 - ${#test}))"" | tee -a $TESTS_DIR/logs/recap.log printf '|%-123s|\n' ' ' | tr ' ' '=' printf '| %-60s| %-60s|\n' 'My nm' 'System nm' printf '|%-123s|\n' ' ' | tr ' ' '-' < "$TESTS_DIR/logs/diff/$test.diff" colordiff | diff-highlight ((FAIL++)) else printf '|%-123s|\n' "$(printf '%123s' | tr ' ' '=')" printf "| $test: ✅%-*s |\n" $((123 - 6 - ${#test}))"" | tee -a $TESTS_DIR/logs/recap.log ((SUCCESS++)) fi done printf "\e[0;32mSuccess: %s\n" $SUCCESS printf "\e[0;31mFail: %s\n" $FAIL printf "\e[0m"