# Run the tests if we can before installation.
# Don't run tests that depend on un-installed modules.
test_errors = 0
begin

  begin
    require 'rexml/xpath' # probe for REXML
    has_rexml = true
  rescue LoadError
    has_rexml = false
  end

  require 'test/unit' # probe for Test::Unit

  Dir.glob(srcdir_root + "/test/*[^~]").grep(/tc_/).each { |f|
    if f =~ /xpath/ && !has_rexml
      $stderr.puts "Skipping test #{f} because you don't have REXML installed"
    else
      begin
          $stderr.puts "Running test #{f}\n"
          test_errors += 1 unless ruby("-Ilib #{f}")
      rescue LoadError
        $stderr.puts "Test #{f} failed because of missing module(s)"
      end
    end
  }

rescue LoadError
  $stderr.puts "All tests skipped because you don't have Test::Unit installed"
end

if test_errors > 0
  $stderr.puts %Q{There were #{test_errors} test errors.
Your installation may not work correctly.}
end
