0

My gem uses a local copy of Tidy HTML Validator. It's available in lib/tidy/tidy. My tests run perfectly locally, but on Travis CI, I'm getting the error that Tidy can't be found.

Errno::ENOENT:
No such file or directory - tidy

The code looks like this:

stdin, stdout, stderr = Open3.popen3('tidy -quiet')

Is there a restriction or something that prevents executing a local executable? I also call a local copy of the Jigsaw CSS Validator which is a Java jar file and is executed like this:

`java -jar css-validator.jar --output=soap12 file:#{uri}`

This works perfectly on Travis CI. Could there be a problem with Open3?

Here's the link to the GitHub repo: https://github.com/jmuheim/headhunter Here's the link to the failing Travis CI build: https://travis-ci.org/jmuheim/headhunter

Update

I have rewritten the code that executes the external java executable to also use Open3, and it's working. So the problem has to do with tidy.

For further debugging I have renamed tidy into tidy2 (to make sure that really the wanted executable is called), and I added a manual File.exist? 'tidy' before calling it, so this would raise an error if it couldn't be found.

  Dir.chdir(VALIDATOR_DIR) do
    raise "Could not find tidy in #{Dir.pwd}" unless File.exists? EXECUTABLE

    # Docs for Tidy: http://tidy.sourceforge.net/docs/quickref.html
    stdin, stdout, stderr = Open3.popen3("#{EXECUTABLE} -quiet")
    # ...
  end

The file is definitely found, but executing it still results in this error.

 1) Headhunter::HtmlValidator#validate returns a local response when calling the validator succeeds
 Failure/Error: subject.validate('invalid.html', read_file('html_validator/invalid.html'))
 Errno::ENOENT:
   No such file or directory - tidy2
 # ./lib/headhunter/html_validator.rb:20:in `block in validate'
 # ./lib/headhunter/html_validator.rb:16:in `chdir'
 # ./lib/headhunter/html_validator.rb:16:in `validate'
 # ./spec/lib/headhunter/html_validator_spec.rb:9:in `block (4 levels) in <top (required)>'
 # ./spec/lib/headhunter/html_validator_spec.rb:8:in `block (3 levels) in <top (required)>'

So the only thing I can guess now is that be there is a permissions problem? Is there a way to set permissions to local executables with Travis CI?

I also tried putting tidy into bin like somebody suggested in the comments, but this didn't seem to change a thing, too.

Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152

2 Answers2

1

A couple things:

Typically the environment is different than your current environment when spawning programs so you have to check what the environment is. This is the case in cron, monit, and for some ruby method calls.

In your case, for Open, it uses Process.spawn so you're not guaranteed to be in your own directory. Open.popen3 takes a :chdir option, so set that to your Dir.pwd and see what happens.

You can also try just using absolute paths.

Sources

http://ruby-doc.org/stdlib-1.9.3/libdoc/open3/rdoc/Open3.html#method-c-popen3

https://stackoverflow.com/a/5917927/463225

http://ruby-doc.org/core-1.9.3/Process.html#method-c-spawn

Community
  • 1
  • 1
WattsInABox
  • 4,548
  • 2
  • 33
  • 43
  • This is very interesting. While I'm quite sure that inz's answer is the correct one, this one has some very useful hints, too. I will get back to both of you as soon as I tried out your suggestions. – Joshua Muheim Feb 27 '14 at 15:33
1

It looks like your tidy2 executable is a Mach-O binary for OS X, but the Travis worker runs Linux. Try to include a suitable ELF binary from http://tidy.sourceforge.net/#binaries.

inz
  • 11
  • 2