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

相关推荐
我叫小白菜10 分钟前
【Java_EE】单例模式、阻塞队列、线程池、定时器
java·开发语言
狐凄16 分钟前
Python实例题:基于 Python 的简单聊天机器人
开发语言·python
weixin_446122461 小时前
JAVA内存区域划分
java·开发语言·redis
悦悦子a啊1 小时前
Python之--基本知识
开发语言·前端·python
QuantumStack2 小时前
【C++ 真题】P1104 生日
开发语言·c++·算法
whoarethenext2 小时前
使用 C++/OpenCV 和 MFCC 构建双重认证智能门禁系统
开发语言·c++·opencv·mfcc
代码的奴隶(艾伦·耶格尔)3 小时前
后端快捷代码
java·开发语言
Jay_5154 小时前
C++多态与虚函数详解:从入门到精通
开发语言·c++
路来了4 小时前
Python小工具之PDF合并
开发语言·windows·python
xiaolang_8616_wjl4 小时前
c++文字游戏_闯关打怪
开发语言·数据结构·c++·算法·c++20