Debian Codegraph @

patch.go

raw
1 // Licensed under the MIT license, see LICENSE file for details.
2
3 package qt
4
5 import "testing"
6
7 // Patch sets a variable to a temporary value for the duration of the test.
8 //
9 // It sets the value pointed to by the given destination to the given
10 // value, which must be assignable to the element type of the destination.
11 //
12 // At the end of the test (see "Deferred execution" in the package docs), the
13 // destination is set back to its original value.
14 func Patch[T any](tb testing.TB, dest *T, value T) {
15 old := *dest
16 *dest = value
17 tb.Cleanup(func() {
18 *dest = old
19 })
20 }