@@ -26,7 +26,7 @@ type TestConfig struct {
2626
2727 // Execution phase for this test. Tests run in ascending phase order.
2828 // Phase is not inherited from parent test.toml files. Default is 0.
29- Phase int
29+ Phase int `inherit:"false"`
3030
3131 // Which OSes the test is enabled on. Each string is compared against runtime.GOOS.
3232 // If absent, default to true.
@@ -224,11 +224,7 @@ func LoadConfig(t *testing.T, dir string) (TestConfig, string) {
224224 }
225225 }
226226
227- if hasLeafConfig {
228- result .Phase = leafConfig .Phase
229- } else {
230- result .Phase = 0
231- }
227+ restoreNonInheritable (& result , leafConfig , hasLeafConfig )
232228
233229 // Always ignore .cache directory (used by local cache)
234230 result .Ignore = append (result .Ignore , ".cache" )
@@ -276,6 +272,24 @@ func DoLoadConfig(t *testing.T, path string) TestConfig {
276272 return config
277273}
278274
275+ // restoreNonInheritable resets fields tagged with `inherit:"false"` to their leaf config values.
276+ // If there is no leaf config, those fields are reset to their zero value.
277+ func restoreNonInheritable (result * TestConfig , leafConfig TestConfig , hasLeafConfig bool ) {
278+ typ := reflect .TypeFor [TestConfig ]()
279+ val := reflect .ValueOf (result ).Elem ()
280+ leafVal := reflect .ValueOf (leafConfig )
281+ for i := range typ .NumField () {
282+ field := typ .Field (i )
283+ if field .Tag .Get ("inherit" ) == "false" {
284+ if hasLeafConfig {
285+ val .Field (i ).Set (leafVal .Field (i ))
286+ } else {
287+ val .Field (i ).SetZero ()
288+ }
289+ }
290+ }
291+ }
292+
279293// mapTransformer is a mergo transformer that merges two maps
280294// by overriding values in the destination map with values from the source map.
281295//
0 commit comments