mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
fix: check if debugtalk.go contains main() function
This commit is contained in:
+24
-9
@@ -60,7 +60,10 @@ def __test_3(): # private function
|
||||
def Test5(): # exported function
|
||||
pass
|
||||
`
|
||||
names := regexPyFunctionName.findAllFunctionNames(content)
|
||||
names, err := regexPyFunctionName.findAllFunctionNames(content)
|
||||
if !assert.Nil(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
if !assert.Contains(t, names, "test_1") {
|
||||
t.FailNow()
|
||||
}
|
||||
@@ -89,10 +92,6 @@ func testFunc2() { // exported function
|
||||
return
|
||||
}
|
||||
|
||||
func main() { // private function
|
||||
return
|
||||
}
|
||||
|
||||
func init() { // private function
|
||||
return
|
||||
}
|
||||
@@ -105,16 +104,16 @@ func _Test3() { // exported function
|
||||
// return
|
||||
// }
|
||||
`
|
||||
names := regexGoFunctionName.findAllFunctionNames(content)
|
||||
names, err := regexGoFunctionName.findAllFunctionNames(content)
|
||||
if !assert.Nil(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
if !assert.Contains(t, names, "Test1") {
|
||||
t.FailNow()
|
||||
}
|
||||
if !assert.Contains(t, names, "testFunc2") {
|
||||
t.FailNow()
|
||||
}
|
||||
if !assert.NotContains(t, names, "main") {
|
||||
t.FailNow()
|
||||
}
|
||||
if !assert.NotContains(t, names, "init") {
|
||||
t.FailNow()
|
||||
}
|
||||
@@ -126,3 +125,19 @@ func _Test3() { // exported function
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindAllGoFunctionNamesAbnormal(t *testing.T) {
|
||||
content := `
|
||||
func init() { // private function
|
||||
return
|
||||
}
|
||||
|
||||
func main() { // should not define main() function
|
||||
return
|
||||
}
|
||||
`
|
||||
_, err := regexGoFunctionName.findAllFunctionNames(content)
|
||||
if !assert.NotNil(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user