0
0

More than 3 years have passed since last update.

【Golang】テスト実行時に "package exec is not in GOROOT"

Posted at

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

execos パッケージの一部です。execos/exec と指定します。

import(
-    "exec"
+    "os/exec"
)

TS; DR(所感)

外部コマンドの実行結果を取得するために、コード中に exec.Command() を使ったところ、VSCode の自動補完で importexec が追加されました。

テストを実行すると "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 をブラウザの検索エンジンに登録したいと思います。とほほ。

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0