feature: use environment in addition to flags to control test options
This applies to -syscall, -unsafe and -unrestricted flags with the corresponding env variables YAEGI_SYSCALL, YAEGI_UNSAFE and YAEGI_UNRESTRICTED, already used in the same way for the run sub-command.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"go/build"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -28,13 +29,15 @@ func test(arg []string) (err error) {
|
||||
run string
|
||||
short bool
|
||||
tags string
|
||||
useUnrestricted bool
|
||||
useUnsafe bool
|
||||
useSyscall bool
|
||||
timeout string
|
||||
verbose bool
|
||||
)
|
||||
|
||||
// The following flags are initialized from environment.
|
||||
useSyscall, _ := strconv.ParseBool(os.Getenv("YAEGI_SYSCALL"))
|
||||
useUnrestricted, _ := strconv.ParseBool(os.Getenv("YAEGI_UNRESTRICTED"))
|
||||
useUnsafe, _ := strconv.ParseBool(os.Getenv("YAEGI_UNSAFE"))
|
||||
|
||||
tflag := flag.NewFlagSet("test", flag.ContinueOnError)
|
||||
tflag.StringVar(&bench, "bench", "", "Run only those benchmarks matching a regular expression.")
|
||||
tflag.BoolVar(&benchmem, "benchmem", false, "Print memory allocation statistics for benchmarks.")
|
||||
@@ -46,9 +49,9 @@ func test(arg []string) (err error) {
|
||||
tflag.BoolVar(&short, "short", false, "Tell long-running tests to shorten their run time.")
|
||||
tflag.StringVar(&tags, "tags", "", "Set a list of build tags.")
|
||||
tflag.StringVar(&timeout, "timeout", "", "If a test binary runs longer than duration d, panic.")
|
||||
tflag.BoolVar(&useUnrestricted, "unrestricted", false, "Include unrestricted symbols.")
|
||||
tflag.BoolVar(&useUnsafe, "unsafe", false, "Include usafe symbols.")
|
||||
tflag.BoolVar(&useSyscall, "syscall", false, "Include syscall symbols.")
|
||||
tflag.BoolVar(&useUnrestricted, "unrestricted", useUnrestricted, "Include unrestricted symbols.")
|
||||
tflag.BoolVar(&useUnsafe, "unsafe", useUnsafe, "Include usafe symbols.")
|
||||
tflag.BoolVar(&useSyscall, "syscall", useSyscall, "Include syscall symbols.")
|
||||
tflag.BoolVar(&verbose, "v", false, "Verbose output: log all tests as they are run.")
|
||||
tflag.Usage = func() {
|
||||
fmt.Println("Usage: yaegi test [options] [path]")
|
||||
@@ -105,12 +108,22 @@ func test(arg []string) (err error) {
|
||||
i.Use(interp.Symbols)
|
||||
if useSyscall {
|
||||
i.Use(syscall.Symbols)
|
||||
// Using a environment var allows a nested interpreter to import the syscall package.
|
||||
if err := os.Setenv("YAEGI_SYSCALL", "1"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if useUnrestricted {
|
||||
i.Use(unrestricted.Symbols)
|
||||
if err := os.Setenv("YAEGI_UNRESTRICTED", "1"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if useUnsafe {
|
||||
i.Use(unsafe.Symbols)
|
||||
if err := os.Setenv("YAEGI_UNSAFE", "1"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err = i.EvalTest(path); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user