#!/bin/sh succeeded="" failed="" run_generic_tests=false function test_site { site="$1" if [[ $site == *.txt && -f $site ]];then site=${site%.txt} fi if [[ ! -f $site.txt ]];then echo "No test file for $site" echo "" failed="true" continue fi site_failed="" echo "Testing $site..." echo "" while read line;do if [[ ! -n "$line" || "$line" =~ ^[[:space:]]*# ]];then continue fi links=($line) echo "Input:" echo "${links[0]}" echo "Goal:" echo "${links[1]}" output=$(/usr/bin/python3 ../rsstube -o "" --output-format url "${links[0]}" | tail -1) echo "Output:" echo "${output}" if [ "$output" == "${links[1]}" ];then echo "Success!" else echo "Failed!" echo "Actual output: $output" site_failed="true" echo "$output" echo "${links[1]}" fi echo "" done < $site.txt if [[ $site_failed != "" ]];then echo "$site did not pass all its tests :(" echo "" failed="$failed- $site\n" else echo "$site passed all its tests! :)" echo "" succeeded="$succeeded- $site\n" fi } if [[ ! -n "$1" || "$1" == "all" ]];then sites=$(ls *.txt | grep -Po '(?<=)(.*)(?=.txt)') run_generic_tests=true else sites="$@" fi for site in $sites;do if [[ $site == "generic" || $site == "generic/" ]];then run_generic_tests=true else test_site $site fi done if [[ $run_generic_tests == "true" ]];then echo "Site-specific tests complete. Running generic tests now." sites=$(ls generic/*.txt | grep -Po '(?<=)(.*)(?=.txt)') for site in $sites;do test_site $site done fi if [[ -n $failed ]];then echo "Some checks failed :(" else echo "All checks passed! :)" fi echo "" echo -e "Succeeded:\n$succeeded" echo -e "Failed:\n$failed"