0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Go言語で作るインタプリタ go test ./lexer で import "monkey/token" ができない

Last updated at Posted at 2022-06-28

非常に具体的な問題を解決するための記事です。

バージョン

$ go version
go version go1.18.3 darwin/amd64

問題点

  • ~/SOME/PATH/monkey/token の用にフォルダを作成する(自分の場合は~/program/go/interpreter/monkey/tokenとしている)

  • go mod init github.com.....としたらダメだった

$ go test ./lexer
# github.com/yojiyama7/go_interpreter/lexer
lexer/lexer_test.go:5:2: package monkey/token is not in GOROOT (/usr/local/go/src/monkey/token)
FAIL	github.com/yojiyama7/go_interpreter/lexer [setup failed]
FAIL

解決策

  • go.modファイルを削除して、
  • monkeyディレクトリで go mod init monkey とする
  • このような内容のgo.modができる
module monkey

go 1.18

DONE

  • monkeyディレクトリでgo test ./lexerが動いた
$ go test ./lexer
# monkey/lexer [monkey/lexer.test]
lexer/lexer_test.go:12:25: undefined: token.TokenType
lexer/lexer_test.go:26:7: undefined: New
FAIL	monkey/lexer [build failed]
FAIL
0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?