Skip to content

Commit

Permalink
Merge pull request #353 from raphinesse/fix-tests-on-windows
Browse files Browse the repository at this point in the history
Fix tests on Windows
  • Loading branch information
denisdefreyne committed Nov 24, 2013
2 parents 83bd420 + e49a568 commit 025755c
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ source "http://rubygems.org"
gemspec

gem 'adsf'
gem 'bluecloth'
gem 'bluecloth', :platforms => :ruby
gem 'builder'
gem 'coderay'
gem 'coffee-script'
gem 'erubis'
gem 'fog'
gem 'haml'
gem 'handlebars'
gem 'handlebars', :platforms => :ruby
gem 'kramdown'
gem 'less', '~> 2.0'
gem 'less', '~> 2.0', :platforms => :ruby
gem 'listen'
gem 'markaby'
gem 'maruku'
Expand Down
3 changes: 3 additions & 0 deletions test/cli/commands/test_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Nanoc::CLI::Commands::DeployTest < Nanoc::TestCase

def test_deploy
skip_unless_have_command "rsync"
if_have 'systemu' do
with_site do |site|
File.open('nanoc.yaml', 'w') do |io|
Expand Down Expand Up @@ -113,6 +114,7 @@ def test_deploy_with_list_deployers
end

def test_deploy_without_kind
skip_unless_have_command "rsync"
if_have 'systemu' do
with_site do |site|
File.open('nanoc.yaml', 'w') do |io|
Expand Down Expand Up @@ -159,6 +161,7 @@ def test_deploy_without_target_without_default
end

def test_deploy_without_target_with_default
skip_unless_have_command "rsync"
if_have 'systemu' do
with_site do |site|
File.open('nanoc.yaml', 'w') do |io|
Expand Down
1 change: 1 addition & 0 deletions test/cli/commands/test_prune.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_run_with_exclude
end

def test_run_with_symlink_to_output_dir
skip_unless_have_symlink
with_site do |site|
# Set output dir
FileUtils.rm_rf('output')
Expand Down
2 changes: 1 addition & 1 deletion test/data_sources/test_filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def test_parse_utf8_bom
io.write "content goes here\n"
end

data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
data_source = Nanoc::DataSources::FilesystemCombined.new(nil, nil, nil, :encoding => 'utf-8')

result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
assert_equal({ 'utf8bomawareness' => 'high' }, result[0])
Expand Down
2 changes: 2 additions & 0 deletions test/data_sources/test_static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def new_data_source(params=nil)
end

def test_items_with_symlinks
skip_unless_have_symlink

# Create data source
data_source = new_data_source(:prefix => 'foo')

Expand Down
4 changes: 4 additions & 0 deletions test/extra/test_filesystem_tools.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# encoding: utf-8

class Nanoc::Extra::FilesystemToolsTest < Nanoc::TestCase
def setup
super
skip_unless_have_symlink
end

def test_all_files_in_follows_symlinks_to_dirs
# Write sample files
Expand Down
4 changes: 1 addition & 3 deletions test/filters/test_asciidoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ class Nanoc::Filters::AsciiDocTest < Nanoc::TestCase

def test_filter
if_have 'systemu' do
if `which asciidoc`.strip.empty?
skip "could not find asciidoc"
end
skip_unless_have_command "asciidoc"

# Create filter
filter = ::Nanoc::Filters::AsciiDoc.new
Expand Down
14 changes: 4 additions & 10 deletions test/filters/test_colorize_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ def test_coderay_with_more_classes

def test_pygmentize
if_have 'nokogiri', 'systemu' do
if `which pygmentize`.strip.empty?
skip "could not find pygmentize"
end
skip_unless_have_command "pygmentize"

# Create filter
filter = ::Nanoc::Filters::ColorizeSyntax.new
Expand All @@ -140,6 +138,7 @@ def test_pygmentize
end

def test_pygmentsrb
skip "pygments.rb does not support Windows" if on_windows?
if_have 'pygments', 'nokogiri' do
# Create filter
filter = ::Nanoc::Filters::ColorizeSyntax.new
Expand All @@ -156,9 +155,7 @@ def test_pygmentsrb

def test_simon_highlight
if_have 'nokogiri', 'systemu' do
if `which highlight`.strip.empty?
skip "could not find `highlight`"
end
skip_unless_have_command "highlight"

# Create filter
filter = ::Nanoc::Filters::ColorizeSyntax.new
Expand Down Expand Up @@ -216,10 +213,7 @@ def test_colorize_syntax_with_xhtml
end

def test_colorize_syntax_with_default_colorizer
if `which pygmentize`.strip.empty?
skip 'no pygmentize found, which is required for this test'
return
end
skip_unless_have_command "pygmentize"

if_have 'nokogiri', 'systemu' do
# Create filter
Expand Down
4 changes: 1 addition & 3 deletions test/filters/test_pandoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ class Nanoc::Filters::PandocTest < Nanoc::TestCase

def test_filter
if_have 'pandoc-ruby' do
if `which pandoc`.strip.empty?
skip "could not find pandoc"
end
skip_unless_have_command "pandoc"

# Create filter
filter = ::Nanoc::Filters::Pandoc.new
Expand Down
25 changes: 25 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,31 @@ def with_env_vars(hash, &block)
orig_env_hash.each_pair { |k,v| ENV[k] = v }
end

def on_windows?
!!(RUBY_PLATFORM =~ /mswin|mingw/)
end

def have_command?(cmd)
which, null = on_windows? ? ["where", "NUL"] : ["which", "/dev/null"]
system("#{which} #{cmd} > #{null} 2>&1")
end

def have_symlink?
File.symlink nil, nil
rescue NotImplementedError
return false
rescue
return true
end

def skip_unless_have_command(cmd)
skip "Could not find external command \"#{cmd}\"" unless have_command?(cmd)
end

def skip_unless_have_symlink
skip "Symlinks are not supported by Ruby on Windows" unless have_symlink?
end

end

class Nanoc::TestCase < MiniTest::Unit::TestCase
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_render_without_filter
io.write("layout '/foo/', nil\n")
end

File.open('layouts/foo.xyz', 'w')
File.open('layouts/foo.xyz', 'w').close()

assert_raises(Nanoc::Errors::CannotDetermineFilter) do
render '/foo/'
Expand All @@ -54,7 +54,7 @@ def test_render_with_unknown_filter
io.write("layout '/foo/', :asdf\n")
end

File.open('layouts/foo.xyz', 'w')
File.open('layouts/foo.xyz', 'w').close()

assert_raises(Nanoc::Errors::UnknownFilter) do
render '/foo/'
Expand Down
2 changes: 1 addition & 1 deletion test/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_build
assert_match(/^nanoc-.*\.gem$/, diff.to_a[0])

# Check output
assert_match(/Successfully built RubyGem\n Name: nanoc\n Version: .*\n File: nanoc-.*\.gem\n/, stdout)
assert_match(/Successfully built RubyGem\s+Name: nanoc\s+Version: .*\s+File: nanoc-.*\.gem\s+/, stdout)
assert_equal '', stderr
ensure
Dir['nanoc-*.gem'].each { |f| FileUtils.rm(f) }
Expand Down

0 comments on commit 025755c

Please sign in to comment.