Documentation ¶
Overview ¶
Package dataloc provides functionality to find the source code location of table-driven test cases.
Example ¶
package main import ( "fmt" "github.com/motemen/go-testutil/dataloc" ) func main() { testcases := []struct { name string a, b int sum int }{ { name: "100+200", a: 100, b: 200, sum: -1, }, { name: "1+1", a: 1, b: 1, sum: 99, }, } for _, testcase := range testcases { if expected, got := testcase.sum, testcase.a+testcase.b; got != expected { fmt.Printf("expected %d but got %d, test case at %s\n", expected, got, dataloc.L(testcase.name)) } } }
Output: expected -1 but got 300, test case at example_test.go:15 expected 99 but got 2, test case at example_test.go:21
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func L ¶
L returns the source code location of the test case identified by its name. It attempts runtime source code analysis to find the location by using the expression passed to dataloc.L(). So some restrictions apply:
- The function must be invoked as "dataloc.L".
- The argument must be an expression of the form "dataloc.L(testcase.key)" , where "testcase" is a variable declared as "for _, testcase := range testcases" , and "testcases" is a slice of a struct type , whose "key" field is a string which is passsed to L().
- or "dataloc.L(key)" , where key is a variable declared as "for key, value := range testcases" , and "testcases" is a map of string to any type , and "key" is the string which is passed to L().
See Example.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.