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

相关推荐
Shun_Tianyou13 分钟前
Python Day17 面向对象 及例题分析
开发语言·数据结构·python·算法
wjs202422 分钟前
XML 用途
开发语言
Dreamsi_zh40 分钟前
Python爬虫07_Requests爬取图片
开发语言·爬虫·python
蒋星熠1 小时前
字母异位词分组(每天刷力扣hot100系列)
开发语言·c++·算法·leetcode·职场和发展
是小崔啊1 小时前
Mac下的Homebrew
macos
杨航 AI1 小时前
PHP 5.5 Action Management with Parameters (English Version)
android·开发语言·php
代码的余温1 小时前
Java试题-选择题(2)
java·开发语言
lemon_sjdk1 小时前
java笔记——ConcurrentLinkedQueue
java·开发语言·笔记
封奚泽优2 小时前
使用Python制造扫雷游戏
开发语言·python·游戏·pygame·扫雷·random
超浪的晨2 小时前
Maven 与单元测试:JavaWeb 项目质量保障的基石
java·开发语言·学习·单元测试·maven·个人开发