test: 3 attempts to avoid clang errors
This commit is contained in:
@@ -9,24 +9,45 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func mockRun(args []string, cfg *Config) {
|
func mockRun(args []string, cfg *Config) {
|
||||||
mockable.EnableMock()
|
const maxAttempts = 3
|
||||||
defer func() {
|
var lastErr error
|
||||||
if r := recover(); r != nil {
|
var lastPanic interface{}
|
||||||
if r != "exit" {
|
for attempt := 0; attempt < maxAttempts; attempt++ {
|
||||||
panic(r)
|
mockable.EnableMock()
|
||||||
} else {
|
func() {
|
||||||
exitCode := mockable.ExitCode()
|
defer func() {
|
||||||
if (exitCode != 0) != false {
|
if r := recover(); r != nil {
|
||||||
panic(fmt.Errorf("got exit code %d", exitCode))
|
if r != "exit" {
|
||||||
|
lastPanic = r
|
||||||
|
} else {
|
||||||
|
exitCode := mockable.ExitCode()
|
||||||
|
if (exitCode != 0) != false {
|
||||||
|
lastPanic = fmt.Errorf("got exit code %d", exitCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
file, _ := os.CreateTemp("", "llgo-*")
|
||||||
|
cfg.OutFile = file.Name()
|
||||||
|
file.Close()
|
||||||
|
defer os.Remove(cfg.OutFile)
|
||||||
|
_, err := Do(args, cfg)
|
||||||
|
if err == nil {
|
||||||
|
return // Success, return immediately from the inner function
|
||||||
}
|
}
|
||||||
|
lastErr = err
|
||||||
|
}()
|
||||||
|
|
||||||
|
if lastPanic == nil && lastErr == nil {
|
||||||
|
return // Success, return from mockRun
|
||||||
}
|
}
|
||||||
}()
|
// Continue to next attempt if this one failed
|
||||||
file, _ := os.CreateTemp("", "llgo-*")
|
}
|
||||||
cfg.OutFile = file.Name()
|
// If we get here, all attempts failed
|
||||||
file.Close()
|
if lastPanic != nil {
|
||||||
defer os.Remove(cfg.OutFile)
|
panic(lastPanic)
|
||||||
Do(args, cfg)
|
}
|
||||||
|
panic(fmt.Errorf("all %d attempts failed, last error: %v", maxAttempts, lastErr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRun(t *testing.T) {
|
func TestRun(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user