Skip to content

Instantly share code, notes, and snippets.

@vaz
Created April 22, 2016 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaz/fd6ee4c3563425ec11c24b96cc9da13b to your computer and use it in GitHub Desktop.
Save vaz/fd6ee4c3563425ec11c24b96cc9da13b to your computer and use it in GitHub Desktop.
testing old-darwin-fallback branch of Listen (PR)
$ bash test.sh
This is what happens now. Simple Gemfile:
source 'https://rubygems.org'
gem 'listen'
Updating bundle...
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using ffi 1.9.10
Using rb-fsevent 0.9.7
Using bundler 1.11.2
Using rb-inotify 0.9.7
Using listen 3.0.6
Bundle complete! 1 Gemfile dependency, 5 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Running the test...
target_os is: darwin11.0
listen: /Users/vaz/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/listen-3.0.6
rb-fsevent: /Users/vaz/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rb-fsevent-0.9.7
listener started
listener stopped
Result: no events, no report :(
This is with the changes in this PR:
source 'https://rubygems.org'
gem 'listen', git: 'https://github.com/guard/listen', branch: 'old-darwin-fallback'
Updating bundle...
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using ffi 1.9.10
Using rb-fsevent 0.9.7
Using bundler 1.11.2
Using rb-inotify 0.9.7
Using listen 3.0.6 from https://github.com/guard/listen (at /Users/vaz/dev/oss/listen@dd2e0ac)
Bundle complete! 1 Gemfile dependency, 5 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Running the test...
target_os is: darwin11.0
listen: /Users/vaz/dev/oss/listen
rb-fsevent: /Users/vaz/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rb-fsevent-0.9.7
rb-fsevent > 0.9.4 no longer supports OS X 10.6 through 10.8.
Please add the following to your Gemfile to avoid polling for changes:
require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin(1[0-3])/i
gem 'rb-fsevent', '<= 0.9.4'
end
listener started
---- got changes:
m: ["/Users/vaz/tmp/listen-test/tmp/one"]
listener stopped
Result: polling is slow, but I got a warning!
This is with the fix suggested in the warning message:
source 'https://rubygems.org'
require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin(1[0-3])/i
gem 'rb-fsevent', '<= 0.9.4'
end
gem 'listen'
Updating bundle...
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using ffi 1.9.10
Using rb-fsevent 0.9.4
Using bundler 1.11.2
Using rb-inotify 0.9.7
Using listen 3.0.6
Bundle complete! 2 Gemfile dependencies, 5 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Running the test...
target_os is: darwin11.0
listen: /Users/vaz/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/listen-3.0.6
rb-fsevent: /Users/vaz/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rb-fsevent-0.9.4
listener started
---- got changes:
m: ["/Users/vaz/tmp/listen-test/tmp/one"]
a: ["/Users/vaz/tmp/listen-test/tmp/two"]
---- got changes:
r: ["/Users/vaz/tmp/listen-test/tmp/two"]
listener stopped
Result: :D
echo "This is what happens now. Simple Gemfile:"
cat >Gemfile <<EOF
source 'https://rubygems.org'
gem 'listen'
EOF
cat Gemfile
echo -e "\nUpdating bundle..."
rm -f Gemfile.lock
bundle install
echo -e "\nRunning the test..."
bundle exec ruby test_listen.rb
echo -e "\nResult: no events, no report :(\n\n"
echo "This is with the changes in this PR:"
cat >Gemfile <<EOF
source 'https://rubygems.org'
gem 'listen', git: 'https://github.com/guard/listen', branch: 'old-darwin-fallback'
EOF
cat Gemfile
echo -e "\nUpdating bundle..."
rm -f Gemfile.lock
bundle install
echo -e "\nRunning the test..."
bundle exec ruby test_listen.rb
echo -e "\nResult: polling is slow, but I got a warning!\n\n"
echo "This is with the fix suggested in the warning message:"
cat >Gemfile <<EOF
source 'https://rubygems.org'
require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin(1[0-3])/i
gem 'rb-fsevent', '<= 0.9.4'
end
gem 'listen'
EOF
cat Gemfile
echo -e "\nUpdating bundle..."
rm -f Gemfile.lock
bundle install
echo -e "\nRunning the test..."
bundle exec ruby test_listen.rb
echo -e "\nResult: :D\n\n"
require 'bundler/setup'
require 'listen'
require 'fileutils'
require 'rbconfig'
include FileUtils
puts "target_os is: #{RbConfig::CONFIG['target_os']}"
puts "listen: #{`bundle show listen`}"
puts "rb-fsevent: #{`bundle show rb-fsevent`}"
TMPDIR = "#{Dir.pwd}/tmp"
rm_rf TMPDIR
mkdir_p TMPDIR
touch File.join(TMPDIR, 'one')
def listening
listener = Listen.to(TMPDIR) do |m, a, r|
puts "---- got changes:"
puts "m: #{m}" unless m.empty?
puts "a: #{a}" unless a.empty?
puts "r: #{r}" unless r.empty?
end
listener.start
puts "listener started"
yield
listener.stop
puts "listener stopped"
end
listening do
sleep 1
touch File.join(TMPDIR, 'one')
touch File.join(TMPDIR, 'two')
sleep 1
rm File.join(TMPDIR, 'two')
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment