lib/tryouts.rb in tryouts-0.6.2 vs lib/tryouts.rb in tryouts-0.6.3
- old
+ new
@@ -1,12 +1,15 @@
+require 'time'
require 'sysinfo'
+require 'digest/sha1'
require 'ostruct'
require 'yaml'
+
begin; require 'json'; rescue LoadError; end # json may not be installed
-GYMNASIUM_HOME = File.join(Dir.pwd, 'tryouts') ## also check try (for rye)
+GYMNASIUM_HOME = File.join(Dir.pwd, '{tryouts,try}') ## also check try (for rye)
GYMNASIUM_GLOB = File.join(GYMNASIUM_HOME, '**', '*_tryouts.rb')
# = Tryouts
#
@@ -27,11 +30,11 @@
class Exception < RuntimeError; end
# = BadDreams
# Raised when there is a problem loading or parsing a Tryouts::Drill::Dream object
class BadDreams < Exception; end
- VERSION = "0.6.2"
+ VERSION = "0.6.3"
require 'tryouts/mixins'
require 'tryouts/tryout'
require 'tryouts/drill'
@@ -49,18 +52,22 @@
# An instance of SysInfo
@@sysinfo = SysInfo.new
@@debug = false
@@verbose = 0
+ # This will be true if any error occurred during any of the drills or parsing.
+ @@failed = false
def self.debug?; @@debug; end
def self.enable_debug; @@debug = true; end
def self.disable_debug; @@debug = false; end
def self.verbose; @@verbose; end
def self.verbose=(v); @@verbose = (v == true) ? 1 : v; end
+ def self.failed?; @@failed; end
+ def self.failed=(v); @@failed = v; end
# Returns +@@instances+
def self.instances; @@instances; end
# Returns +@@sysinfo+
def self.sysinfo; @@sysinfo; end
@@ -75,15 +82,17 @@
attr_accessor :tryouts
# A Symbol representing the command taking part in the tryouts. For @dtype :cli only.
attr_accessor :command
# A Symbol representing the name of the library taking part in the tryouts. For @dtype :api only.
attr_accessor :library
-
+ # An Array of exceptions that were raised during the tryouts that were not captured by a drill.
+ attr_reader :errors
+
def initialize(group=nil)
@group = group || "Default Group"
@tryouts = HASH_TYPE.new
- @paths = []
+ @paths, @errors = [], []
@command = nil
end
# Populate this Tryouts from a block. The block should contain calls to
# the external DSL methods: tryout, command, library, group
@@ -129,11 +138,17 @@
def library(name=nil, path=nil)
return @library if name.nil?
@library = name.to_sym
@dtype = :api
$LOAD_PATH.unshift path unless path.nil?
- require @library.to_s
+ begin
+ require @library.to_s
+ rescue SyntaxError, LoadError, Exception,
+ RuntimeError, NoMethodError, NameError => ex
+ @errors << ex
+ Tryouts.failed = true
+ end
end
# Calls Tryouts#library on the current instance of Tryouts
#
# NOTE: this is a standalone DSL-syntax method.
def self.library(*args)
@@ -172,11 +187,17 @@
to = Tryouts::Tryout.new(name, dtype, command)
@tryouts[name] = to
end
# Process the rest of the DSL
- to.from_block block if block
+ begin
+ to.from_block block if block
+ rescue SyntaxError, LoadError, Exception,
+ RuntimeError, NoMethodError, NameError => ex
+ @errors << ex
+ Tryouts.failed = true
+ end
to
end
# Calls Tryouts#tryout on the current instance of Tryouts
#
# NOTE: this is a standalone DSL-syntax method.
@@ -219,16 +240,26 @@
# NOTE: this is an OO syntax method
def self.parse_file(fpath)
raise "No such file: #{fpath}" unless File.exists?(fpath)
file_content = File.read(fpath)
to = Tryouts.new
- to.instance_eval file_content, fpath
- if @@instances.has_key? to.group
- to = @@instances[to.group]
+ begin
to.instance_eval file_content, fpath
+ # After parsing the DSL, we'll know the group name.
+ # If a Tryouts object already exists for that group
+ # we'll use that instead and re-parse the DSL.
+ if @@instances.has_key? to.group
+ to = @@instances[to.group]
+ to.instance_eval file_content, fpath
+ end
+ to.paths << fpath
+ rescue SyntaxError, LoadError, Exception,
+ RuntimeError, NoMethodError, NameError => ex
+ to.errors << ex
+ Tryouts.failed = true
end
- to.paths << fpath
@@instances[to.group] = to
+ to
end
# Run all Tryout objects in +@tryouts+
#
# NOTE: this is an OO syntax method