Go 言語(Golang)の
testing
を使ってテストを実行すると「exec
パッケージがない」と言われます。
$ go test .
# github.com/KEINOS/Hello-World
main_test.go:5:2: package exec is not in GOROOT (/usr/local/go/src/exec)
FAIL github.com/KEINOS/Hello-World [setup failed]
FAIL
意外なことに「"golang" package exec is not in GOROOT」とググっても、当然すぎるのか、すぐに見つからなかったので自分のググラビリティとして。
- go version go1.15.3
TL; DR
exec
はos
パッケージの一部です。exec
→os/exec
と指定します。
import(
- "exec"
+ "os/exec"
)
TS; DR(所感)
外部コマンドの実行結果を取得するために、コード中に exec.Command()
を使ったところ、VSCode の自動補完で import
に exec
が追加されました。
テストを実行すると "package exec is not in GOROOT
" と叱られます。
金曜の夕方だからなのか、公式ドキュメントも調べず、いきなり検索猿人で闇雲に「"golang" package exec is not in GOROOT」とググってもすぐに出てきませんでした。
公式の package
ドキュメントを見たら、一発で出てきました。
Package exec
import "os/exec"(Package exec @ The Go Programming Language より)
公式 package をブラウザの検索エンジンに登録したいと思います。とほほ。
参考文献
- Package exec @ The Go Programming Language
- golangで便利ツール作ろうと思ったらos/execでハマった話 @ Qiita