MCPcopy
hub / github.com/rclone/rclone / TestMain

Function TestMain

cmdtest/cmdtest_test.go:23–40  ·  view source on GitHub ↗

TestMain is initially called by go test to initiate the testing. TestMain is also called during the tests to start rclone main in a fresh context (using exec.Command). The context is determined by setting/finding the environment variable RCLONE_TEST_MAIN

(m *testing.M)

Source from the content-addressed store, hash-verified

21// TestMain is also called during the tests to start rclone main in a fresh context (using exec.Command).
22// The context is determined by setting/finding the environment variable RCLONE_TEST_MAIN
23func TestMain(m *testing.M) {
24 _, found := os.LookupEnv(rcloneTestMain)
25 if !found {
26 // started by Go test => execute tests
27 err := os.Setenv(rcloneTestMain, "true")
28 if err != nil {
29 fs.Fatalf(nil, "Unable to set %s: %s", rcloneTestMain, err.Error())
30 }
31 os.Exit(m.Run())
32 } else {
33 // started by func rcloneExecMain => call rclone main in cmdtest.go
34 err := os.Unsetenv(rcloneTestMain)
35 if err != nil {
36 fs.Fatalf(nil, "Unable to unset %s: %s", rcloneTestMain, err.Error())
37 }
38 main()
39 }
40}
41
42const rcloneTestMain = "RCLONE_TEST_MAIN"
43

Callers

nothing calls this directly

Calls 6

FatalfFunction · 0.92
ExitMethod · 0.80
mainFunction · 0.70
SetenvMethod · 0.65
ErrorMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…