Skip to content

Instantly share code, notes, and snippets.

@kprav33n
Created April 1, 2020 08:43
Show Gist options
  • Save kprav33n/f4c5132f63e79248e5f3cc5891aad02f to your computer and use it in GitHub Desktop.
Save kprav33n/f4c5132f63e79248e5f3cc5891aad02f to your computer and use it in GitHub Desktop.
#!/bin/bash
usage() {
echo "Usage: $0 CONFIG"
exit 1
}
if [ $# -ne 1 ]; then
usage
fi
input_files=$(grep input_files $1 | cut -d '=' -f 2 | sed 's/,/ /g')
output_dir=$(grep output_dir $1 | cut -d '=' -f 2)
num_output=$(grep n_output_files $1 | cut -d '=' -f 2)
echo "Testing with input files $input_files against output in $output_dir"
echo -n "Checking number of output files..."
[ $num_output -eq $(ls $output_dir | wc -l) ] && echo "PASS" || echo "FAIL"
echo "Checking if output in sorted order..."
for out in $(ls $output_dir); do
echo -n " $output_dir/$out "
diff -u <(LC_COLLATE=c sort $output_dir/$out) $output_dir/$out && echo "PASS" || echo "FAIL"
done
echo -n "Checking final output..."
diff -u <(awk '{print}' $input_files | sed 's/\.//g' | tr ' ' '\n' | sed '/^$/d' | LC_COLLATE=c sort | uniq -c | awk '{print $2 " " $1}') <(awk '{print}' $output_dir/* | LC_COLLATE=c sort) && echo "PASS" || echo "FAIL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment