英文:
`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 <dir> | 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论