开发者

Program Interaction and testing via bash script

开发者 https://www.devze.com 2022-12-19 01:53 出处:网络
I\'ve just completed the coding section of simple homework assignment for my C++ class.The second part of the assignment requires us to verify our code\'s input validation.(The program takes several d

I've just completed the coding section of simple homework assignment for my C++ class. The second part of the assignment requires us to verify our code's input validation. (The program takes several different values as inputs from a user and prints those values to a file)

I was hoping that I could use bash script for this. Is there any way to use bash sc开发者_如何学运维ript to run and interact with a program? How can I put the program's output into a variable (note that program has a series of input requests and outputs).

Thanks


To build on @Travis' answer, create two files: one holds your inputs (input.txt) and one holds the expected output (expected_output.txt). Then do the following:

./myprogram <input.txt >output.txt
diff output.txt expected_output.txt

If the diff command has any output, there's a problem.


You can do much of this with a shell script but you might want to consider using some other testing tools instead like CppUnit or expect.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号