compiler: ensure that any passed in target, if it does not point to a .json file, is a full LLVM triple
Signed-off-by: Ron Evans <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
86b888fdcb
коммит
a5fb785334
2 изменённых файлов: 20 добавлений и 1 удалений
|
@ -206,7 +206,7 @@ func LoadTarget(target string) (*TargetSpec, error) {
|
||||||
// Load target from given triple, ignore GOOS/GOARCH environment
|
// Load target from given triple, ignore GOOS/GOARCH environment
|
||||||
// variables.
|
// variables.
|
||||||
tripleSplit := strings.Split(target, "-")
|
tripleSplit := strings.Split(target, "-")
|
||||||
if len(tripleSplit) == 1 {
|
if len(tripleSplit) < 3 {
|
||||||
return nil, errors.New("expected a full LLVM target or a custom target in -target flag")
|
return nil, errors.New("expected a full LLVM target or a custom target in -target flag")
|
||||||
}
|
}
|
||||||
goos := tripleSplit[2]
|
goos := tripleSplit[2]
|
||||||
|
|
19
target_test.go
Обычный файл
19
target_test.go
Обычный файл
|
@ -0,0 +1,19 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestLoadTarget(t *testing.T) {
|
||||||
|
_, err := LoadTarget("arduino")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("LoadTarget test failed:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = LoadTarget("notexist")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("LoadTarget should have failed with non existing target")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != "expected a full LLVM target or a custom target in -target flag" {
|
||||||
|
t.Error("LoadTarget failed for wrong reason:", err)
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче