diff options
author | Jacques Supcik <[email protected]> | 2020-09-20 13:49:16 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2020-09-20 13:49:16 +0200 |
commit | 13fe668929a54db13c0b3c7a974c51825168b00c (patch) | |
tree | 92baf505044acc820295bc8b4c2dae3a56dceed3 /compileopts/target_test.go | |
parent | 2a72262c33c793c1ded3dbbb725e97547ef28540 (diff) | |
download | tinygo-13fe668929a54db13c0b3c7a974c51825168b00c.tar.gz tinygo-13fe668929a54db13c0b3c7a974c51825168b00c.zip |
compileopts: simplify copyProperties using reflection
Diffstat (limited to 'compileopts/target_test.go')
-rw-r--r-- | compileopts/target_test.go | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/compileopts/target_test.go b/compileopts/target_test.go index 271c20eba..aa6462383 100644 --- a/compileopts/target_test.go +++ b/compileopts/target_test.go @@ -1,6 +1,9 @@ package compileopts -import "testing" +import ( + "reflect" + "testing" +) func TestLoadTarget(t *testing.T) { _, err := LoadTarget("arduino") @@ -17,3 +20,67 @@ func TestLoadTarget(t *testing.T) { t.Error("LoadTarget failed for wrong reason:", err) } } + +func TestOverrideProperties(t *testing.T) { + baseAutoStackSize := true + base := &TargetSpec{ + GOOS: "baseGoos", + CPU: "baseCpu", + Features: []string{"bf1", "bf2"}, + BuildTags: []string{"bt1", "bt2"}, + Emulator: []string{"be1", "be2"}, + DefaultStackSize: 42, + AutoStackSize: &baseAutoStackSize, + } + childAutoStackSize := false + child := &TargetSpec{ + GOOS: "", + CPU: "chlidCpu", + Features: []string{"cf1", "cf2"}, + Emulator: []string{"ce1", "ce2"}, + AutoStackSize: &childAutoStackSize, + DefaultStackSize: 64, + } + + base.overrideProperties(child) + + if base.GOOS != "baseGoos" { + t.Errorf("Overriding failed : got %v", base.GOOS) + } + if base.CPU != "chlidCpu" { + t.Errorf("Overriding failed : got %v", base.CPU) + } + if !reflect.DeepEqual(base.Features, []string{"cf1", "cf2", "bf1", "bf2"}) { + t.Errorf("Overriding failed : got %v", base.Features) + } + if !reflect.DeepEqual(base.BuildTags, []string{"bt1", "bt2"}) { + t.Errorf("Overriding failed : got %v", base.BuildTags) + } + if !reflect.DeepEqual(base.Emulator, []string{"ce1", "ce2"}) { + t.Errorf("Overriding failed : got %v", base.Emulator) + } + if *base.AutoStackSize != false { + t.Errorf("Overriding failed : got %v", base.AutoStackSize) + } + if base.DefaultStackSize != 64 { + t.Errorf("Overriding failed : got %v", base.DefaultStackSize) + } + + baseAutoStackSize = true + base = &TargetSpec{ + AutoStackSize: &baseAutoStackSize, + DefaultStackSize: 42, + } + child = &TargetSpec{ + AutoStackSize: nil, + DefaultStackSize: 0, + } + base.overrideProperties(child) + if *base.AutoStackSize != true { + t.Errorf("Overriding failed : got %v", base.AutoStackSize) + } + if base.DefaultStackSize != 42 { + t.Errorf("Overriding failed : got %v", base.DefaultStackSize) + } + +} |