Run prepares and executes the test, and any possible subtests.
(t *testing.T)
| 79 | |
| 80 | // Run prepares and executes the test, and any possible subtests. |
| 81 | func (test *Case) Run(t *testing.T) { |
| 82 | t.Helper() |
| 83 | // Run the test |
| 84 | //nolint:thelper |
| 85 | testRun := func(subT *testing.T) { |
| 86 | subT.Helper() |
| 87 | |
| 88 | silentT := assertive.WithSilentSuccess(subT) |
| 89 | |
| 90 | assertive.True(silentT, test.t == nil, "You cannot run a test multiple times") |
| 91 | assertive.True(silentT, test.Description != "" || test.parent == nil, |
| 92 | "A subtest description cannot be empty") |
| 93 | assertive.True(silentT, test.Command == nil || test.Expected != nil, |
| 94 | "Expectations for a test command cannot be nil. You may want to use `Setup` instead"+ |
| 95 | "of `Command`.") |
| 96 | |
| 97 | // Attach testing.T |
| 98 | test.t = subT |
| 99 | |
| 100 | // Ensure we have env |
| 101 | if test.Env == nil { |
| 102 | test.Env = map[string]string{} |
| 103 | } |
| 104 | |
| 105 | // If we have a parent, get parent env, data and config |
| 106 | var parentData Data |
| 107 | |
| 108 | var parentConfig Config |
| 109 | |
| 110 | if test.parent != nil { |
| 111 | parentData = test.parent.Data |
| 112 | parentConfig = test.parent.Config |
| 113 | |
| 114 | for k, v := range test.parent.Env { |
| 115 | if _, ok := test.Env[k]; !ok { |
| 116 | test.Env[k] = v |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // Inherit and attach Data and Config |
| 122 | test.Data = newData(test.t, test.Data, parentData) |
| 123 | test.Config = configureConfig(test.Config, parentConfig) |
| 124 | |
| 125 | var custCom CustomizableCommand |
| 126 | if registeredTestable == nil { |
| 127 | custCom = NewGenericCommand() |
| 128 | } else { |
| 129 | custCom = registeredTestable.CustomCommand(test, test.t) |
| 130 | } |
| 131 | |
| 132 | // Separate cwd from the temp directory |
| 133 | custCom.WithCwd(test.t.TempDir()) |
| 134 | custCom.withT(test.t) |
| 135 | // Set the command tempdir to another temp location. |
| 136 | // This is required for the current extension mechanism to allow creation of command dependent configuration |
| 137 | // assets. Note that this is a different location than both CWD and Data.Temp().Path(). |
| 138 | custCom.withTempDir(test.t.TempDir()) |