lib/rgot/common.rb in rgot-0.0.5 vs lib/rgot/common.rb in rgot-0.1.0
- old
+ new
@@ -1,64 +1,88 @@
+require 'thread'
+
module Rgot
class Common
+ attr_accessor :output
+
def initialize
@output = ""
@failed = false
@skipped = false
@finished = false
@start = Rgot.now
+ @mutex = Mutex.new
end
def failed?
- @failed
+ @mutex.synchronize { @failed }
end
def skipped?
- @skipped
+ @mutex.synchronize { @skipped }
end
def finished?
- @finished
+ @mutex.synchronize { @finished }
end
def fail!
- @failed = true
+ @mutex.synchronize { @failed = true }
end
def skip!
- @skipped = true
+ @mutex.synchronize { @skipped = true }
end
def finish!
- @finished = true
+ @mutex.synchronize { @finished = true }
end
def log(*args)
- internal_log(sprintf(*args))
+ internal_log(args.map(&:to_s).join(' '))
end
- def skip(*args)
+ def logf(*args)
internal_log(sprintf(*args))
- skip_now
end
- def skip_now
- skip!
- finish!
- throw :skip
+ def error(*args)
+ internal_log(args.map(&:to_s).join(' '))
+ fail!
end
- def error(*args)
+ def errorf(*args)
internal_log(sprintf(*args))
fail!
end
- def fatal(msg)
- internal_log(msg)
+ def fatal(*args)
+ internal_log(args.map(&:to_s).join(' '))
fail_now
end
+ def fatalf(*args)
+ internal_log(sprintf(*args))
+ fail_now
+ end
+
+ def skip(*args)
+ internal_log(args.map(&:to_s).join(' '))
+ skip_now
+ end
+
+ def skipf(*args)
+ internal_log(sprintf(*args))
+ skip_now
+ end
+
+ def skip_now
+ skip!
+ finish!
+ throw :skip
+ end
+
def fail_now
fail!
finish!
throw :skip
end
@@ -72,9 +96,9 @@
relative_path = Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd)).to_s
"\t#{relative_path}:#{line}: #{str}\n"
end
def internal_log(msg)
- @output << decorate(msg)
+ @mutex.synchronize { @output << decorate(msg) }
end
end
end