Introduce TestWriteDeclsAndStmts
I wanted a way to quickly add example gomacro files as test cases.
This change adds TestWriteDeclsAndStmts that essentially constructs a new fast interpreter, calls EvalFile and then WriteDeclsToFile. The testdata directory is searched for test cases; every test case must have a .gomacro file, a .go file and optionally a .err file. The .gomacro file will be passed to EvalFile and its resulting error will be compared against contents of any .err file. Then the contents of the .go file will be compared to the output of WriteDeclsToStream. To create a test just add the .gomacro file and then go test can be called with the UPDATE_SNAPSHOTS envvar set, e.g.
UPDATE_SNAPSHOTS=on go test ./cmd -run=TestWriteDeclsAndStmts
This will call EvalFile and WriteDeclsToFile and generate the .go and .err files. Note the tests will fail because we are generating, not testing against the fixture.
The first test added is failing and demonstrates issue #84, so that issue should be resolved before merging.
I've just notice that you've made use of the 'golden file' pattern in printer_test.go (or I suspect you've copy'n'pasted from the go standard lib). Would it be better to rename the go files to golden files?
Also, what are your thoughts on pulling in the third party package, github.com/kylelemons/godebug/diff? (It's okay to say, no more third party packages, you've done a great job keeping the external deps small, it seems frivolous to add one just for some pretty diffs in a test.)
I've just realised that it's very important to limit the dependencies of gomacro (see comment on #82). So I'll pull it out and just use the diff function here.
The gomacro/go/printer package is just a fork of the go/printer package from std library. I did not bother to update its tests.