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

相关推荐
互联网中的一颗神经元9 小时前
小白python入门 - 39. 采集流水线小项目
开发语言·python
Wang's Blog9 小时前
Go-Zero 项目开发22:用户群聊功能的实现与完善
开发语言·golang
a11177610 小时前
坦克大战3D Three.js 3D (开源项目)
开发语言·javascript·3d
库奇噜啦呼11 小时前
【iOS】NSOperation与NSOperationQueue
macos·ios·cocoa
Wang's Blog12 小时前
Go-Zero项目开发24: 基于Bitmap实现群聊消息已读未读
开发语言·后端·golang
吃好睡好便好14 小时前
MATLAB中图像的读取、写入和显示
开发语言·图像处理·学习·计算机视觉·matlab
yaoxin52112315 小时前
476. Java 反射 - 调用方法
java·开发语言
猫头虎15 小时前
什么是ZCode for GLM-5.2?
开发语言·人工智能·python·科技·算法·ai编程·ai写作
bksczm16 小时前
Linux之日志和线程池、内存池
java·开发语言
笨蛋不要掉眼泪16 小时前
Java虚拟机:对象复活、引用强度与Stop-The-World
java·开发语言·jvm