From 0a83563cadcbc037e135a4c1c65d5498d5637faf Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Wed, 15 Apr 2015 03:38:05 +0000 Subject: [PATCH] Improve error reporting on run control evaluation --- features/run_control/evaluation.feature | 9 +++++++++ lib/uh/wm/run_control.rb | 6 +++--- spec/uh/wm/run_control_spec.rb | 7 ++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/features/run_control/evaluation.feature b/features/run_control/evaluation.feature index e60c40b..32c280c 100644 --- a/features/run_control/evaluation.feature +++ b/features/run_control/evaluation.feature @@ -7,3 +7,12 @@ Feature: run control file evaluation """ When I start uhwm Then the output must contain "run control evaluation" + + Scenario: reports run control code in backtrace on errors + Given a run control file with: + """ + 'no error on first line' + fail 'fails on second line' + """ + When I start uhwm + Then the output must match /\.uhwmrc\.rb:2:.+fails on second line/ diff --git a/lib/uh/wm/run_control.rb b/lib/uh/wm/run_control.rb index 9beb390..7c68a3d 100644 --- a/lib/uh/wm/run_control.rb +++ b/lib/uh/wm/run_control.rb @@ -12,7 +12,7 @@ module Uh def evaluate env rc_path = File.expand_path(env.rc_path) rc = new env - rc.evaluate File.read(rc_path) if File.exist?(rc_path) + rc.evaluate File.read(rc_path), rc_path if File.exist?(rc_path) end end @@ -20,8 +20,8 @@ module Uh @env = env end - def evaluate code - instance_eval code + def evaluate code, path + instance_eval code, path end def key keysym, &block diff --git a/spec/uh/wm/run_control_spec.rb b/spec/uh/wm/run_control_spec.rb index a0f2f97..421ccc3 100644 --- a/spec/uh/wm/run_control_spec.rb +++ b/spec/uh/wm/run_control_spec.rb @@ -23,7 +23,8 @@ module Uh end it 'tells the new instance to evaluate run control file content' do - expect(rc).to receive(:evaluate).with ':run_control_code' + expect(rc) + .to receive(:evaluate).with(':run_control_code', env.rc_path) allow(described_class).to receive(:new) { rc } described_class.evaluate env end @@ -39,12 +40,12 @@ module Uh describe '#evaluate' do it 'evaluates given code' do - expect { rc.evaluate 'throw :run_control_code' } + expect { rc.evaluate 'throw :run_control_code', 'some_path' } .to throw_symbol :run_control_code end it 'provides access to assigned env' do - expect { rc.evaluate 'fail @env.object_id.to_s' } + expect { rc.evaluate 'fail @env.object_id.to_s', 'some_path' } .to raise_error env.object_id.to_s end end