forked from arduino/arduino-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools_test.go
176 lines (161 loc) · 6.3 KB
/
tools_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].
package cores
import (
"testing"
"github.com/arduino/arduino-cli/internal/arduino/resources"
"github.com/stretchr/testify/require"
)
func TestFlavorCompatibility(t *testing.T) {
type os struct {
Os string
Arch string
}
windows32 := &os{"windows", "386"}
windows64 := &os{"windows", "amd64"}
linux32 := &os{"linux", "386"}
linux64 := &os{"linux", "amd64"}
linuxArm := &os{"linux", "arm"}
linuxArmbe := &os{"linux", "armbe"}
linuxArm64 := &os{"linux", "arm64"}
linuxRiscv64 := &os{"linux", "riscv64"}
darwin32 := &os{"darwin", "386"}
darwin64 := &os{"darwin", "amd64"}
darwinArm64 := &os{"darwin", "arm64"}
freebsd32 := &os{"freebsd", "386"}
freebsd64 := &os{"freebsd", "amd64"}
oses := []*os{
windows32,
windows64,
linux32,
linux64,
linuxArm,
linuxArmbe,
linuxArm64,
linuxRiscv64,
darwin32,
darwin64,
darwinArm64,
freebsd32,
freebsd64,
}
type test struct {
Flavour *Flavor
Compatibles []*os
ExactMatch []*os
}
tests := []*test{
{&Flavor{OS: "i686-mingw32"}, []*os{windows32, windows64}, []*os{windows32}},
{&Flavor{OS: "x86_64-mingw32"}, []*os{windows64}, []*os{windows64}},
{&Flavor{OS: "i386-apple-darwin11"}, []*os{darwin32, darwin64, darwinArm64}, []*os{darwin32}},
{&Flavor{OS: "x86_64-apple-darwin"}, []*os{darwin64, darwinArm64}, []*os{darwin64}},
{&Flavor{OS: "arm64-apple-darwin"}, []*os{darwinArm64}, []*os{darwinArm64}},
// Raspberry PI, BBB or other ARM based host
// PI: "arm-linux-gnueabihf"
// Raspbian on PI2: "arm-linux-gnueabihf"
// Ubuntu Mate on PI2: "arm-linux-gnueabihf"
// Debian 7.9 on BBB: "arm-linux-gnueabihf"
// Raspbian on PI Zero: "arm-linux-gnueabihf"
{&Flavor{OS: "arm-linux-gnueabihf"}, []*os{linuxArm, linuxArmbe}, []*os{linuxArm, linuxArmbe}},
// Arch-linux on PI2: "armv7l-unknown-linux-gnueabihf"
{&Flavor{OS: "armv7l-unknown-linux-gnueabihf"}, []*os{linuxArm, linuxArmbe}, []*os{linuxArm, linuxArmbe}},
{&Flavor{OS: "i686-linux-gnu"}, []*os{linux32}, []*os{linux32}},
{&Flavor{OS: "i686-pc-linux-gnu"}, []*os{linux32}, []*os{linux32}},
{&Flavor{OS: "x86_64-linux-gnu"}, []*os{linux64}, []*os{linux64}},
{&Flavor{OS: "x86_64-pc-linux-gnu"}, []*os{linux64}, []*os{linux64}},
{&Flavor{OS: "aarch64-linux-gnu"}, []*os{linuxArm64}, []*os{linuxArm64}},
{&Flavor{OS: "arm64-linux-gnu"}, []*os{linuxArm64}, []*os{linuxArm64}},
{&Flavor{OS: "riscv64-linux-gnu"}, []*os{linuxRiscv64}, []*os{linuxRiscv64}},
}
checkCompatible := func(test *test, os *os) {
// if the os is in the "positive" set iCompatibleWith must return true...
res, _ := test.Flavour.isCompatibleWith(os.Os, os.Arch)
for _, compatibleOs := range test.Compatibles {
if compatibleOs == os {
require.True(t, res, "'%s' tag compatible with '%s,%s' pair", test.Flavour.OS, os.Os, os.Arch)
return
}
}
// ...otherwise false
require.False(t, res, "'%s' tag compatible with '%s,%s' pair", test.Flavour.OS, os.Os, os.Arch)
}
checkExactMatch := func(test *test, os *os) {
// if the os is in the "positive" set iExactMatchWith must return true...
for _, positiveOs := range test.ExactMatch {
if positiveOs == os {
require.True(t, test.Flavour.isExactMatchWith(os.Os, os.Arch), "'%s' tag exact match with '%s,%s' pair", test.Flavour.OS, os.Os, os.Arch)
return
}
}
// ...otherwise false
require.False(t, test.Flavour.isExactMatchWith(os.Os, os.Arch), "'%s' tag exact match with '%s,%s' pair", test.Flavour.OS, os.Os, os.Arch)
}
for _, test := range tests {
for _, os := range oses {
checkCompatible(test, os)
checkExactMatch(test, os)
}
}
}
func TestFlavorPrioritySelection(t *testing.T) {
res := (&ToolRelease{
Flavors: []*Flavor{
{OS: "i386-apple-darwin11", Resource: &resources.DownloadResource{ArchiveFileName: "1"}},
{OS: "x86_64-apple-darwin", Resource: &resources.DownloadResource{ArchiveFileName: "2"}},
{OS: "arm64-apple-darwin", Resource: &resources.DownloadResource{ArchiveFileName: "3"}},
},
}).GetFlavourCompatibleWith("darwin", "arm64")
require.NotNil(t, res)
require.Equal(t, "3", res.ArchiveFileName)
res = (&ToolRelease{
Flavors: []*Flavor{
{OS: "i386-apple-darwin11", Resource: &resources.DownloadResource{ArchiveFileName: "1"}},
{OS: "x86_64-apple-darwin", Resource: &resources.DownloadResource{ArchiveFileName: "2"}},
},
}).GetFlavourCompatibleWith("darwin", "arm64")
require.NotNil(t, res)
require.Equal(t, "2", res.ArchiveFileName)
res = (&ToolRelease{
Flavors: []*Flavor{
{OS: "x86_64-apple-darwin", Resource: &resources.DownloadResource{ArchiveFileName: "2"}},
{OS: "i386-apple-darwin11", Resource: &resources.DownloadResource{ArchiveFileName: "1"}},
},
}).GetFlavourCompatibleWith("darwin", "arm64")
require.NotNil(t, res)
require.Equal(t, "2", res.ArchiveFileName)
res = (&ToolRelease{
Flavors: []*Flavor{
{OS: "i386-apple-darwin11", Resource: &resources.DownloadResource{ArchiveFileName: "1"}},
},
}).GetFlavourCompatibleWith("darwin", "arm64")
require.NotNil(t, res)
require.Equal(t, "1", res.ArchiveFileName)
res = (&ToolRelease{
Flavors: []*Flavor{
{OS: "i686-mingw32", Resource: &resources.DownloadResource{ArchiveFileName: "1"}},
{OS: "x86_64-mingw32", Resource: &resources.DownloadResource{ArchiveFileName: "2"}},
},
}).GetFlavourCompatibleWith("windows", "amd64")
require.NotNil(t, res)
require.Equal(t, "2", res.ArchiveFileName)
res = (&ToolRelease{
Flavors: []*Flavor{
{OS: "x86_64-mingw32", Resource: &resources.DownloadResource{ArchiveFileName: "2"}},
{OS: "i686-mingw32", Resource: &resources.DownloadResource{ArchiveFileName: "1"}},
},
}).GetFlavourCompatibleWith("windows", "amd64")
require.NotNil(t, res)
require.Equal(t, "2", res.ArchiveFileName)
}