diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/executable/source_with_comments.rb | 3 | ||||
-rw-r--r-- | test/executable/suite.rb | 76 | ||||
-rwxr-xr-x | test/functional/basic.rb | 41 | ||||
-rwxr-xr-x | test/functional/examples.rb | 2 | ||||
-rw-r--r-- | test/functional/for_redcloth.rb | 18 | ||||
-rwxr-xr-x | test/functional/suite.rb | 3 | ||||
-rw-r--r-- | test/lib/README | 1 | ||||
-rw-r--r-- | test/lib/assert_warning.rb | 15 | ||||
-rw-r--r-- | test/unit/file_type.rb | 4 | ||||
-rwxr-xr-x | test/unit/plugin.rb | 22 | ||||
-rw-r--r-- | test/unit/plugins/example.rb | 2 | ||||
-rw-r--r-- | test/unit/plugins/user_defined/user_plugin.rb | 2 | ||||
-rw-r--r-- | test/unit/plugins_with_default/default.rb | 5 | ||||
-rw-r--r-- | test/unit/plugins_with_default/default_plugin.rb | 5 | ||||
-rw-r--r-- | test/unit/plugins_with_default/example_without_register_for.rb | 4 |
15 files changed, 130 insertions, 73 deletions
diff --git a/test/executable/source_with_comments.rb b/test/executable/source_with_comments.rb new file mode 100644 index 0000000..ec79358 --- /dev/null +++ b/test/executable/source_with_comments.rb @@ -0,0 +1,3 @@ +# a class +class ClassName +end diff --git a/test/executable/suite.rb b/test/executable/suite.rb index ec696ec..b3f8025 100644 --- a/test/executable/suite.rb +++ b/test/executable/suite.rb @@ -3,31 +3,44 @@ require 'rubygems' unless defined? Gem require 'shoulda-context' require 'pathname' -$:.unshift 'lib' +require 'json' + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' puts "Running CodeRay #{CodeRay::VERSION} executable tests..." class TestCodeRayExecutable < Test::Unit::TestCase - ruby = 'ruby' - ROOT_DIR = Pathname.new(File.dirname(__FILE__)) + '..' + '..' EXECUTABLE = ROOT_DIR + 'bin' + 'coderay' - EXE_COMMAND = '%s -wI%s %s'% [ - ruby, # calling Ruby process command - ROOT_DIR + 'lib', # library dir - EXECUTABLE # coderay - ] + EXE_COMMAND = + if RUBY_PLATFORM === 'java' && `ruby --ng -e ''` && $?.success? + # use Nailgun + 'ruby --ng -wI%s %s' + else + 'ruby -wI%s %s' + end % [ROOT_DIR + 'lib', EXECUTABLE] - def coderay args, fake_tty = false - if fake_tty + def coderay args, options = {} + if options[:fake_tty] command = "#{EXE_COMMAND} #{args} --tty" else command = "#{EXE_COMMAND} #{args}" end + puts command if $DEBUG - output = `#{command} 2>&1` + + if options[:input] + output = IO.popen "#{command} 2>&1", "r+" do |io| + io.write options[:input] + io.close_write + io.read + end + else + output = `#{command} 2>&1` + end + if output[EXECUTABLE.to_s] raise output else @@ -74,30 +87,30 @@ class TestCodeRayExecutable < Test::Unit::TestCase end context 'highlighting a file to the terminal' do - source_file = 'test/executable/source.py' + source_file = ROOT_DIR + 'test/executable/source.py' source = File.read source_file ansi_seq = /\e\[[0-9;]+m/ should 'not throw an error' do - assert_nothing_raised { coderay(source_file, :tty) } + assert_nothing_raised { coderay(source_file, :fake_tty => true) } end should 'output its contents to stdout' do - target = coderay(source_file, :tty) + target = coderay(source_file, :fake_tty => true) assert_equal source, target.chomp.gsub(ansi_seq, '') end should 'output ANSI-colored text' do - target = coderay(source_file, :tty) + target = coderay(source_file, :fake_tty => true) assert_not_equal source, target.chomp assert_equal 6, target.scan(ansi_seq).size end end - context 'highlighting a file into a pipe (source.rb > source.rb.html)' do - source_file = 'test/executable/source.rb' + context 'highlighting a file into a pipe (source.rb -html > source.rb.html)' do + source_file = ROOT_DIR + 'test/executable/source.rb' target_file = "#{source_file}.html" - command = "#{source_file} > #{target_file}" + command = "#{source_file} -html > #{target_file}" source = File.read source_file @@ -126,7 +139,7 @@ class TestCodeRayExecutable < Test::Unit::TestCase end context 'highlighting a file into another file (source.rb source.rb.json)' do - source_file = 'test/executable/source.rb' + source_file = ROOT_DIR + 'test/executable/source.rb' target_file = "#{source_file}.json" command = "#{source_file} #{target_file}" @@ -151,8 +164,8 @@ class TestCodeRayExecutable < Test::Unit::TestCase end context 'highlighting a file without explicit input type (source.py)' do - source_file = 'test/executable/source.py' - command = source_file + source_file = ROOT_DIR + 'test/executable/source.py' + command = "#{source_file} -html" source = File.read source_file @@ -166,8 +179,8 @@ class TestCodeRayExecutable < Test::Unit::TestCase end context 'highlighting a file with explicit input type (-ruby source.py)' do - source_file = 'test/executable/source.py' - command = "-ruby #{source_file}" + source_file = ROOT_DIR + 'test/executable/source.py' + command = "-ruby #{source_file} -html" source = File.read source_file @@ -181,7 +194,7 @@ class TestCodeRayExecutable < Test::Unit::TestCase end context 'highlighting a file with explicit input and output type (-ruby source.py -span)' do - source_file = 'test/executable/source.py' + source_file = ROOT_DIR + 'test/executable/source.py' command = "-ruby #{source_file} -span" source = File.read source_file @@ -194,4 +207,19 @@ class TestCodeRayExecutable < Test::Unit::TestCase end end + context 'the LOC counter' do + source_file = ROOT_DIR + 'test/executable/source_with_comments.rb' + command = "-ruby -loc" + + should 'work' do + output = coderay(command, :input => <<-CODE) +# test +=begin +=end +test + CODE + assert_equal "1\n", output + end + end + end diff --git a/test/functional/basic.rb b/test/functional/basic.rb index 94e1dd7..8200ae4 100755 --- a/test/functional/basic.rb +++ b/test/functional/basic.rb @@ -1,21 +1,12 @@ # encoding: utf-8 require 'test/unit' +require File.expand_path('../../lib/assert_warning', __FILE__) + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' class BasicTest < Test::Unit::TestCase - def assert_warning expected_warning - require 'stringio' - oldstderr = $stderr - $stderr = StringIO.new - yield - $stderr.rewind - given_warning = $stderr.read.chomp - assert_equal expected_warning, given_warning - ensure - $stderr = oldstderr - end - def test_version assert_nothing_raised do assert_match(/\A\d\.\d\.\d?\z/, CodeRay::VERSION) @@ -135,7 +126,7 @@ more code # and another comment, in-line. assert_equal 0, CodeRay.scan(rHTML, :html).lines_of_code assert_equal 0, CodeRay.scan(rHTML, :php).lines_of_code assert_equal 0, CodeRay.scan(rHTML, :yaml).lines_of_code - assert_equal 4, CodeRay.scan(rHTML, :rhtml).lines_of_code + assert_equal 4, CodeRay.scan(rHTML, :erb).lines_of_code end def test_rubygems_not_loaded @@ -243,8 +234,28 @@ more code # and another comment, in-line. scanner = CodeRay::Scanners::Plain.new "foo\nbär+quux" assert_equal 0, scanner.pos assert_equal 1, scanner.line - assert_equal 0, scanner.column - scanner.scan(/foo\nbär/) + assert_equal 1, scanner.column + scanner.scan(/foo/) + assert_equal 3, scanner.pos + assert_equal 1, scanner.line + assert_equal 4, scanner.column + scanner.scan(/\n/) + assert_equal 4, scanner.pos + assert_equal 2, scanner.line + assert_equal 1, scanner.column + scanner.scan(/b/) + assert_equal 5, scanner.pos + assert_equal 2, scanner.line + assert_equal 2, scanner.column + scanner.scan(/a/) + assert_equal 5, scanner.pos + assert_equal 2, scanner.line + assert_equal 2, scanner.column + scanner.scan(/ä/) + assert_equal 7, scanner.pos + assert_equal 2, scanner.line + assert_equal 4, scanner.column + scanner.scan(/r/) assert_equal 8, scanner.pos assert_equal 2, scanner.line assert_equal 5, scanner.column diff --git a/test/functional/examples.rb b/test/functional/examples.rb index f80c90c..3de8be5 100755 --- a/test/functional/examples.rb +++ b/test/functional/examples.rb @@ -1,4 +1,6 @@ require 'test/unit' + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' class ExamplesTest < Test::Unit::TestCase diff --git a/test/functional/for_redcloth.rb b/test/functional/for_redcloth.rb index 8c6491d..3c45eec 100644 --- a/test/functional/for_redcloth.rb +++ b/test/functional/for_redcloth.rb @@ -1,5 +1,7 @@ require 'test/unit' -$:.unshift 'lib' +require File.expand_path('../../lib/assert_warning', __FILE__) + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' begin @@ -64,15 +66,19 @@ class BasicTest < Test::Unit::TestCase # See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets. def test_for_redcloth_false_positive require 'coderay/for_redcloth' - assert_equal '<p><code>[project]_dff.skjd</code></p>', - RedCloth.new('@[project]_dff.skjd@').to_html + assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do + assert_equal '<p><code>[project]_dff.skjd</code></p>', + RedCloth.new('@[project]_dff.skjd@').to_html + end # false positive, but expected behavior / known issue assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">_dff.skjd</span></p>", RedCloth.new('@[ruby]_dff.skjd@').to_html - assert_equal <<-BLOCKCODE.chomp, + assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do + assert_equal <<-BLOCKCODE.chomp, <pre><code>[project]_dff.skjd</code></pre> - BLOCKCODE - RedCloth.new('bc. [project]_dff.skjd').to_html + BLOCKCODE + RedCloth.new('bc. [project]_dff.skjd').to_html + end end end if defined? RedCloth
\ No newline at end of file diff --git a/test/functional/suite.rb b/test/functional/suite.rb index 6d795c0..5490f98 100755 --- a/test/functional/suite.rb +++ b/test/functional/suite.rb @@ -1,5 +1,6 @@ require 'test/unit' -$:.unshift 'lib' + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' mydir = File.dirname(__FILE__) diff --git a/test/lib/README b/test/lib/README index 7d7a0a0..7c41648 100644 --- a/test/lib/README +++ b/test/lib/README @@ -1,3 +1,2 @@ Contents: - test/unit: We need the old Test::Unit for the scanner test suite to work with Ruby 1.9. -- term/ansicolor: Used for colorful output of the scanner tests.
\ No newline at end of file diff --git a/test/lib/assert_warning.rb b/test/lib/assert_warning.rb new file mode 100644 index 0000000..828b464 --- /dev/null +++ b/test/lib/assert_warning.rb @@ -0,0 +1,15 @@ +class Test::Unit::TestCase + + def assert_warning expected_warning + require 'stringio' + oldstderr = $stderr + $stderr = StringIO.new + yield + $stderr.rewind + given_warning = $stderr.read.chomp + assert_equal expected_warning, given_warning + ensure + $stderr = oldstderr + end + +end diff --git a/test/unit/file_type.rb b/test/unit/file_type.rb index d62a006..1dc1ba0 100644 --- a/test/unit/file_type.rb +++ b/test/unit/file_type.rb @@ -73,8 +73,8 @@ class FileTypeTests < Test::Unit::TestCase assert_equal :page, FileType['test.htm'] assert_equal :page, FileType['test.xhtml'] assert_equal :page, FileType['test.html.xhtml'] - assert_equal :rhtml, FileType['_form.rhtml'] - assert_equal :rhtml, FileType['_form.html.erb'] + assert_equal :erb, FileType['_form.rhtml'] + assert_equal :erb, FileType['_form.html.erb'] end def test_yaml diff --git a/test/unit/plugin.rb b/test/unit/plugin.rb index 678b883..2231c75 100755 --- a/test/unit/plugin.rb +++ b/test/unit/plugin.rb @@ -1,6 +1,8 @@ require 'test/unit' +require File.expand_path('../../lib/assert_warning', __FILE__) + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' -require 'pathname' class PluginScannerTest < Test::Unit::TestCase @@ -20,7 +22,7 @@ class PluginScannerTest < Test::Unit::TestCase extend CodeRay::Plugin plugin_host PluginsWithDefault end - default :default + default :default_plugin end def test_load @@ -36,7 +38,9 @@ class PluginScannerTest < Test::Unit::TestCase def test_default assert_nothing_raised do - assert_operator PluginsWithDefault[:gargamel], :<, PluginsWithDefault::Plugin + assert_warning 'PluginScannerTest::PluginsWithDefault could not load plugin :gargamel; falling back to :default_plugin' do + assert_operator PluginsWithDefault[:gargamel], :<, PluginsWithDefault::Plugin + end end assert_equal PluginsWithDefault::Default, PluginsWithDefault.default end @@ -64,16 +68,4 @@ class PluginScannerTest < Test::Unit::TestCase assert_equal 'The Example', Plugins::Example.title end - def assert_warning expected_warning - require 'stringio' - oldstderr = $stderr - $stderr = StringIO.new - yield - $stderr.rewind - given_warning = $stderr.read.chomp - assert_equal expected_warning, given_warning - ensure - $stderr = oldstderr - end - end diff --git a/test/unit/plugins/example.rb b/test/unit/plugins/example.rb index e28dc7c..af1aeba 100644 --- a/test/unit/plugins/example.rb +++ b/test/unit/plugins/example.rb @@ -3,4 +3,4 @@ class Example < PluginScannerTest::Plugins::Plugin register_for :example title 'The Example' -end
\ No newline at end of file +end diff --git a/test/unit/plugins/user_defined/user_plugin.rb b/test/unit/plugins/user_defined/user_plugin.rb index 61e5372..f47c934 100644 --- a/test/unit/plugins/user_defined/user_plugin.rb +++ b/test/unit/plugins/user_defined/user_plugin.rb @@ -2,4 +2,4 @@ class UserPlugin < PluginScannerTest::Plugins::Plugin register_for :user_plugin -end
\ No newline at end of file +end diff --git a/test/unit/plugins_with_default/default.rb b/test/unit/plugins_with_default/default.rb deleted file mode 100644 index e67c9f1..0000000 --- a/test/unit/plugins_with_default/default.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Default < PluginScannerTest::PluginsWithDefault::Plugin - - register_for :default - -end
\ No newline at end of file diff --git a/test/unit/plugins_with_default/default_plugin.rb b/test/unit/plugins_with_default/default_plugin.rb new file mode 100644 index 0000000..ae9e4c5 --- /dev/null +++ b/test/unit/plugins_with_default/default_plugin.rb @@ -0,0 +1,5 @@ +class DefaultPlugin < PluginScannerTest::PluginsWithDefault::Plugin + + register_for :default_plugin + +end diff --git a/test/unit/plugins_with_default/example_without_register_for.rb b/test/unit/plugins_with_default/example_without_register_for.rb index d9f40be..083baf6 100644 --- a/test/unit/plugins_with_default/example_without_register_for.rb +++ b/test/unit/plugins_with_default/example_without_register_for.rb @@ -1,5 +1,5 @@ -class ExampleWithoutRegisterFor < PluginScannerTest::Plugins::Plugin +class ExampleWithoutRegisterFor < PluginScannerTest::PluginsWithDefault::Plugin register_for :wrong_id -end
\ No newline at end of file +end |