File: test_helper.rb

package info (click to toggle)
ohcount 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,712 kB
  • ctags: 3,205
  • sloc: ansic: 6,524; ruby: 2,560; perl: 2,041; erlang: 350; lisp: 272; sh: 244; pascal: 196; vhdl: 150; haskell: 149; asm: 128; cs: 124; awk: 98; java: 92; php: 73; tcl: 58; xml: 57; fortran: 54; makefile: 32; python: 31; ada: 30; objc: 30; jsp: 28; sql: 18; cobol: 13; ml: 9; cpp: 3
file content (60 lines) | stat: -rw-r--r-- 1,655 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'test/unit'
require 'fileutils'
require 'find'
require File.dirname(__FILE__) + '/../../../ruby/ohcount.rb' # .rb is to specify the .rb instead of .bundle
require File.dirname(__FILE__) + '/../../../ruby/gestalt' # .rb is to specify the .rb instead of .bundle

unless defined?(TEST_DIR)
	TEST_DIR = File.dirname(__FILE__)
end

module Ohcount
end

# Ohcount::Test is a base class which includes several helper methods for parser testing.
# All unit tests in Ohcount should derive from this class.
#
# ==== Manual Testing
#
# To manually test a parser, rebuild ohcount and run it against your test file:
#
#   rake
#   bin/ohcount --annotate test/src_dir/my_file.ext
#
# The +annotate+ option will emit your test file to the console, and each line will be
# labeled as code, comment, or blank.
#
class Ohcount::Test < Test::Unit::TestCase

	# For reasons unknown, the base class defines a default_test method to throw a failure.
	# We override it with a no-op to prevent this 'helpful' feature.
	def default_test; end

	protected

  def assert_tool(path, *tools)
    gestalts = tools.map do |t|
      Base.new(:tool, t.to_s)
    end
    assert_gestalts path, gestalts
  end

	def assert_platform(path, *platforms)
    gestalts = platforms.map do |p|
      Base.new(:platform, p.to_s)
    end
    assert_gestalts path, gestalts
  end

	def assert_gestalts(path, expected_gestalts)
		sfl = SourceFileList.new(:paths => [test_dir(path)])
		assert sfl.size > 0
		sfl.analyze(:gestalt)
    assert_equal expected_gestalts.sort, sfl.gestalts.sort
  end

	def test_dir(d)
		File.expand_path(File.dirname(__FILE__) + "/../../gestalt_files/#{ d }")
	end
end