aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRon Evans <[email protected]>2019-09-18 10:43:20 +0200
committerAyke <[email protected]>2019-09-18 16:11:09 +0200
commita5fb785334d8c0b31ccc4cfa92f4976a69bd8187 (patch)
treed10eda12b78ab26840de94c2e2c460f4f1f5255d
parent86b888fdcbfd67ea792f3b073e1c1c790941eadc (diff)
downloadtinygo-a5fb785334d8c0b31ccc4cfa92f4976a69bd8187.tar.gz
tinygo-a5fb785334d8c0b31ccc4cfa92f4976a69bd8187.zip
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 <[email protected]>
-rw-r--r--target.go2
-rw-r--r--target_test.go19
2 files changed, 20 insertions, 1 deletions
diff --git a/target.go b/target.go
index 7dcaa968d..ad701e837 100644
--- a/target.go
+++ b/target.go
@@ -206,7 +206,7 @@ func LoadTarget(target string) (*TargetSpec, error) {
// Load target from given triple, ignore GOOS/GOARCH environment
// variables.
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")
}
goos := tripleSplit[2]
diff --git a/target_test.go b/target_test.go
new file mode 100644
index 000000000..659dcd647
--- /dev/null
+++ b/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)
+ }
+}