### Write a test Source: https://github.com/bradleyjkemp/cupaloy/blob/master/README.md Example of writing a test case using cupaloy.SnapshotT to capture and compare test output against a snapshot. ```golang func TestParsing(t *testing.T) { ast := ParseFile("test_input") // check that the result is the same as the last time the snapshot was updated // if the result has changed (e.g. because the behaviour of the parser has changed) // then the test will be failed with an error containing a diff of the changes cupaloy.SnapshotT(t, ast) } ``` -------------------------------- ### Table driven tests Source: https://github.com/bradleyjkemp/cupaloy/blob/master/README.md Example demonstrating how to use cupaloy.SnapshotT within table-driven tests to snapshot the result of each test case. ```golang var testCases = map[string][]string{ "TestCaseOne": []string{......}, "AnotherTestCase": []string{......}, .... } func TestCases(t *testing.T) { for testName, args := range testCases { t.Run(testName, func(t *testing.T) { result := functionUnderTest(args...) cupaloy.SnapshotT(t, result) }) } } ``` -------------------------------- ### Changing output directory Source: https://github.com/bradleyjkemp/cupaloy/blob/master/README.md Example of creating a new cupaloy snapshotter with a custom subdirectory for storing snapshots and then using it to snapshot a result. ```golang func TestSubdirectory(t *testing.T) { result := someFunction() snapshotter := cupaloy.New(cupaloy.SnapshotSubdirectory("testdata")) err := snapshotter.Snapshot(result) if err != nil { t.Fatalf("error: %s", err) } } ``` -------------------------------- ### Update a snapshot Source: https://github.com/bradleyjkemp/cupaloy/blob/master/README.md Command to update snapshot files by setting the UPDATE_SNAPSHOTS environment variable and re-running tests. ```bash UPDATE_SNAPSHOTS=true go test ./... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.