【Go学习】macOS+IDEA运行golang项目,报command-line-arguments,undefined

写在前面的话:idea如何配置golang,自行百度

问题1:通过idea的terminal执行go test报错

bash 复制代码
✘ xxxxx@macdeMacBook-Pro-3  /Volumes/mac/.../LearnGoWithTests/hello  go test
go: go.mod file not found in current directory or any parent directory; see 'go help modules'

这个问题就是当前目录没有go.mod文件,直接用go命令生成一个即可(example.com/m 可以随便自定义,比如:helloWorld)

bash 复制代码
✘ xxxxx@macdeMacBook-Pro-3  /Volumes/mac/.../LearnGoWithTests/hello  go mod init example.com/m      
go: creating new go.mod: module example.com/m
go: to add module requirements and sums:
        go mod tidy

再次执行go test就没问题了(下面的虽然case FAIL了,但是执行是没问题的)

bash 复制代码
✘ xxxxx@macdeMacBook-Pro-3  /Volumes/mac/.../LearnGoWithTests/hello  go test
PASS
ok      example.com/m   0.470s
问题2:通过idea的Run或Debug执行,就会报command-line-arguments,undefined

【解决方法】打开preferences,如下图设置一下即可

然后再用Run或Debug执行就可以了,如下图

相关推荐
FQNmxDG4S3 小时前
Java多线程编程:Thread与Runnable的并发控制
java·开发语言
前端老石人3 小时前
HTML 字符引用完全指南
开发语言·前端·html
matlab_xiaowang3 小时前
Redux 入门:JavaScript 可预测状态管理库
开发语言·javascript·其他·ecmascript
虹科网络安全3 小时前
艾体宝干货|数据复制详解:类型、原理与适用场景
java·开发语言·数据库
axng pmje4 小时前
Java语法进阶
java·开发语言·jvm
老前端的功夫4 小时前
【Java从入门到入土】28:Stream API:告别for循环的新时代
java·开发语言·python
qq_435287924 小时前
第9章 夸父逐日与后羿射日:死循环与进程终止?十个太阳同时值班的并行冲突
java·开发语言·git·死循环·进程终止·并行冲突·夸父逐日
止语Lab4 小时前
从手动到框架:Go DI 演进的三个拐点
开发语言·后端·golang
yaoxin5211235 小时前
397. Java 文件操作基础 - 创建常规文件与临时文件
java·开发语言·python
小短腿的代码世界5 小时前
Qt日志系统深度解析:从qDebug到企业级日志框架
开发语言·qt