xref: /aosp_15_r20/external/toolchain-utils/compiler_wrapper/command_test.go (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1// Copyright 2019 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package main
6
7import (
8	"reflect"
9	"sort"
10	"testing"
11)
12
13func TestMergeEnvValues(t *testing.T) {
14	testData := []struct {
15		values  []string
16		updates []string
17		result  []string
18	}{
19		{[]string{}, []string{}, []string{}},
20		{[]string{"A=1"}, []string{}, []string{"A=1"}},
21		{[]string{"A=1=2=3"}, []string{}, []string{"A=1=2=3"}},
22		{[]string{}, []string{"A=1"}, []string{"A=1"}},
23		{[]string{}, []string{"A=1=2=3"}, []string{"A=1=2=3"}},
24		{[]string{"A=1"}, []string{"A=2"}, []string{"A=2"}},
25		{[]string{"A="}, []string{}, []string{"A="}},
26		{[]string{"A="}, []string{"A=2"}, []string{"A=2"}},
27		{[]string{"A=1"}, []string{"A="}, []string{}},
28		{[]string{}, []string{"A=1", "A="}, []string{}},
29		{[]string{}, []string{"A=1", "A=", "A=2"}, []string{"A=2"}},
30		{[]string{"A=1", "B=2"}, []string{"C=3", "D=4"}, []string{"A=1", "B=2", "C=3", "D=4"}},
31	}
32	for _, tt := range testData {
33		result := mergeEnvValues(tt.values, tt.updates)
34		sort.Strings(result)
35		if !reflect.DeepEqual(tt.result, result) {
36			t.Errorf("unexpected result: %s", result)
37		}
38	}
39}
40