File: patch_go1.17.go

package info (click to toggle)
golang-github-frankban-quicktest 1.14.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: makefile: 2
file content (27 lines) | stat: -rw-r--r-- 641 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Licensed under the MIT license, see LICENSE file for details.

//go:build !go1.17
// +build !go1.17

package quicktest

import "os"

// Setenv sets an environment variable to a temporary value for the
// duration of the test.
//
// At the end of the test (see "Deferred execution" in the package docs), the
// environment variable is returned to its original value.
//
// This is the equivalent of testing.T.Setenv introduced in Go 1.17.
func (c *C) Setenv(name, val string) {
	oldVal, oldOK := os.LookupEnv(name)
	os.Setenv(name, val)
	c.cleanup(func() {
		if oldOK {
			os.Setenv(name, oldVal)
		} else {
			os.Unsetenv(name)
		}
	})
}