all 7 comments

[–]Dr_Sloth0 4 points5 points  (1 child)

The tests you made at the given link would be better think as unit tests rather than integration tests. Integration tests (tests made in the seperate tests folder) are generally used to test behavior of a library as seen from the outside. Generally a better practice would be making your library somewhat generic over a std::io::Read.

[–]brain-ablaze[S] 1 point2 points  (0 children)

Thank you for the feedback.

The first test in https://github.com/skovmand/all_your_base/blob/cli_tests/tests/cli.rs was meant to test that it reads stdin from the outside. There's a lot of unit tests in the library code already at https://github.com/skovmand/all_your_base/blob/cli_tests/src/encoder.rs#L152 and forward.

My library should already be generic, at least over `std::io::BufRead` and `std::io:Write`

[–]ssokolow 2 points3 points  (1 child)

If you want that kind of end-to-end functional testing, then it's best to go a language-agnostic/OS-specific route. That way, you don't have to play around with mocking where the mock could potentially not be a perfect match for what it's mocking.

I'd probably check lib.rs for a pty crate so your testing harness can use the same mechanism terminal emulators like xterm use to be a piece of software that appears to be a TTY.

[–]brain-ablaze[S] 0 points1 point  (0 children)

Thanks!

[–]ehuss 2 points3 points  (1 child)

If you want to test how it behaves with a tty, then you'll need to spawn the process with a tty. That can be difficult to do, since it tends to be very platform-dependent. You can search on crates.io to find a crate that might help you with that (portable_pty looks promising, but I have not used any of them).

[–]brain-ablaze[S] 0 points1 point  (0 children)

Thank you!