Skip to content

Commit

Permalink
Initial work on new runner scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ford committed Feb 19, 2008
1 parent e224f1b commit 2adb784
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bin/mspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/usr/bin/env ruby

ENV["CI_FILES"] = ['spec/ruby/1.8/core',
'spec/ruby/1.8/language',
'spec/compiler',
'spec/parser'].join(" ")
ENV["TAGS_DIR"] = File.expand_path('spec/tags')

require File.dirname(__FILE__) + '/../mspec/scripts/mspec'
load 'mspec/bin/mspec'
94 changes: 94 additions & 0 deletions mspec/bin/mspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env ruby

require 'optparse'
require 'mspec/version'
require 'mspec/bin/options'

includes = []
requires = []
name = nil
target = 'shotgun/rubinius'
flags = []
command = nil
options = []

if ["ci", "run", "tag"].include? ARGV[0]
command = ARGV.shift
options << "-h" if ARGV.delete("-h") || ARGV.delete("--help")
end

opts = OptionParser.new("", 24, ' ') do |opts|
opts.banner = "mspec [COMMAND] [options] (FILE|DIRECTORY|GLOB)+"
opts.separator ""

opts.on("-t", "--target TARGET", String,
"Implementation to run the specs: r:ruby|r19:ruby19|x:rbx|j:jruby") do |t|
case t
when 'r', 'ruby'
target = 'ruby'
when 'r19', 'ruby19'
target = 'ruby19'
when 'x', 'rbx', 'rubinius'
target = 'shotgun/rubinius'
when 'j', 'jruby'
target = 'jruby'
else
target = t
end
end
opts.on("-T", "--target-opt OPT", String,
"Pass OPT as a flag to the target implementation") do |t|
flags << t
end
opts.on("-I", "--include DIR", String,
"Pass DIR through as the -I option to the target") do |d|
includes << "-I#{d}"
end
opts.on("-r", "--require LIBRARY", String,
"Pass LIBRARY through as the -r option to the target") do |f|
requires << "-r#{f}"
end
opts.on("-n", "--name RUBY_NAME", String,
"Override the name used to determine the implementation") do |n|
name = "RUBY_NAME = \"#{n}\";"
end
opts.on("-D", "--gdb", "Run under gdb") do
flags << '--gdb'
end
opts.on("-A", "--valgrind", "Run under valgrind") do
flags << '--valgrind'
end
opts.on("-w", "--warnings", "Don't supress warnings") do
flags << '-w'
ENV['OUTPUT_WARNINGS'] = '1'
end
opts.on("-v", "--version", "Show version") do
puts "MSpec #{MSpec::VERSION}"
exit
end
opts.on("-h", "--help", "Show this message") do
puts opts
puts %[
where COMMAND is one of:
run - Run the specified specs (default)
ci - Run the known good spec
tag - Add or remove tags
mspec COMMAND -h for more options
]
exit
end
end

options += opts.filter! ARGV
opts.parse ARGV

ENV['MSPEC_RUNNER'] = '1'
ENV['MSPEC_OPTIONS'] = options.join(" ")
exec %[#{target} \
#{flags.join(" ")} \
#{includes.join(" ")} \
#{requires.join(" ")} \
mspec/bin/mspec-#{command || "run"}
]
6 changes: 6 additions & 0 deletions mspec/bin/mspec-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

require 'optparse'
require 'spec/spec_helper'

puts "mspec ci"
30 changes: 30 additions & 0 deletions mspec/bin/mspec-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env ruby

require 'optparse'
require 'spec/spec_helper'
require 'mspec/bin/options'

opts = SpecOptions.new "run", "", 24, " "
opts.options.on("-Y", "--verify",
"Verify that guarded specs pass and fail as expected") { MSpec.set_mode :verify }
opts.options.on("-O", "--report", "Report guarded specs") { MSpec.set_mode :report }
patterns = opts.parse
config = opts.config

if patterns.empty?
puts "No files specified."
puts opts
exit
end

files = []
patterns.each do |item|
stat = File.stat(File.expand_path(item))
files << item if stat.file?
files.concat(Dir[item+"/**/*_spec.rb"].sort) if stat.directory?
end

MSpec.register_files files
opts.config.register

MSpec.process
6 changes: 6 additions & 0 deletions mspec/bin/mspec-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

require 'optparse'
require 'spec/spec_helper'
require 'mspec/bin/options'
puts "mspec tag"
162 changes: 162 additions & 0 deletions mspec/bin/options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# FIXME: There are essentially two options for these runner
# scripts: 1. all in one file, 2. in separate files. The fact
# that the subcommands share a number of options weighs
# toward having a single script. However, the subcommands
# also take specialized options which can be confusing. Added
# to this the support for switches to specify a different
# implementation and the balance swings to separate scripts.
#
# Now, the fun begins. The main script needs a way to specify
# certain command line options and then pass the rest to the
# invoked subscript. Unfortunately, this possibility does not
# exist in the universe inhabited by OptionParser or GetoptLong.
#
# The #filter! method below does not properly handle optional
# arguments to a switch.
class OptionParser
class Switch
def consume?(opt)
if opt == short.to_s or opt == long.to_s
return arg ? 2 : 1
elsif opt[0..1] == short.to_s and opt.size > 2
return 1
else
return 0
end
end
end

def filter!(argv)
@stack.inject(options=[]) do |list, entry|
entry.list.each do |switch|
next unless switch.kind_of? OptionParser::Switch
list << switch
end
list
end

filtered = []
recognized = []
consume = nil
until argv.empty?
opt = argv.shift
options.find { |o| consume = o.consume?(opt); consume != 0 }
if consume == 0
filtered << opt
else
recognized << opt
recognized << argv.shift if consume == 2
end
end
argv.replace recognized
filtered
end
end

class SpecConfig
attr_accessor :formatter, :includes, :excludes,
:patterns, :xpatterns, :tags, :xtags

def initialize
@formatter = DottedFormatter
@includes = []
@excludes = []
@patterns = []
@xpatterns = []
@tags = []
@xtags = []
end

def register
@formatter.new.register
end
end

class SpecOptions
attr_reader :options, :config

def initialize(command, *args)
@config = SpecConfig.new

@options = OptionParser.new(*args) do |opts|
opts.banner = "mspec #{command} [options] (FILE|DIRECTORY|GLOB)+"
opts.separator ""

opts.on("-f", "--format FORMAT", String,
"Formatter for reporting: s:specdoc|d:dotted|h:html|u:unitdiff") do |o|
case o
when 's', 'specdoc'
@config.formatter = SpecdocFormatter
when 'h', 'html'
@config.formatter = HtmlFormatter
when 'd', 'dot', 'dotted'
@config.formatter = DottedFormatter
when 'u', 'unit', 'unitdiff'
@config.formatter = UnitdiffFormatter
when 'm', 'summary'
@config.formatter = SummaryFormatter
else
puts "Unknown format: #{o}"
puts opts
exit
end
end
opts.on("-e", "--example STRING", String,
"Execute examples with descriptions matching STRING") do |o|
puts "I'm here! #{o}"
@config.includes << o
end
opts.on("-E", "--exclude STRING", String,
"Exclude examples with descriptions matching STRING") do |o|
@config.excludes << o
end
opts.on("-p", "--pattern PATTERN", Regexp,
"Execute examples with descriptions matching PATTERN") do |o|
@config.patterns << o
end
opts.on("-P", "--exclude-pattern PATTERN", Regexp,
"Exclude examples with descriptions matching PATTERN") do |o|
@config.xpatterns << o
end
opts.on("-g", "--tag TAG", String,
"Execute examples with descriptions matching ones tagged with TAG") do |o|
@config.tags << o
end
opts.on("-G", "--exclude-tag TAG", String,
"Exclude examples with descriptions matching ones tagged with TAG") do |o|
@config.xtags << o
end
opts.on("-V", "--verbose", "Output the name of each file processed") do
obj = Object.new
def obj.start
@width = MSpec.retrieve(:files).inject(0) { |max, f| f.size > max ? f.size : max }
end
def obj.load
print "\n#{file.ljust(@width)}"
end
MSpec.register :start, obj
MSpec.register :load, obj
end
opts.on("-m", "--marker MARKER", String,
"Outout MARKER for each file processed") do |o|
obj = Object.new
def obj.load
print o
end
MSpec.register :load, obj
end
opts.on("-v", "--version", "Show version") do
puts "MSpec #{MSpec::VERSION}"
exit
end
opts.on("-h", "--help", "Show this message") do
puts opts
exit
end
end
end

def parse
@options.parse ENV['MSPEC_OPTIONS'].split
end
end

0 comments on commit 2adb784

Please sign in to comment.