| 1 | #!/usr/bin/ruby |
|---|
| 2 | # |
|---|
| 3 | # Test suite for Linguistics classes |
|---|
| 4 | # |
|---|
| 5 | # |
|---|
| 6 | |
|---|
| 7 | BEGIN { |
|---|
| 8 | $:.unshift "lib", "tests" |
|---|
| 9 | |
|---|
| 10 | require './utils' |
|---|
| 11 | include UtilityFunctions |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | verboseOff { |
|---|
| 15 | require 'lingtestcase' |
|---|
| 16 | require 'find' |
|---|
| 17 | require 'test/unit' |
|---|
| 18 | require 'test/unit/testsuite' |
|---|
| 19 | require 'test/unit/ui/console/testrunner' |
|---|
| 20 | require 'optparse' |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | # Turn off output buffering |
|---|
| 24 | $stderr.sync = $stdout.sync = true |
|---|
| 25 | |
|---|
| 26 | # Initialize variables |
|---|
| 27 | safelevel = 0 |
|---|
| 28 | patterns = [] |
|---|
| 29 | requires = [] |
|---|
| 30 | |
|---|
| 31 | # Parse command-line switches |
|---|
| 32 | ARGV.options {|oparser| |
|---|
| 33 | oparser.banner = "Usage: #$0 [options] [TARGETS]\n" |
|---|
| 34 | |
|---|
| 35 | oparser.on( "--debug", "-d", TrueClass, "Turn debugging on" ) { |
|---|
| 36 | $DEBUG = true |
|---|
| 37 | debugMsg "Turned debugging on." |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | oparser.on( "--verbose", "-v", TrueClass, "Make progress verbose" ) { |
|---|
| 41 | $VERBOSE = true |
|---|
| 42 | debugMsg "Turned verbose on." |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | # Handle the 'help' option |
|---|
| 46 | oparser.on( "--help", "-h", "Display this text." ) { |
|---|
| 47 | $stderr.puts oparser |
|---|
| 48 | exit!(0) |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | oparser.parse! |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | # Parse test patterns |
|---|
| 55 | ARGV.each {|pat| patterns << Regexp::new( pat, Regexp::IGNORECASE )} |
|---|
| 56 | $stderr.puts "#{patterns.length} patterns given on the command line" |
|---|
| 57 | |
|---|
| 58 | ### Load all the tests from the tests dir |
|---|
| 59 | Find.find("tests") {|file| |
|---|
| 60 | Find.prune if /\/\./ =~ file or /~$/ =~ file |
|---|
| 61 | Find.prune if /TEMPLATE/ =~ file |
|---|
| 62 | next if File.stat( file ).directory? |
|---|
| 63 | |
|---|
| 64 | unless patterns.empty? |
|---|
| 65 | Find.prune unless patterns.find {|pat| pat =~ file} |
|---|
| 66 | end |
|---|
| 67 | |
|---|
| 68 | debugMsg "Considering '%s': " % file |
|---|
| 69 | next unless file =~ /\.tests.rb$/ |
|---|
| 70 | debugMsg "Requiring '%s'..." % file |
|---|
| 71 | require "#{file}" |
|---|
| 72 | requires << file |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | $stderr.puts "Required #{requires.length} files." |
|---|
| 76 | unless patterns.empty? |
|---|
| 77 | $stderr.puts "[" + requires.sort.join( ", " ) + "]" |
|---|
| 78 | end |
|---|
| 79 | |
|---|
| 80 | # Build the test suite |
|---|
| 81 | class LinguisticsTests |
|---|
| 82 | class << self |
|---|
| 83 | def suite |
|---|
| 84 | suite = Test::Unit::TestSuite.new( "Linguistics" ) |
|---|
| 85 | |
|---|
| 86 | if suite.respond_to?( :add ) |
|---|
| 87 | ObjectSpace.each_object( Class ) {|klass| |
|---|
| 88 | suite.add( klass.suite ) if klass < Linguistics::TestCase |
|---|
| 89 | } |
|---|
| 90 | else |
|---|
| 91 | ObjectSpace.each_object( Class ) {|klass| |
|---|
| 92 | suite << klass.suite if klass < Linguistics::TestCase |
|---|
| 93 | } |
|---|
| 94 | end |
|---|
| 95 | |
|---|
| 96 | return suite |
|---|
| 97 | end |
|---|
| 98 | end |
|---|
| 99 | end |
|---|
| 100 | |
|---|
| 101 | # Run tests |
|---|
| 102 | $SAFE = safelevel |
|---|
| 103 | Test::Unit::UI::Console::TestRunner.new( LinguisticsTests ).start |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|