Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Crocmagnon committed Jul 12, 2024
1 parent f35e8a2 commit 0d95004
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions testdata/src/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,59 @@ func example() {
ctx = wrapContext(ctx) // want "nested context in loop"
break
}

for {
err := doSomething()
if err != nil {
ctx = wrapContext(ctx) // want "nested context in loop"
}

break
}

for {
err := doSomething()
if err != nil {
if true {
ctx = wrapContext(ctx) // want "nested context in loop"
}
}

break
}

for {
ctx := wrapContext(ctx)

err := doSomething()
if err != nil {
ctx = wrapContext(ctx)
}

break
}

for {
err := doSomething()
if err != nil {
ctx := wrapContext(ctx)
ctx = wrapContext(ctx)
}

ctx = wrapContext(ctx) // want "nested context in loop"

break
}
}

func wrapContext(ctx context.Context) context.Context {
return context.WithoutCancel(ctx)
}

func doSomething() error {
return nil
}

// storing contexts in a struct isn't recommended, but local copies of a non-pointer struct should act like local copies of a context.
func inStructs(ctx context.Context) {
for i := 0; i < 10; i++ {
Expand Down

0 comments on commit 0d95004

Please sign in to comment.