From e9de59b37bbd56a40f4597ecd74ac705742ce0dd Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 14 Apr 2015 00:36:24 +0000 Subject: [PATCH 1/5] Manage run control file path in Env --- lib/uh/wm/env.rb | 7 +++++-- spec/uh/wm/env_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/uh/wm/env.rb b/lib/uh/wm/env.rb index 029ab97..3c14d9b 100644 --- a/lib/uh/wm/env.rb +++ b/lib/uh/wm/env.rb @@ -1,6 +1,8 @@ module Uh module WM class Env + RC_PATH = '~/.uhwmrc.rb'.freeze + LOGGER_LEVEL = Logger::WARN LOGGER_LEVEL_VERBOSE = Logger::INFO LOGGER_LEVEL_DEBUG = Logger::DEBUG @@ -12,10 +14,11 @@ module Uh def_delegator :@output, :print attr_reader :output - attr_accessor :verbose, :debug, :layout_class + attr_accessor :verbose, :debug, :rc_path, :layout_class def initialize output - @output = output + @output = output + @rc_path = RC_PATH end def verbose? diff --git a/spec/uh/wm/env_spec.rb b/spec/uh/wm/env_spec.rb index 77cf3f3..e5280c6 100644 --- a/spec/uh/wm/env_spec.rb +++ b/spec/uh/wm/env_spec.rb @@ -13,6 +13,10 @@ module Uh expect(env).not_to be_debug end + it 'has the default rc path set' do + expect(env.rc_path).to eq '~/.uhwmrc.rb' + end + it 'has no layout_class set' do expect(env.layout_class).not_to be end From d6ae5d9446ff50554ab72659d3a4e489547ed556 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 14 Apr 2015 00:37:46 +0000 Subject: [PATCH 2/5] Add rspec helpers for filesystem --- spec/support/filesystem_helpers.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 spec/support/filesystem_helpers.rb diff --git a/spec/support/filesystem_helpers.rb b/spec/support/filesystem_helpers.rb new file mode 100644 index 0000000..8aa32d0 --- /dev/null +++ b/spec/support/filesystem_helpers.rb @@ -0,0 +1,11 @@ +require 'tempfile' + +module FileSystemHelpers + def with_file content + Tempfile.create('uhwm_rspec') do |f| + f.write content + f.rewind + yield f + end + end +end From 8165a1d4f579a77045a5f97cd866398d0371c326 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 14 Apr 2015 01:39:11 +0000 Subject: [PATCH 3/5] Mock home directory in all cucumber scenarios --- features/support/env.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/support/env.rb b/features/support/env.rb index 2dffcfa..09a839c 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -15,6 +15,10 @@ World(Uh::WM::Testing::AcceptanceHelpers) Headless.new.start +Before do + set_env 'HOME', File.expand_path(current_dir) +end + After do uhwm_ensure_stop end From 7493ab3284c9f3000621681f2329b4d5477fd918 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 14 Apr 2015 00:38:45 +0000 Subject: [PATCH 4/5] Evaluate run control file when present --- features/run_control/evaluation.feature | 10 +++++++++ features/steps/output_steps.rb | 4 ++++ lib/uh/wm/runner.rb | 6 +++++ spec/uh/wm/runner_spec.rb | 30 ++++++++++++++++++++++--- 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 features/run_control/evaluation.feature diff --git a/features/run_control/evaluation.feature b/features/run_control/evaluation.feature new file mode 100644 index 0000000..24eb4bd --- /dev/null +++ b/features/run_control/evaluation.feature @@ -0,0 +1,10 @@ +@mocked_home_directory +Feature: run control file evaluation + + Scenario: evaluates the default run control file when it exists + Given a file named .uhwmrc.rb with: + """ + puts 'run control evaluation' + """ + When I start uhwm + Then the output must contain "run control evaluation" diff --git a/features/steps/output_steps.rb b/features/steps/output_steps.rb index 21c51d4..b056e62 100644 --- a/features/steps/output_steps.rb +++ b/features/steps/output_steps.rb @@ -19,6 +19,10 @@ Then /^the output must contain:$/ do |content| uhwm_wait_output content.to_s end +Then /^the output must contain "([^"]+)"$/ do |content| + uhwm_wait_output content.to_s +end + Then /^the output must contain current display$/ do uhwm_wait_output ENV['DISPLAY'] end diff --git a/lib/uh/wm/runner.rb b/lib/uh/wm/runner.rb index 24c0675..e972cbe 100644 --- a/lib/uh/wm/runner.rb +++ b/lib/uh/wm/runner.rb @@ -4,6 +4,7 @@ module Uh class << self def run env, **options runner = new env, **options + runner.evaluate_run_control runner.register_event_hooks runner.connect_manager runner.run_until { runner.stopped? } @@ -30,6 +31,11 @@ module Uh @stopped = true end + def evaluate_run_control + rc_path = File.expand_path(@env.rc_path) + eval File.read(rc_path) if File.exist?(rc_path) + end + def register_event_hooks register_manager_hooks register_layout_event_hooks diff --git a/spec/uh/wm/runner_spec.rb b/spec/uh/wm/runner_spec.rb index 8149e84..02c41bd 100644 --- a/spec/uh/wm/runner_spec.rb +++ b/spec/uh/wm/runner_spec.rb @@ -1,3 +1,5 @@ +require 'support/filesystem_helpers' + SomeLayout = Class.new do define_method(:register) { |*args| } end @@ -5,10 +7,15 @@ end module Uh module WM RSpec.describe Runner do - let(:env) do - Env.new(StringIO.new).tap { |o| o.layout_class = SomeLayout } + include FileSystemHelpers + + let(:env) { Env.new(StringIO.new) } + subject(:runner) { described_class.new env } + + before do + env.layout_class = SomeLayout + env.rc_path = 'non_existent_run_control.rb' end - subject(:runner) { described_class.new env } describe '#initialize' do it 'assigns the env' do @@ -52,6 +59,23 @@ module Uh end end + describe '#evaluate_run_control' do + context 'when run control file exists' do + it 'evaluates the run control file' do + with_file 'throw :run_control' do |f| + env.rc_path = f.path + expect { runner.evaluate_run_control }.to throw_symbol :run_control + end + end + end + + context 'when run control file does not exist' do + it 'does not raise any error' do + expect { runner.evaluate_run_control }.not_to raise_error + end + end + end + describe '#register_event_hooks' do it 'registers manager event hooks for logging' do runner.register_event_hooks From 62c824cd7df0e47fdbb98ccf9a4424a26d2a80cb Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 14 Apr 2015 00:39:36 +0000 Subject: [PATCH 5/5] Specify alternate run control file path from CLI --- features/cli/run_control.feature | 9 +++++++++ features/steps/output_steps.rb | 1 + lib/uh/wm/cli.rb | 5 +++++ spec/uh/wm/cli_spec.rb | 9 +++++++++ 4 files changed, 24 insertions(+) create mode 100644 features/cli/run_control.feature diff --git a/features/cli/run_control.feature b/features/cli/run_control.feature new file mode 100644 index 0000000..84c7832 --- /dev/null +++ b/features/cli/run_control.feature @@ -0,0 +1,9 @@ +Feature: run control file path CLI option + + Scenario: changes the path to run control file + Given a file named uhwmrc.rb with: + """ + puts 'run control evaluation' + """ + When I run uhwm with option -f uhwmrc.rb + Then the output must contain "run control evaluation" diff --git a/features/steps/output_steps.rb b/features/steps/output_steps.rb index b056e62..e55109e 100644 --- a/features/steps/output_steps.rb +++ b/features/steps/output_steps.rb @@ -6,6 +6,7 @@ options: -h, --help print this message -v, --version enable verbose mode -d, --debug enable debug mode + -f, --run-control PATH specify alternate run control file -r, --require PATH require ruby feature -l, --layout LAYOUT specify layout eoh diff --git a/lib/uh/wm/cli.rb b/lib/uh/wm/cli.rb index b11715a..8853582 100644 --- a/lib/uh/wm/cli.rb +++ b/lib/uh/wm/cli.rb @@ -64,6 +64,11 @@ module Uh @env.log_logger_level end + opts.on '-f', '--run-control PATH', + 'specify alternate run control file' do |e| + @env.rc_path = e + end + opts.on '-r', '--require PATH', 'require ruby feature' do |feature| require feature @env.log "Loaded `#{feature}' ruby feature" diff --git a/spec/uh/wm/cli_spec.rb b/spec/uh/wm/cli_spec.rb index 32a53ac..7576c4c 100644 --- a/spec/uh/wm/cli_spec.rb +++ b/spec/uh/wm/cli_spec.rb @@ -148,6 +148,15 @@ module Uh end end + context 'with run control option' do + let(:arguments) { %w[-f uhwmrc.rb] } + + it 'assigns run control file path in the env' do + cli.parse_arguments! + expect(cli.env.rc_path).to eq 'uhwmrc.rb' + end + end + context 'with require option' do let(:arguments) { %w[-r abbrev] }