TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Entr(1) – Run tests whenever files change

108 pointsby jsnathanabout 8 years ago

19 comments

contingenciesabout 8 years ago
Another approach would be to use the Linux kernel&#x27;s fantastic <i>inotify()</i> feature, which does not require running tools designed for other purposes...<p><a href="https:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;7&#x2F;inotify" rel="nofollow">https:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;7&#x2F;inotify</a><p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Inotify" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Inotify</a><p>There is also a less well utilized <i>fsnotify</i> feature for filesystem-wide notifications. Here is a cross-platform go implementation which also supports OSX: <a href="https:&#x2F;&#x2F;github.com&#x2F;fsnotify&#x2F;fsnotify" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fsnotify&#x2F;fsnotify</a>
评论 #13865660 未加载
评论 #13866149 未加载
评论 #13866194 未加载
评论 #13865845 未加载
评论 #13881638 未加载
评论 #13865497 未加载
评论 #13866358 未加载
tonyabout 8 years ago
entr is is what I eventually settled on after years of searching the perfect utility to build&#x2F;run tests after file changes. After using gulp, grunt, watching_testrunner (which I eventually inherited maintainership of), watchman, watchdog (<a href="https:&#x2F;&#x2F;github.com&#x2F;gorakhargosh&#x2F;watchdog" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gorakhargosh&#x2F;watchdog</a>), sniffer (<a href="https:&#x2F;&#x2F;github.com&#x2F;jeffh&#x2F;sniffer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jeffh&#x2F;sniffer</a>)<p>entr is cross-platform on OS X, linux <i>and</i> BSD.<p>watching_testrunner has no BSD support<p>watchman is way too big and not domain specific enough to my needs<p>sniffer worked quite well but it required having a scent.py file everywhere<p>entr keeps it all in a neat, unix like package you can pipe files to.<p>I keep some example usage in my book, <i>The Tao of tmux</i> at <a href="https:&#x2F;&#x2F;leanpub.com&#x2F;the-tao-of-tmux&#x2F;read#leanpub-auto-file-watching" rel="nofollow">https:&#x2F;&#x2F;leanpub.com&#x2F;the-tao-of-tmux&#x2F;read#leanpub-auto-file-w...</a>. In this section I demonstrate my workflow with entr(1) in a Makefile. The code I use in the example should work across OS X &#x2F; BSD &#x2F; Linux (note the utilities like find(1) may behave a bit differently across unix-like systems).<p>I use the Makefile w&#x2F; entr(1) in development on my projects like tmuxp at <a href="https:&#x2F;&#x2F;github.com&#x2F;tony&#x2F;tmuxp&#x2F;blob&#x2F;master&#x2F;Makefile" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tony&#x2F;tmuxp&#x2F;blob&#x2F;master&#x2F;Makefile</a>. tmuxp is BSD-licensed so you&#x27;re free to work off that if you&#x27;d like to try it on your own project.
leni536about 8 years ago
<p><pre><code> ls -d * | entr make </code></pre> Just a nit: this seems to be imperfect for filenames containing new lines (I know, I know). An xargs like -0, --null option could make it more robust. Then the equivalent of the above command would be something like:<p><pre><code> find . -maxdepth 1 -name &#x27;[!.]*&#x27; -print0 | entr -0 make </code></pre> Edit: Seems like -print0 is not POSIX compliant. Is there any safe way to pass a list of paths using the shell in a fully POSIX compliant way?
评论 #13866550 未加载
评论 #13866607 未加载
评论 #13867495 未加载
strictfpabout 8 years ago
What a coincidence! I tested it yesterday. Worked like a charm. Thanks!<p>One note: the browser reloading script was not installed on debian, so I downloaded it. It was not clear from the documentation if that was the intention.
oeverabout 8 years ago
A similar tool written in Rust is watchexec.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;mattgreen&#x2F;watchexec" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mattgreen&#x2F;watchexec</a>
评论 #13866249 未加载
whizzkidabout 8 years ago
Ruby developers have been using Guard for a long time now.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;guard&#x2F;guard" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;guard&#x2F;guard</a>
评论 #13865736 未加载
cgagabout 8 years ago
I use entr all the time. I usually do something like piping go files to entry to run a script to build and run my app or tests.<p>Much simpler than most tools I&#x27;ve seen like it.
michaelmiorabout 8 years ago
&gt; It is not uncommon for modern web frameworks to continuously hunt for file system changes and auto-reloads when run in single threaded or standalone mode. This functionality is superfluous if the application can respond to signals.<p>This is true if all that happens is a page reload, butamy frameworks are able to patch code or styles into the running page without a reload. This requires more than a signal handler.
评论 #13867701 未加载
评论 #13866578 未加载
scooprabout 8 years ago
Many years ago I did a little utility I called autobuild[0] to do similar things. It has osx and windows support, but never got around doing linux support. I don&#x27;t think inotify has an easy way of doing recursive filesystem notifications, having to manage the hierarchy and their notifiers, so it lapsed when I didn&#x27;t need it at the time.<p>It felt like this kind of tool would&#x2F;should be one of those standard command line tools always available, or the at least of those standard things everyone knows to install, like silversearcher&#x2F;ripgrep etc.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;scoopr&#x2F;autobuild" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;scoopr&#x2F;autobuild</a>
evinismabout 8 years ago
this is one of those problems I&#x27;ve needed to solve for forever, but which i&#x27;ve never explicitly looked up a clean solution for. I can immediately think of 3 instances in the past week where this would have been perfect.
评论 #13865524 未加载
junkblockerabout 8 years ago
A long time entr user, I recently switch to modd for flexible almost makefile like configurability, and watching&#x2F;ignoring of multiple patterns to name a few convenient feature.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;cortesi&#x2F;modd" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cortesi&#x2F;modd</a>
nameless912about 8 years ago
I wrote a dead-simple version of this (that uses polling and doesn&#x27;t give you filters for files) in python and called it `jonsnow` and threw it on pypi. I understand this is an insanely useful utility, but it&#x27;s interesting that everyone seems to spin their own :)
awinter-pyabout 8 years ago
awesome.<p>What would be really great is a fuse DAG.<p>Some paths should run programs on write, others on read.<p>The filesystem is <i>already</i> the lock provider for a lot of programs; we should be using it as the event processor.<p>This is inherently polyglot -- every programming language in common use has FS utils.
ameliusabout 8 years ago
Next step: run tests whenever you enter a keystroke in your editor?
评论 #13866881 未加载
pkghostabout 8 years ago
Cross-platform alternative: <a href="http:&#x2F;&#x2F;emcrisostomo.github.io&#x2F;fswatch&#x2F;" rel="nofollow">http:&#x2F;&#x2F;emcrisostomo.github.io&#x2F;fswatch&#x2F;</a>
andy_pppabout 8 years ago
Looks interesting; anyone know how well this works inside docker? For me watching files can often cause huge CPU usage.
floatbothabout 8 years ago
For node: <a href="https:&#x2F;&#x2F;github.com&#x2F;kimmobrunfeldt&#x2F;chokidar-cli" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kimmobrunfeldt&#x2F;chokidar-cli</a>
dorianmabout 8 years ago
There is also Guard <a href="https:&#x2F;&#x2F;github.com&#x2F;guard&#x2F;guard" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;guard&#x2F;guard</a>
bulutsuzkuabout 8 years ago
Files? Tests were invented for OOP, no need to have files
评论 #13866831 未加载