github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/compileopts/target_test.go (about) 1 package compileopts 2 3 import ( 4 "errors" 5 "io/fs" 6 "reflect" 7 "testing" 8 ) 9 10 func TestLoadTarget(t *testing.T) { 11 _, err := LoadTarget(&Options{Target: "arduino"}) 12 if err != nil { 13 t.Error("LoadTarget test failed:", err) 14 } 15 16 _, err = LoadTarget(&Options{Target: "notexist"}) 17 if err == nil { 18 t.Error("LoadTarget should have failed with non existing target") 19 } 20 21 if !errors.Is(err, fs.ErrNotExist) { 22 t.Error("LoadTarget failed for wrong reason:", err) 23 } 24 } 25 26 func TestOverrideProperties(t *testing.T) { 27 baseAutoStackSize := true 28 base := &TargetSpec{ 29 GOOS: "baseGoos", 30 CPU: "baseCpu", 31 CFlags: []string{"-base-foo", "-base-bar"}, 32 BuildTags: []string{"bt1", "bt2"}, 33 DefaultStackSize: 42, 34 AutoStackSize: &baseAutoStackSize, 35 } 36 childAutoStackSize := false 37 child := &TargetSpec{ 38 GOOS: "", 39 CPU: "chlidCpu", 40 CFlags: []string{"-child-foo", "-child-bar"}, 41 AutoStackSize: &childAutoStackSize, 42 DefaultStackSize: 64, 43 } 44 45 base.overrideProperties(child) 46 47 if base.GOOS != "baseGoos" { 48 t.Errorf("Overriding failed : got %v", base.GOOS) 49 } 50 if base.CPU != "chlidCpu" { 51 t.Errorf("Overriding failed : got %v", base.CPU) 52 } 53 if !reflect.DeepEqual(base.CFlags, []string{"-base-foo", "-base-bar", "-child-foo", "-child-bar"}) { 54 t.Errorf("Overriding failed : got %v", base.CFlags) 55 } 56 if !reflect.DeepEqual(base.BuildTags, []string{"bt1", "bt2"}) { 57 t.Errorf("Overriding failed : got %v", base.BuildTags) 58 } 59 if *base.AutoStackSize != false { 60 t.Errorf("Overriding failed : got %v", base.AutoStackSize) 61 } 62 if base.DefaultStackSize != 64 { 63 t.Errorf("Overriding failed : got %v", base.DefaultStackSize) 64 } 65 66 baseAutoStackSize = true 67 base = &TargetSpec{ 68 AutoStackSize: &baseAutoStackSize, 69 DefaultStackSize: 42, 70 } 71 child = &TargetSpec{ 72 AutoStackSize: nil, 73 DefaultStackSize: 0, 74 } 75 base.overrideProperties(child) 76 if *base.AutoStackSize != true { 77 t.Errorf("Overriding failed : got %v", base.AutoStackSize) 78 } 79 if base.DefaultStackSize != 42 { 80 t.Errorf("Overriding failed : got %v", base.DefaultStackSize) 81 } 82 83 }