From e41e5106cca28d9ccfb976dc38562ab08388c09f Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 23 Jul 2020 23:24:05 +0200 Subject: [PATCH] main: add -target flag to tests This makes it easy to test one particular architecture, for example: go test -v -target=hifive1-qemu This speeds up testing and allows testing targets that are not included in the test by default (such as RISC-V tests on Linux). --- main_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main_test.go b/main_test.go index f3f10fd2..8597de1f 100644 --- a/main_test.go +++ b/main_test.go @@ -6,6 +6,7 @@ package main import ( "bufio" "bytes" + "flag" "fmt" "io/ioutil" "os" @@ -25,6 +26,8 @@ import ( const TESTDATA = "testdata" +var testTarget = flag.String("target", "", "override test target") + func TestCompiler(t *testing.T) { matches, err := filepath.Glob(filepath.Join(TESTDATA, "*.go")) if err != nil { @@ -44,6 +47,14 @@ func TestCompiler(t *testing.T) { sort.Strings(matches) + if *testTarget != "" { + // This makes it possible to run one specific test (instead of all), + // which is especially useful to quickly check whether some changes + // affect a particular target architecture. + runPlatTests(*testTarget, matches, t) + return + } + if runtime.GOOS != "windows" { t.Run("Host", func(t *testing.T) { runPlatTests("", matches, t)