Class: MonkeyTest::CLI
- Inherits:
-
Object
- Object
- MonkeyTest::CLI
- Defined in:
- lib/monkeytest/cli.rb
Constant Summary collapse
- TESTLOADER =
Path to the test loader script
File.dirname(__FILE__) + '/test_loader.rb'
Class Method Summary collapse
Instance Method Summary collapse
- #build_cmd ⇒ Object
- #find_files(directory, pattern) ⇒ Object
- #find_files_r(directory, pattern) ⇒ Object
- #find_test_files(options) ⇒ Object
- #fling! ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse_options(args = ARGV) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
15 16 17 18 19 |
# File 'lib/monkeytest/cli.rb', line 15 def initialize @options = @cmd = build_cmd fling! end |
Class Method Details
.fling! ⇒ Object
11 12 13 |
# File 'lib/monkeytest/cli.rb', line 11 def self.fling! new end |
Instance Method Details
#build_cmd ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/monkeytest/cli.rb', line 26 def build_cmd cmd = "ruby -rubygems -e \"require 'monkeytest'" cmd << "; COLOR=#{@options.color}" cmd << "; OUTPUT_LEVEL=:#{@options.outputLevel.to_s}" cmd << "; OUTPUT_FORMAT=:#{@options.outputFormat.to_s}" cmd << "; FILE=#{@options.outputFile}" unless @options.outputFile.nil? cmd << "; FILE=nil" if @options.outputFile.nil? cmd << "\" \"#{TESTLOADER}\" \"#{@options.testFiles.join('" "')}\" --runner=monkey" return cmd end |
#find_files(directory, pattern) ⇒ Object
188 189 190 191 |
# File 'lib/monkeytest/cli.rb', line 188 def find_files(directory,pattern) files = directory.find_all { |f| f =~ pattern and !File.directory?(directory.path + "/" + f) } files.collect { |f| directory.path + "/" + f } end |
#find_files_r(directory, pattern) ⇒ Object
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/monkeytest/cli.rb', line 177 def find_files_r(directory,pattern) directories = directory.find_all { |f| !(f =~ /^\./) and File.directory?(directory.path + "/" + f) } files = directory.find_all { |f| f =~ pattern and !File.directory?(directory.path + "/" + f) } files.collect! { |f| directory.path + "/" + f } if directories.empty? return files else return(files.push directories.collect { |dir| find_files_r(Dir.new(directory.path + "/" + dir),pattern) }) end end |
#find_test_files(options) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/monkeytest/cli.rb', line 162 def find_test_files() files = [] if !.unit.nil? or !.integration.nil? or !.functional.nil? files.push find_files(Dir.new(.directory.path + "/unit"), .pattern) if File.exists?(.directory.path + "/unit") unless .unit.nil? files.push find_files(Dir.new(.directory.path + "/functional"), .pattern) if File.exists?(.directory.path + "/functional") unless .functional.nil? files.push find_files(Dir.new(.directory.path + "/integration"), .pattern) if File.exists?(.directory.path + "/integration") unless .integration.nil? files.flatten! elsif .recursive files = find_files_r(.directory, .pattern) else files = find_files(.directory, .pattern) end return files.flatten end |
#fling! ⇒ Object
21 22 23 24 |
# File 'lib/monkeytest/cli.rb', line 21 def fling! #puts @cmd system @cmd end |
#parse_options(args = ARGV) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/monkeytest/cli.rb', line 37 def (args=ARGV) = OpenStruct.new # Setup default options .outputFormat = :console .outputLevel = :normal .color = true if File.exists?("./test") .directory = Dir.new("./test") else .directory = Dir.new(".") end .pattern = /^.+_test\.rb$/ .recursive = true opts = OptionParser.new do |opts| opts. = "Usage: monkeytest [options]" # Options for specifying which tests will be run opts.separator "" opts.separator "Test selection criteria options:" opts.on("-d DIRECTORY", "--directory DIRECTORY", "Run tests found in the given directory") { |dir| begin .directory = Dir.new(dir) rescue Exception => e puts e exit end } opts.on("-d", "--directory DIRECTORY","Search DIRECTORY for tests") { |dir| .directory = Dir.new(dir) } opts.on("-r", "--[no-]recursive", "[Don't] Search directories recursively") { |r| .recursive = r } opts.on("-u", "--[no-]unit", "[Don't] Run unit tests") { |u| .unit = u } opts.on("-f", "--[no-]functional", "[Don't] Run functional tests") { |f| .functional = f } opts.on("-i", "--[no-]integration", "[Don't] Run integration tests") { |i| .integration = i } opts.on("-p PATTERN", "--pattern PATTERN", Regexp, "Run test files which match PATTERN\n#{' '*37}(use quotes for safety!)") { |regex| .pattern = regex } # Options for output opts.separator "" opts.separator "Output options:" opts.on("-q", "--quiet", "Output summary of failures and errors only") { |q| if .outputLevel == :verbose puts "Only one of --quiet or --verbose is allowed." exit!(1) end .outputLevel = :quiet } opts.on("-v", "--verbose", "Output full fault messages") { |s| if .outputLevel == :quiet puts "Only one of --quiet or --verbose is allowed." exit!(1) end .outputLevel = :verbose } opts.on("--[no-]color", "[Don't] Show colored output") { |c| .color = c } #opts.on("--html", "--html [FILE]", "Output results in HTML\n#{' '*37}(optionally to the given file)") { |html| # options.outputFormat = :html # options.outputFile = html #} #opts.on("--rss", "--rss [FILE]", "Output results in RSS\n#{' '*37}(optionally to the given file)") { |rss| # options.outputFormat = :rss # options.outputFile = rss #} # Other options opts.separator "" opts.separator "Other options:" opts.on("-h", "--help", "Displays this help message") { puts opts exit!(0) } opts.on("-V", "--version", "Display monkey test version info" ) do require 'monkeytest/version' puts "Monkey Test v#{MonkeyTest::Version::STRING}" exit!(0) end end begin opts.parse!(args) rescue OptionParser::MissingArgument => e puts "Option #{e.to_s.match(/\-[\w]+/).to_s} is missing a required argument." exit!(1) rescue Exception => e puts e exit!(1) end .testFiles = find_test_files() if .testFiles.empty? puts "No test files were found with the given criteria." exit!(0) end return end |