runs mspec: Parses the command line and executes the desired commands
Zachary Kurmas
Copyright © 2012
value returned if program is not given enough / correct command-line arguments
value returned when the spec file parses, but running the test generates an exception
result of running –version, –help, etc.
Name used in the “usage” output
value returned when the input file is not valid Ruby code
# File lib/mipsunit/mspec/runner.rb, line 58 def self.process_file(file_name) if file_name == '-' run_and_rescue { eval($stdin.read) } else if !File.exist?(file_name) then quit("File \"#{file_name}\" does not exist.", BAD_FILE) end if !File.readable?(file_name) then quit("File \"#{file_name}\" is not readable.", BAD_FILE) end if !File.file?(file_name) then quit("File \"#{file_name}\" is not a regular file.", BAD_FILE) end run_and_rescue { load(file_name) } end run_and_rescue do io = StringIO.new Generator.generate(MIPSUnit::MSpec.global.groups, io) $stdout.puts io.string end #begin # # The StringIO object allows us to defer printing anything to stdout # # until we are sure that there aren't any problems with the spec. # # (In other words, we don't want the output stream to print part of a test # # file, only to bail when an exception gets raised.) # io = StringIO.new # Generator.generate(MIPSUnit::MSpec.global.groups, io) # $stdout.puts io.string #rescue InvalidSpecException => e # $stderr.puts "Invalid spec file." # $stderr.puts e # exit INVALID_SPEC_FILE #end end
# File lib/mipsunit/mspec/runner.rb, line 36 def self.quit(message, value) $stderr.puts(message) exit_wrapper(value) end
# File lib/mipsunit/mspec/runner.rb, line 100 def self.run(args) if args.include?("--version") quit("MIPSUnit::MSpec version #{MIPSUnit::MSpec::VERSION}", META_OUTPUT) elsif (args.size < 1) usage else file_name = args[0] process_file(file_name) end end
# File lib/mipsunit/mspec/runner.rb, line 45 def self.run_and_rescue begin yield rescue InvalidSpecException => e $stderr.puts "Invalid spec file." $stderr.puts e.message # prints the backtrace so users can see the offending line of their file $stderr.puts $stderr.puts e.backtrace exit_wrapper INVALID_SPEC_FILE end end
# File lib/mipsunit/mspec/runner.rb, line 41 def self.usage quit("Usage: #{NAME} filename", BAD_USAGE) end