0

I have a folder with test cases named like test_1_in, test_1_out, test_2_in, test_2_out etc. I want to write a script, that can test my program with these pairs, I suppose it would do something like this in a loop

diff <($program < $test_in) <($test_out)

So the question is what is the best way to do it in Bash? How to iterate through the pairs of files? And also how to capture exception, that is print some error message if diff shows some difference?

M. Twarog
  • 2,418
  • 3
  • 21
  • 39
Denisof
  • 336
  • 1
  • 10

1 Answers1

1

Iterate over *_in, and generate *_out using parameter expansions:

for test_in in test_*_in; do
  test_out="${test_in%_*}_out"
  if diff <("$program" "$test_in") "$test_out"; then
    echo "$test_in failed."
  fi
done
oguz ismail
  • 1
  • 16
  • 47
  • 69