`go test` 文件修改监控用于自动化测试。

huangapple go评论80阅读模式
英文:

`go test` file modification monitoring for automated testing

问题

有没有办法在项目文件被修改时自动运行go test命令?

也许有一个通用的解决方案,可以在路径中的文件被修改时运行一个命令,这个解决方案可以用于这个用途吗?

英文:

Is there a way to have go test run whenever a project's files are modified?

Perhaps there is a good general solution to run a command when files in a path are modified that could be used for this use?

答案1

得分: 3

你可以使用inotifywait来实现这个功能。例如,监听某个目录,并在关闭时执行go test命令,同时有数据被写入:

inotifywait -e close_write <dir> | while read file; do go test; done

或者你可以使用Go语言中的howeyc/fsnotify包编写自己的工具,这是一个类似的示例应用程序:类似的示例应用程序

还有一个用Ruby编写的工具叫做rerun

rerun go test

上述命令将监视当前目录的变化,并在发生变化时运行go test命令。

英文:

You can use inotifywait for that. Example watching some dir and executing go test on close while having data written:

inotifywait -e close_write &lt;dir&gt; | while read file; do go test; done

Or you write your own tool in go utilizing the howeyc/fsnotify package: Similar example application.

There's also rerun, written in ruby:

rerun go test

Above command will watch the current directory for changes and run go test when a change occurs.

huangapple
  • 本文由 发表于 2013年11月22日 08:22:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/20134641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定