1// Copyright 2020 The Bazel Authors. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package bzltestutil 16 17import ( 18 "fmt" 19 "os" 20 "testing" 21) 22 23func TestShouldWrap(t *testing.T) { 24 var tests = []struct { 25 envs map[string]string 26 shouldWrap bool 27 }{ 28 { 29 envs: map[string]string{ 30 "GO_TEST_WRAP": "0", 31 "XML_OUTPUT_FILE": "", 32 }, 33 shouldWrap: false, 34 }, { 35 envs: map[string]string{ 36 "GO_TEST_WRAP": "1", 37 "XML_OUTPUT_FILE": "", 38 }, 39 shouldWrap: true, 40 }, { 41 envs: map[string]string{ 42 "GO_TEST_WRAP": "", 43 "XML_OUTPUT_FILE": "path", 44 }, 45 shouldWrap: true, 46 }, 47 } 48 for _, tt := range tests { 49 t.Run(fmt.Sprintf("%v", tt.envs), func(t *testing.T) { 50 for k, v := range tt.envs { 51 if v == "" { 52 os.Unsetenv(k) 53 } else { 54 os.Setenv(k, v) 55 } 56 } 57 got := ShouldWrap() 58 if tt.shouldWrap != got { 59 t.Errorf("shouldWrap returned %t, expected %t", got, tt.shouldWrap) 60 } 61 }) 62 } 63} 64