What tools are there to test the black box using stdin/stdout?

I need a tool to conduct unit testing of the same program written in different languages. To write every time the code tests for it in each language, first, long, and secondly, what is worse, is prone to errors in the tests. I want a guarantee that all versions of the program work identically, and if the tests are different, it is impossible to guarantee.

My idea is to make tests in groups of:

  • program keys;
  • input data read program from stdin;
  • the output data recorded by the program to stdout.


For example, some tests for utility wc:

[test of words]
options=-w
input=one two three
output=3

[test of characters]
options=-c
input=one two three
output=13


And challenge test data:

$ some-utility --tests=wc_tests.--ini command=wc

Yes, I understand that to write such a tool easier. However, it is better to use an existing, well-functioning and maintainable solution than creating a regular bike.
July 8th 19 at 12:17
1 answer
July 8th 19 at 12:19
Solution
Found a solution: Bats (Bash Automated Testing System). It is a system of unit-testing scripts in bash and console utilities. Allows you to do what I wanted and much more.

The example in question, Bats will look like the following (file test.bats):

#!/usr/bin/env bats

@test "a test of words" {
 result="`printf 'one two three' | wc-w`"
 [[ "$result" == 3 ]]
}

@test "a test of characters" {
 result="`printf 'one two three' | wc-c`"
 [[ "$result" == 13 ]]
}


Run:

$ bats test.bats

Conclusion:

✓ test of words
✓ test of characters

2 tests, 0 failures

Find more questions by tags Modular testing