From 1f69d0370189c8b126a66e4b4a6bf6e86b293ab4 Mon Sep 17 00:00:00 2001 From: zacatac Date: Thu, 25 Oct 2018 00:40:56 -0700 Subject: [PATCH 1/7] Remove isNaked consideration from templates --- internal/render/bindata/esc.go | 89 +++++++++++++++------- internal/render/templates/function.tmpl | 2 +- testdata/bad_customtemplates/function.tmpl | 2 +- testdata/customtemplates/function.tmpl | 2 +- 4 files changed, 65 insertions(+), 30 deletions(-) diff --git a/internal/render/bindata/esc.go b/internal/render/bindata/esc.go index 8e54710..b60db00 100644 --- a/internal/render/bindata/esc.go +++ b/internal/render/bindata/esc.go @@ -6,6 +6,8 @@ import ( "bytes" "compress/gzip" "encoding/base64" + "fmt" + "io" "io/ioutil" "net/http" "os" @@ -100,7 +102,24 @@ func (f *_escFile) Close() error { } func (f *_escFile) Readdir(count int) ([]os.FileInfo, error) { - return nil, nil + if !f.isDir { + return nil, fmt.Errorf(" escFile.Readdir: '%s' is not directory", f.name) + } + + fis, ok := _escDirs[f.local] + if !ok { + return nil, fmt.Errorf(" escFile.Readdir: '%s' is directory, but we have no info about content of this dir, local=%s", f.name, f.local) + } + limit := count + if count <= 0 || limit > len(fis) { + limit = len(fis) + } + + if len(fis) == 0 && count > 0 { + return nil, io.EOF + } + + return []os.FileInfo(fis[0:limit]), nil } func (f *_escFile) Stat() (os.FileInfo, error) { @@ -191,9 +210,10 @@ func FSMustString(useLocal bool, name string) string { var _escData = map[string]*_escFile{ "/templates/call.tmpl": { + name: "call.tmpl", local: "templates/call.tmpl", size: 241, - modtime: 1532208007, + modtime: 1540446832, compressed: ` H4sIAAAAAAAC/0SOQWrDQAxFryKMFy0YHaDQA3hTSlvatRjLrsCeFo2SEITuHsY4mdWHP2/el/vEs2SG LtG6dhHuF7FfwA9OLGfW2sgM+c8Ax/JpekoWYYbunKf6eicBI1qLb7RxxJO7Ul4Yehmg5xVeXgHfSWlj @@ -202,30 +222,32 @@ Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= }, "/templates/function.tmpl": { + name: "function.tmpl", local: "templates/function.tmpl", - size: 2375, - modtime: 1532208007, + size: 2347, + modtime: 1540453194, compressed: ` -H4sIAAAAAAAC/7RWTU/jOhRdJ7/iUgFqn4rZF3XxELynt3h0VNCwGI1GJr3pWOM6HfsGVFn+7yM7zmdT -hs2wIMn1xzk+9xyDtRvMhUKY5KXKSBRq4lxq7RWc57BYAnMuTf0QWMue0NAD36FzU4K/CA0JtWVPM7Bp -4pe8CfoObI0ZilfUzqVJKIsc2H/mkXSZUSg21X8Eyo2pagkd9gh5qIAJk/2+cbbmaouDBYm14duTDPQO -e4xDfgmqTfxqMOtS533w6ln5Y37imu+QUAewQI3rbY9Yh9bxigAYSkfsOoh9fC+o8aJ/+dqBUXyHHlao -bVw8InPNnatNq/VAriht9WgUkabVrN7yWNAT4r0jWZIEvfyvkTUd3dZoSkmmxnnmit6TrIFcI5VamXut -i6jBG1d0rzW8FIUc6OyFvL6Gp9XdagF/bzbgtYaMGzQstCEvNFgrclAFeQUf+A/cOAff5kDke2Jt2Csy -r1plU4g/NanH8qUaco7YulRTIuYbOAefoWFqIFKEq1blseaeSNFRywLN0I7DHsNkrp27jNSjoOwzlyU6 -Z+stToQrsZZVYV8AEatswzqRm7cbtFFLRvJ39BHxRhJTH/NZC2pO30vSYgmXLwdCw27LPEdtPwIYkzEN -zV0peeiaZ3ZcXykMKs2gYUa420tOCBNdGXYC53mwaTuScSmr8ikWI65NRB67NiTmHKDWVVfHQG4aU079 -vLMlKCFn/knE6jDENhMLW+bTSXevHRrDtxiPgn4GLOHidQ718ovXybwHL9S+bA6PWs87YLPWEfWl0Et3 -GBvERIcDW1tdRFmhSKgS48HGHPaupY4hT3kqqP5vQW1wGo+xx3DbTmc3nSmVqt37qfWdNBgxbrkRWefv -UNPc83zMXz6UPQ5dnaVQOGz0h/n8IfwzjbnEjNgd4v7+Z8nltNlh3ic06zJquvcRH9aEI9n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pl": { + name: "header.tmpl", local: "templates/header.tmpl", size: 142, - modtime: 1532208053, + modtime: 1540452831, compressed: ` H4sIAAAAAAAC/0TMMQ7CMAyF4d2nsDrBQC7BxIK4gkUebYXiViGb9e6OlAi6/bL1voiM1+rQaYFl1ImU iGo+Q9N1KwXePmRE6g941gspuz3fNkMj0mMkKbKWfatNT4dw65cB3K2AHJO2/DhSzv/6BgAA///GzMM9 @@ -234,9 +256,10 @@ jgAAAA== }, "/templates/inline.tmpl": { + name: "inline.tmpl", local: "templates/inline.tmpl", size: 49, - modtime: 1532202343, + modtime: 1540446006, compressed: ` H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA //+q60H/MQAAAA== @@ -244,9 +267,10 @@ H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA }, "/templates/inputs.tmpl": { + name: "inputs.tmpl", local: "templates/inputs.tmpl", size: 152, - modtime: 1532208007, + modtime: 1540446821, compressed: ` H4sIAAAAAAAC/0yNMQoCQQxFrxKWLSUHEDyAneAJIptZptgomWz1yd1lRoupEh7/vw9sWqopLdU+Z7Ql E1gLXW/E/a2F7B3Ez/MV2qJlRrDJoRcC1LZ/Zi388GpxH5IOXWzXwcXl0FD/dcX3xsCgfWLyzOcbAAD/ @@ -255,9 +279,10 @@ E1gLXW/E/a2F7B3Ez/MV2qJlRrDJoRcC1LZ/Zi388GpxH5IOXWzXwcXl0FD/dcX3xsCgfWLyzOcbAAD/ }, "/templates/message.tmpl": { + name: "message.tmpl", local: "templates/message.tmpl", size: 201, - modtime: 1532208007, + modtime: 1540446006, compressed: ` H4sIAAAAAAAC/zyN4WqDQBCE//sUiyi0oPsAhT5A/xRpS/9f4mgW9GLuTkNY9t2DB/HXDDPDN6o9BvGg ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 @@ -266,9 +291,10 @@ ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 }, "/templates/results.tmpl": { + name: "results.tmpl", local: "templates/results.tmpl", size: 168, - modtime: 1532208007, + modtime: 1540446006, compressed: ` H4sIAAAAAAAC/1yNTQrCQAyFr/Iosyw9gOBS3HsDoRkJlAy8ma5C7i6pRcFVfr4vee6rVDXBROn7NvoU AXc+7SUoOqPIhssVy+ODI9y1omjEDHexNTf3NrBkc85a82DstH4jG1MW8uQ4hMbv0385A3/uUd8BAAD/ @@ -276,13 +302,22 @@ AXc+7SUoOqPIhssVy+ODI9y1omjEDHexNTf3NrBkc85a82DstH4jG1MW8uQ4hMbv0385A3/uUd8BAAD/ `, }, - "/": { + "/templates": { + name: "templates", + local: `templates`, isDir: true, - local: "", }, +} - "/templates": { - isDir: true, - local: "templates", +var _escDirs = map[string][]os.FileInfo{ + + "templates": { + _escData["/templates/call.tmpl"], + _escData["/templates/function.tmpl"], + _escData["/templates/header.tmpl"], + _escData["/templates/inline.tmpl"], + _escData["/templates/inputs.tmpl"], + _escData["/templates/message.tmpl"], + _escData["/templates/results.tmpl"], }, } diff --git a/internal/render/templates/function.tmpl b/internal/render/templates/function.tmpl index fa1e59c..1b25c3e 100644 --- a/internal/render/templates/function.tmpl +++ b/internal/render/templates/function.tmpl @@ -41,7 +41,7 @@ func {{.TestName}}(t *testing.T) { }{ // TODO: Add test cases. } - for {{if not .IsNaked}} _, tt := {{end}} range tests { + for _, tt := range tests { {{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} {{- with .Receiver}} {{- if .IsStruct}} diff --git a/testdata/bad_customtemplates/function.tmpl b/testdata/bad_customtemplates/function.tmpl index 062b265..3adab1d 100644 --- a/testdata/bad_customtemplates/function.tmpl +++ b/testdata/bad_customtemplates/function.tmpl @@ -41,7 +41,7 @@ func {{.TestName}}(t *testing.T) { }{ // TODO: Add test cases. } - for {{if not .IsNaked}} _, tt := {{end}} range testCases { + for _, tt := range testCases { {{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} {{- with .Receiver}} {{- if .IsStruct}} diff --git a/testdata/customtemplates/function.tmpl b/testdata/customtemplates/function.tmpl index 062b265..3adab1d 100644 --- a/testdata/customtemplates/function.tmpl +++ b/testdata/customtemplates/function.tmpl @@ -41,7 +41,7 @@ func {{.TestName}}(t *testing.T) { }{ // TODO: Add test cases. } - for {{if not .IsNaked}} _, tt := {{end}} range testCases { + for _, tt := range testCases { {{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} {{- with .Receiver}} {{- if .IsStruct}} From 4526e50d4bc91b93a2ce61b8bf9f02a8d7e6514e Mon Sep 17 00:00:00 2001 From: zacatac Date: Thu, 25 Oct 2018 09:21:49 -0700 Subject: [PATCH 2/7] Consider subtest and nosubtest case --- internal/render/bindata/esc.go | 32 ++++++++++++------------- internal/render/templates/function.tmpl | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/internal/render/bindata/esc.go b/internal/render/bindata/esc.go index b60db00..78e11b3 100644 --- a/internal/render/bindata/esc.go +++ b/internal/render/bindata/esc.go @@ -224,22 +224,22 @@ Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= "/templates/function.tmpl": { name: "function.tmpl", local: "templates/function.tmpl", - size: 2347, - modtime: 1540453194, + size: 2392, + modtime: 1540483824, compressed: ` -H4sIAAAAAAAC/7RWT08bPxA9736KIQKU/BTMPSiHH4JWPbSpAiqHqqrMZja15HhTexYUWf7ulb3ev9lQ -LuVAsuM/782b9xas3WAuFMIkL1VGolAT51Jrr+A8h8USmHNp6pfAWvaIhr7wHTo3JfiP0JBQW/Y4A5sm -/siroF/A1piheEHtXJqEssiBfTIPpMuMQrGpfhAoN6aqJXTYI+ShAiZ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v8RAAMoTN2A8QxvhfUeNH/+HMAo/gBPaxQ ++3h4RuaWO1e7XuuJXFHa5tEpIk2vWZvyXNAL4n0gWZIEvfyvmTMD3bZoakmmxXnhij6SrIPcItVamQet +q6jBO1f0oDW8VpWc6OyFvLmB5839ZgU/7nbgtYaCGzQstKGsNFgrSsgqDeypfm2akamKvKCP/B/c5blz +8NcSiHyTrA3JYynNdptC/GlZdpmcI7atVUbEfEeX4IdqOkYQOcN1L/tcty+M1VkPA83Qn9MRw2aunfsW +qUeF2e9c1uicbVNcmLbEWtZM/wqIWOMjNpjBZZ+gn71kZiDPPiLezAi1Zb5oQV31o9FareHb64nQsLu6 +LFHbzwDGUWnau1HyNHRTfh7fKAwq5dAxIzwcJSeEhW4cvICrMvi2Xym4lE34EosZGyeijF2bEnMOUOum +q3Mgt50pM7/vyxqUkLl/ErF2OmKbiYWUZbYY5jqgMXyPsRT0O2ANX9+W0B7/+rZYjuCFOtZd8aj1cgCW +945ob4nRuIe1yZjoULC1zc1UVIqEqjEWNuewDy11DnnJU0H1nyvqB6fzGHsK12+W3w62NKoOL6zed9Jg +xLjjRhSDP0xdc6/KOX/5oRxxGOoshcJpoz/N5zvhf9FYSiyI3SMeH/6tucy6DMsxoXzIqOveZ3zYEo5k +f60liaMckY18eq/+j1Evkrz8D8PEp+ALGl7XLnVp2vr0vwAAAP//X+Qs81gJAAA= `, }, @@ -247,7 +247,7 @@ gU/BN9R9XbvUpWnt0z8BAAD//8T1AD4rCQAA name: "header.tmpl", local: "templates/header.tmpl", size: 142, - modtime: 1540452831, + modtime: 1540481163, compressed: ` H4sIAAAAAAAC/0TMMQ7CMAyF4d2nsDrBQC7BxIK4gkUebYXiViGb9e6OlAi6/bL1voiM1+rQaYFl1ImU iGo+Q9N1KwXePmRE6g941gspuz3fNkMj0mMkKbKWfatNT4dw65cB3K2AHJO2/DhSzv/6BgAA///GzMM9 diff --git a/internal/render/templates/function.tmpl b/internal/render/templates/function.tmpl index 1b25c3e..f16cf48 100644 --- a/internal/render/templates/function.tmpl +++ b/internal/render/templates/function.tmpl @@ -41,7 +41,7 @@ func {{.TestName}}(t *testing.T) { }{ // TODO: Add test cases. } - for _, tt := range tests { + for {{if (or .Subtests (not .IsNaked))}} _, tt := {{end}} range tests { {{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} {{- with .Receiver}} {{- if .IsStruct}} From b8babca589ba0deb93a0584b33f24a8def83adf4 Mon Sep 17 00:00:00 2001 From: zacatac Date: Thu, 25 Oct 2018 09:22:33 -0700 Subject: [PATCH 3/7] Update custom templates --- testdata/bad_customtemplates/function.tmpl | 2 +- testdata/customtemplates/function.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testdata/bad_customtemplates/function.tmpl b/testdata/bad_customtemplates/function.tmpl index 3adab1d..ee7753f 100644 --- a/testdata/bad_customtemplates/function.tmpl +++ b/testdata/bad_customtemplates/function.tmpl @@ -41,7 +41,7 @@ func {{.TestName}}(t *testing.T) { }{ // TODO: Add test cases. } - for _, tt := range testCases { + for {{if (or .Subtests (not .IsNaked))}} _, tt := {{end}} range tests { {{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} {{- with .Receiver}} {{- if .IsStruct}} diff --git a/testdata/customtemplates/function.tmpl b/testdata/customtemplates/function.tmpl index 3adab1d..ee7753f 100644 --- a/testdata/customtemplates/function.tmpl +++ b/testdata/customtemplates/function.tmpl @@ -41,7 +41,7 @@ func {{.TestName}}(t *testing.T) { }{ // TODO: Add test cases. } - for _, tt := range testCases { + for {{if (or .Subtests (not .IsNaked))}} _, tt := {{end}} range tests { {{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} {{- with .Receiver}} {{- if .IsStruct}} From dc1c0397032b70bc973d7f9b522d36e18a10641a Mon Sep 17 00:00:00 2001 From: zacatac Date: Thu, 25 Oct 2018 09:22:50 -0700 Subject: [PATCH 4/7] Add tests for both subtests and no subtests cases --- gotests_test.go | 16 ++++++++++ .../goldens/naked_function_with_subtests.go | 29 +++++++++++++++++++ .../naked_function_without_subtests.go | 25 ++++++++++++++++ testdata/naked_function_with_subtests.go | 9 ++++++ testdata/naked_function_without_subtests.go | 9 ++++++ 5 files changed, 88 insertions(+) create mode 100644 testdata/goldens/naked_function_with_subtests.go create mode 100644 testdata/goldens/naked_function_without_subtests.go create mode 100644 testdata/naked_function_with_subtests.go create mode 100644 testdata/naked_function_without_subtests.go diff --git a/gotests_test.go b/gotests_test.go index a429ac6..9236296 100644 --- a/gotests_test.go +++ b/gotests_test.go @@ -559,6 +559,22 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/existing_test_file_with_package_level_mixed_types_comments.go"), }, + { + name: "Naked function with subtests", + args: args{ + srcPath: "testdata/naked_function_with_subtests.go", + subtests: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/naked_function_with_subtests.go"), + }, + { + name: "Naked function without subtests", + args: args{ + srcPath: "testdata/naked_function_without_subtests.go", + subtests: false, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/naked_function_without_subtests.go"), + }, { name: "Test non existing template path", args: args{ diff --git a/testdata/goldens/naked_function_with_subtests.go b/testdata/goldens/naked_function_with_subtests.go new file mode 100644 index 0000000..ea4cb3b --- /dev/null +++ b/testdata/goldens/naked_function_with_subtests.go @@ -0,0 +1,29 @@ +package testdata + +import "testing" + +func Test_main(t *testing.T) { + tests := []struct { + name string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + main() + }) + } +} + +func Test_do(t *testing.T) { + tests := []struct { + name string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + do() + }) + } +} diff --git a/testdata/goldens/naked_function_without_subtests.go b/testdata/goldens/naked_function_without_subtests.go new file mode 100644 index 0000000..d2c829a --- /dev/null +++ b/testdata/goldens/naked_function_without_subtests.go @@ -0,0 +1,25 @@ +package testdata + +import "testing" + +func Test_main(t *testing.T) { + tests := []struct { + name string + }{ + // TODO: Add test cases. + } + for range tests { + main() + } +} + +func Test_do(t *testing.T) { + tests := []struct { + name string + }{ + // TODO: Add test cases. + } + for range tests { + do() + } +} diff --git a/testdata/naked_function_with_subtests.go b/testdata/naked_function_with_subtests.go new file mode 100644 index 0000000..3915821 --- /dev/null +++ b/testdata/naked_function_with_subtests.go @@ -0,0 +1,9 @@ +package testdata + +func main() { + do() +} + +func do() { + +} diff --git a/testdata/naked_function_without_subtests.go b/testdata/naked_function_without_subtests.go new file mode 100644 index 0000000..3915821 --- /dev/null +++ b/testdata/naked_function_without_subtests.go @@ -0,0 +1,9 @@ +package testdata + +func main() { + do() +} + +func do() { + +} From 870fe24a1cd78d9e20294da8b8481279efa55441 Mon Sep 17 00:00:00 2001 From: Zackery Field Date: Fri, 26 Oct 2018 12:27:41 -0700 Subject: [PATCH 5/7] Revert back to testCases --- testdata/bad_customtemplates/function.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testdata/bad_customtemplates/function.tmpl b/testdata/bad_customtemplates/function.tmpl index ee7753f..1fe3a85 100644 --- a/testdata/bad_customtemplates/function.tmpl +++ b/testdata/bad_customtemplates/function.tmpl @@ -41,7 +41,7 @@ func {{.TestName}}(t *testing.T) { }{ // TODO: Add test cases. } - for {{if (or .Subtests (not .IsNaked))}} _, tt := {{end}} range tests { + for {{if (or .Subtests (not .IsNaked))}} _, tt := {{end}} range testCases { {{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} {{- with .Receiver}} {{- if .IsStruct}} From f261d53f57da06335fcf851c5f02618d22d0ebac Mon Sep 17 00:00:00 2001 From: Zackery Field Date: Fri, 26 Oct 2018 12:29:06 -0700 Subject: [PATCH 6/7] Revert back to testCases --- testdata/customtemplates/function.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testdata/customtemplates/function.tmpl b/testdata/customtemplates/function.tmpl index ee7753f..1fe3a85 100644 --- a/testdata/customtemplates/function.tmpl +++ b/testdata/customtemplates/function.tmpl @@ -41,7 +41,7 @@ func {{.TestName}}(t *testing.T) { }{ // TODO: Add test cases. } - for {{if (or .Subtests (not .IsNaked))}} _, tt := {{end}} range tests { + for {{if (or .Subtests (not .IsNaked))}} _, tt := {{end}} range testCases { {{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} {{- with .Receiver}} {{- if .IsStruct}} From dc6d6636f64d9f2598db364e05a4ceecc1e5101b Mon Sep 17 00:00:00 2001 From: zacatac Date: Sat, 27 Oct 2018 10:02:47 -0700 Subject: [PATCH 7/7] trigger travis CI --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 92bc540..f4216ba 100644 --- a/README.md +++ b/README.md @@ -30,20 +30,20 @@ Available options: ``` -all generate go tests for all functions and methods - - -excl regexp. generate go tests for functions and methods that don't + + -excl regexp. generate go tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all - - -exported generate go tests for exported functions and methods. Takes + + -exported generate go tests for exported functions and methods. Takes precedence over -only and -all -i print test inputs in error messages - + -only regexp. generate go tests for functions and methods that match only. Takes precedence over -all - + -w write output to (test) files instead of stdout - + -nosubtests disable subtest generation. Only available for Go 1.7+ -template_dir optional. Path to a directory containing custom test code templates