Skip to content
Browse files

Raise an exception if libtidy could not be found.

  • Loading branch information...
1 parent a65581b commit 49cbaa1d62c751a3f8c9c514776f4ae9854dca43 @libc committed
Showing with 28 additions and 10 deletions.
  1. +3 −1 lib/tidy_ffi.rb
  2. +1 −1 lib/tidy_ffi/tidy.rb
  3. +12 −8 lib/tidy_ffi/tidy_ffi_extensions.rb
  4. +12 −0 spec/extensions_spec.rb
View
4 lib/tidy_ffi.rb
@@ -3,8 +3,10 @@
module TidyFFI
self.autoload :LibTidy, 'tidy_ffi/lib_tidy'
self.autoload :Interface, 'tidy_ffi/interface'
+
+ class LibTidyNotInstalled < StandardError; end
end
require 'tidy_ffi/options_container'
require 'tidy_ffi/tidy'
-require 'tidy_ffi/tidy_ffi_extensions'
+require 'tidy_ffi/tidy_ffi_extensions'
View
2 lib/tidy_ffi/tidy.rb
@@ -80,4 +80,4 @@ def validate_options?
end
attr_writer :validate_options
end
-end
+end
View
20 lib/tidy_ffi/tidy_ffi_extensions.rb
@@ -11,16 +11,20 @@ def library_path
def find_tidy
fnames = ['libtidy.dylib', 'libtidy.so']
- pathes = []
- pathes += ENV['LD_LIBRARY_PATH'].split(':') if ENV['LD_LIBRARY_PATH']
- pathes += ENV['DYLD_LIBRARY_PATH'].split(':') if ENV['DYLD_LIBRARY_PATH']
- pathes += ENV['PATH'].split(':').reject { |a| a['sbin'] }.map { |a| a.sub('/bin', '/lib') } if ENV['PATH']
- pathes = ['/usr/lib', '/usr/local/lib'] if pathes.size == 0
- for path in pathes.uniq
- fnames.each { |fname| return File.join(path, fname) if File.exists?(File.join(path, fname)) }
+ paths = []
+ paths += ENV['LD_LIBRARY_PATH'].split(':') if ENV['LD_LIBRARY_PATH']
+ paths += ENV['DYLD_LIBRARY_PATH'].split(':') if ENV['DYLD_LIBRARY_PATH']
+ paths += ENV['PATH'].split(':').reject { |a| a['sbin'] }.map { |a| a.sub('/bin', '/lib') } if ENV['PATH']
+ paths = ['/usr/lib', '/usr/local/lib'] if paths.size == 0
+ paths.uniq.each do |path|
+ fnames.each do |fname|
+ library_path = File.join(path, fname)
+ return library_path if File.exists? library_path
+ end
end
+ raise TidyFFI::LibTidyNotInstalled, "Could not find libtidy"
nil
end
private :find_tidy
end
-TidyFFI.extend TidyFFI::TidyFFIExtensions
+TidyFFI.extend TidyFFI::TidyFFIExtensions
View
12 spec/extensions_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe TidyFFI::TidyFFIExtensions do
+ include TidyFFI::TidyFFIExtensions
+
+ describe '#find_tidy' do
+ it 'raises TidyFFI::LibTidyNotInstalled if the library could not be found' do
+ stub(File).exists? { false }
+ expect { find_tidy }.to raise_error(TidyFFI::LibTidyNotInstalled)
+ end
+ end
+end

0 comments on commit 49cbaa1

Please sign in to comment.
Something went wrong with that request. Please try again.