Mates, awk is so fantastic! I just cobbled this together to get an overview of all my table test cases for a certain Go function:
awk '/^func/ { p=0 } /^func TestValidateCustomFields/ { p=1 } /name:/ { if (p) { sub(/^\s+name:\s+"/, ""); sub(/",$/, ""); print } }' registration_test.go
The structure is like this:
func TestValidateCustomFields(t *testing.T) {
for _, tt := range []struct {
name string
…
}{
{
name: "<test description>",
…
},
…
} {
t.Run(tt.name, func(t *testing.T) {
…
})
}
}
It’s so handy, I should make an alias for this.