From e7d6ffbe50058c413ea3d491b0747d27eda604b0 Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 19 Dec 2013 17:48:49 -0500 Subject: [PATCH] Added verbose logger. --- lib/bwoken.rb | 14 ++++++++++++++ lib/bwoken/build.rb | 2 ++ lib/bwoken/cli/test.rb | 1 + lib/bwoken/script.rb | 2 ++ spec/lib/bwoken/script_spec.rb | 7 +++++++ 5 files changed, 26 insertions(+) diff --git a/lib/bwoken.rb b/lib/bwoken.rb index e9c9a67..05d3dca 100644 --- a/lib/bwoken.rb +++ b/lib/bwoken.rb @@ -1,4 +1,5 @@ require 'fileutils' +require 'logger' module Bwoken class << self @@ -78,5 +79,18 @@ def results_path end end + def verbose=(value) + @verbose = value + end + + def verbose + !! @verbose + end + + def logger + @logger ||= Logger.new(STDOUT).tap do |logger| + logger.level = verbose ? Logger::DEBUG : Logger::INFO + end + end end end diff --git a/lib/bwoken/build.rb b/lib/bwoken/build.rb index e46f226..f55d0c3 100644 --- a/lib/bwoken/build.rb +++ b/lib/bwoken/build.rb @@ -76,6 +76,8 @@ def cmd def compile formatter.before_build_start + Bwoken.logger.debug cmd + succeeded, out_string, err_string = RUBY_VERSION == '1.8.7' ? compile_18 : compile_19_plus if succeeded diff --git a/lib/bwoken/cli/test.rb b/lib/bwoken/cli/test.rb index 78f1e5e..895776e 100644 --- a/lib/bwoken/cli/test.rb +++ b/lib/bwoken/cli/test.rb @@ -61,6 +61,7 @@ def initialize opts Bwoken.integration_path = options[:'integration-path'] Bwoken.app_name = options[:'product-name'] + Bwoken.verbose = options[:'verbose'] end def run diff --git a/lib/bwoken/script.rb b/lib/bwoken/script.rb index 11df9bf..b9f78b0 100644 --- a/lib/bwoken/script.rb +++ b/lib/bwoken/script.rb @@ -50,6 +50,8 @@ def device_flag def run formatter.before_script_run path + Bwoken.logger.debug cmd + Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| exit_status = formatter.format stdout raise ScriptFailedError.new('Test Script Failed') unless exit_status == 0 diff --git a/spec/lib/bwoken/script_spec.rb b/spec/lib/bwoken/script_spec.rb index 1411b23..86ab0cd 100644 --- a/spec/lib/bwoken/script_spec.rb +++ b/spec/lib/bwoken/script_spec.rb @@ -33,6 +33,13 @@ class Simulator; end subject.run end + it 'logs the command being run' do + subject.stub(:cmd).and_return('cmd') + Open3.stub(:popen3) + Bwoken.logger.should_receive(:debug).with('cmd') + subject.run + end + context 'when passing' do it 'does not raise a ScriptFailedError' do Open3.stub(:popen3).and_yield(*%w(in out err thr))