Brussels / 3 & 4 February 2024

schedule

Testing Go command line programs with `go-internal/testscript`


Using go-internal/testscript, a little known library of filesystem testing tools, we can test Go command-line programs within the go test framework, with a high degree of integration. Testing command-line programs feels awkward in Go. You can test the program's functions, of course, but what about making sure the whole thing works, with command line arguments, flags, and options? We can build the program and run shell scripts, but that process is cumbersome, not integrated, and easy to let errors slip by. Enters go-internal/testscript, a testing library that was designed to test the go tool itself. With it, we can test our command-line applications without leaving the 'go test' framework. The testscript environment already offers built-in commands and conditions to test our application in many ways. For the advanced user, moreover, there is the possibility of creating custom commands and checks that make the test fit our development needs properly. Attendees of this talk will learn: * how to start with testscript, by testing any command-line application, whether it is produced by your project or not; * how to integrate testscript into your project, and test the resulting binary within the test environment, without any additional steps; * how to customise testscript runs using custom commands and conditions.

Speakers

Photo of Giuseppe Maxia Giuseppe Maxia

Attachments

Links