guptarohit / asciigraph

Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
https://pkg.go.dev/github.com/guptarohit/asciigraph
BSD 3-Clause "New" or "Revised" License
2.64k stars 99 forks source link

Add tests for CLI #42

Open guptarohit opened 1 year ago

guptarohit commented 1 year ago

We should have tests for CLI as well

KarlHeitmann commented 1 year ago

Do you have any idea on how to make the tests for CLI? I am quite new to go, I've done some testing on Rust, and I took a look at asciigraph_test.go file and understand how it works. But how can I test the for s.Scan() { ... } block on line 104? Do you have any resource or example I can take as source of inspiration? Would you like to test the flags passed to CLI are doing the right thing?

guptarohit commented 1 year ago

This would be tricky, possibly we have to redirect stdin & stdout. Redirect os.stdout to some in-memory buffer or temp file maybe? And similarly, pass out input test data to os.stdin. Unfortunately atm I don't have any related resource for it, but if I find anything related to it I'll share here. Yes, testing flags as well would be good idea.