1
0
mirror of https://github.com/magefile/mage.git synced 2026-10-24 06:19:18 +03:00
Files
mage/sh/testmain_test.go
Nate Finch 8fa000d89f Helpers galore (#26)
* Helpers galore

This commit adds helper functions that should be commonly needed
by many magefiles. It includes command execution handlers as well
as error handlers.

This commit also removes the only two non-stdlib dependencies in
the codebase.  Since mage will likely be vendored into a repo,
it would be nice to avoid cluttering the vendor directory with
dependencies that are only for the build script.
2017-10-02 22:22:21 -04:00

47 lines
748 B
Go

package sh
import (
"flag"
"fmt"
"os"
"testing"
)
var (
helperCmd bool
printArgs bool
stderr string
stdout string
exitCode int
printVar string
)
func init() {
flag.BoolVar(&helperCmd, "helper", false, "")
flag.BoolVar(&printArgs, "printArgs", false, "")
flag.StringVar(&stderr, "stderr", "", "")
flag.StringVar(&stdout, "stdout", "", "")
flag.IntVar(&exitCode, "exit", 0, "")
flag.StringVar(&printVar, "printVar", "", "")
}
func TestMain(m *testing.M) {
flag.Parse()
if printArgs {
fmt.Println(flag.Args())
return
}
if printVar != "" {
fmt.Println(os.Getenv(printVar))
return
}
if helperCmd {
fmt.Fprintln(os.Stderr, stderr)
fmt.Fprintln(os.Stdout, stdout)
os.Exit(exitCode)
}
os.Exit(m.Run())
}