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

相关推荐
野犬寒鸦3 分钟前
JVM垃圾回收机制面试常问问题及详解
java·服务器·开发语言·jvm·后端·算法·面试
参.商.11 分钟前
【Day45】647. 回文子串 5. 最长回文子串
leetcode·golang
本喵是FW13 分钟前
C语言手记3
c语言·开发语言
一杯美式 no sugar20 分钟前
类和对象(中)
开发语言·c++
qq_4160187222 分钟前
实时数据可视化库
开发语言·c++·算法
2401_8732046536 分钟前
C++中的策略模式进阶
开发语言·c++·算法
xushichao198941 分钟前
C++中的职责链模式实战
开发语言·c++·算法
清风徐来QCQ1 小时前
js中的模板字符串
开发语言·前端·javascript
2301_818419011 小时前
C++中的协程编程
开发语言·c++·算法
add45a1 小时前
C++中的工厂方法模式
开发语言·c++·算法