OTWO-1213 Works around lost encoding in Ruby/C binding layer
[ohcount] / test / unit / ruby / test_helper.rb
1 require 'test/unit'
2 require 'fileutils'
3 require 'find'
4 require File.dirname(__FILE__) + '/../../../ruby/ohcount.rb' # .rb is to specify the .rb instead of .bundle
5 require File.dirname(__FILE__) + '/../../../ruby/gestalt' # .rb is to specify the .rb instead of .bundle
6
7 unless defined?(TEST_DIR)
8         TEST_DIR = File.dirname(__FILE__)
9 end
10
11 module Ohcount
12 end
13
14 # Ohcount::Test is a base class which includes several helper methods for parser testing.
15 # All unit tests in Ohcount should derive from this class.
16 #
17 # ==== Manual Testing
18 #
19 # To manually test a parser, rebuild ohcount and run it against your test file:
20 #
21 #   rake
22 #   bin/ohcount --annotate test/src_dir/my_file.ext
23 #
24 # The +annotate+ option will emit your test file to the console, and each line will be
25 # labeled as code, comment, or blank.
26 #
27 class Ohcount::Test < Test::Unit::TestCase
28
29         # For reasons unknown, the base class defines a default_test method to throw a failure.
30         # We override it with a no-op to prevent this 'helpful' feature.
31         def default_test; end
32
33         protected
34
35   def assert_tool(path, *tools)
36     gestalts = tools.map do |t|
37       Base.new(:tool, t.to_s)
38     end
39     assert_gestalts path, gestalts
40   end
41
42         def assert_platform(path, *platforms)
43     gestalts = platforms.map do |p|
44       Base.new(:platform, p.to_s)
45     end
46     assert_gestalts path, gestalts
47   end
48
49         def assert_gestalts(path, expected_gestalts)
50     assert_equal expected_gestalts.sort, get_gestalts(path)
51   end
52
53         def get_gestalts(path)
54                 sfl = SourceFileList.new(:paths => [test_dir(path)])
55                 assert sfl.size > 0
56                 sfl.analyze(:gestalt)
57                 sfl.gestalts.sort
58         end
59
60         def test_dir(d)
61                 File.expand_path(File.dirname(__FILE__) + "/../../gestalt_files/#{ d }")
62         end
63 end
64