0

So, I have this command line program binary (let's say its named ./prog) that I want to test. I want to use shunit2 as my testing framework. Unfortunately it asks the user for input. How can I test this? For example:

  1. start ./prog
  2. prog asks: Username:
  3. Check/assert that the string is the expected string (string should be accessible to shunit2)
  4. Now I need to specify an input, say John
  5. prog prints something in response, say it echoes John
  6. Check/assert that John is the expected output (string should be again accessible to shunit2)

How do I assert/verify/check this in shunit2, i.e. that the given input John results in the correct output string John?

I know there exist tools like 'expect' or 'expect-lite'. But, how would I test this using the shell only?

Or, how can I integrate expect or expect-lite so that I can verify the input using shunit2?

1
  • You wouldn't. Because you can't. Use expect. Commented Nov 19, 2013 at 12:19

1 Answer 1

1

You probably just need to pass the input to prog's stdin. Among many ways to do that is this:

{ echo "Username"; echo "John"; } | ./prog
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.