【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执行就可以了,如下图

相关推荐
小成202303202651 小时前
Linux高级02
linux·开发语言
知行合一。。。2 小时前
Python--04--数据容器(总结)
开发语言·python
咸鱼2.02 小时前
【java入门到放弃】需要背诵
java·开发语言
ZK_H2 小时前
嵌入式c语言——关键字其6
c语言·开发语言·计算机网络·面试·职场和发展
A.A呐2 小时前
【C++第二十九章】IO流
开发语言·c++
椰猫子2 小时前
Java:异常(exception)
java·开发语言
lifewange2 小时前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
cmpxr_2 小时前
【C】原码和补码以及环形坐标取模算法
c语言·开发语言·算法
2401_827499993 小时前
python项目实战09-AI智能伴侣(ai_partner_5-6)
开发语言·python
PD我是你的真爱粉3 小时前
MCP 协议详解:从架构、工作流到 Python 技术栈落地
开发语言·python·架构