Merge branch 'runcontrol-file'
This commit is contained in:
commit
4049bf255d
9
features/cli/run_control.feature
Normal file
9
features/cli/run_control.feature
Normal file
@ -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"
|
10
features/run_control/evaluation.feature
Normal file
10
features/run_control/evaluation.feature
Normal file
@ -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"
|
@ -6,6 +6,7 @@ options:
|
|||||||
-h, --help print this message
|
-h, --help print this message
|
||||||
-v, --version enable verbose mode
|
-v, --version enable verbose mode
|
||||||
-d, --debug enable debug mode
|
-d, --debug enable debug mode
|
||||||
|
-f, --run-control PATH specify alternate run control file
|
||||||
-r, --require PATH require ruby feature
|
-r, --require PATH require ruby feature
|
||||||
-l, --layout LAYOUT specify layout
|
-l, --layout LAYOUT specify layout
|
||||||
eoh
|
eoh
|
||||||
@ -19,6 +20,10 @@ Then /^the output must contain:$/ do |content|
|
|||||||
uhwm_wait_output content.to_s
|
uhwm_wait_output content.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then /^the output must contain "([^"]+)"$/ do |content|
|
||||||
|
uhwm_wait_output content.to_s
|
||||||
|
end
|
||||||
|
|
||||||
Then /^the output must contain current display$/ do
|
Then /^the output must contain current display$/ do
|
||||||
uhwm_wait_output ENV['DISPLAY']
|
uhwm_wait_output ENV['DISPLAY']
|
||||||
end
|
end
|
||||||
|
@ -15,6 +15,10 @@ World(Uh::WM::Testing::AcceptanceHelpers)
|
|||||||
|
|
||||||
Headless.new.start
|
Headless.new.start
|
||||||
|
|
||||||
|
Before do
|
||||||
|
set_env 'HOME', File.expand_path(current_dir)
|
||||||
|
end
|
||||||
|
|
||||||
After do
|
After do
|
||||||
uhwm_ensure_stop
|
uhwm_ensure_stop
|
||||||
end
|
end
|
||||||
|
@ -64,6 +64,11 @@ module Uh
|
|||||||
@env.log_logger_level
|
@env.log_logger_level
|
||||||
end
|
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|
|
opts.on '-r', '--require PATH', 'require ruby feature' do |feature|
|
||||||
require feature
|
require feature
|
||||||
@env.log "Loaded `#{feature}' ruby feature"
|
@env.log "Loaded `#{feature}' ruby feature"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
module Uh
|
module Uh
|
||||||
module WM
|
module WM
|
||||||
class Env
|
class Env
|
||||||
|
RC_PATH = '~/.uhwmrc.rb'.freeze
|
||||||
|
|
||||||
LOGGER_LEVEL = Logger::WARN
|
LOGGER_LEVEL = Logger::WARN
|
||||||
LOGGER_LEVEL_VERBOSE = Logger::INFO
|
LOGGER_LEVEL_VERBOSE = Logger::INFO
|
||||||
LOGGER_LEVEL_DEBUG = Logger::DEBUG
|
LOGGER_LEVEL_DEBUG = Logger::DEBUG
|
||||||
@ -12,10 +14,11 @@ module Uh
|
|||||||
def_delegator :@output, :print
|
def_delegator :@output, :print
|
||||||
|
|
||||||
attr_reader :output
|
attr_reader :output
|
||||||
attr_accessor :verbose, :debug, :layout_class
|
attr_accessor :verbose, :debug, :rc_path, :layout_class
|
||||||
|
|
||||||
def initialize output
|
def initialize output
|
||||||
@output = output
|
@output = output
|
||||||
|
@rc_path = RC_PATH
|
||||||
end
|
end
|
||||||
|
|
||||||
def verbose?
|
def verbose?
|
||||||
|
@ -4,6 +4,7 @@ module Uh
|
|||||||
class << self
|
class << self
|
||||||
def run env, **options
|
def run env, **options
|
||||||
runner = new env, **options
|
runner = new env, **options
|
||||||
|
runner.evaluate_run_control
|
||||||
runner.register_event_hooks
|
runner.register_event_hooks
|
||||||
runner.connect_manager
|
runner.connect_manager
|
||||||
runner.run_until { runner.stopped? }
|
runner.run_until { runner.stopped? }
|
||||||
@ -30,6 +31,11 @@ module Uh
|
|||||||
@stopped = true
|
@stopped = true
|
||||||
end
|
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
|
def register_event_hooks
|
||||||
register_manager_hooks
|
register_manager_hooks
|
||||||
register_layout_event_hooks
|
register_layout_event_hooks
|
||||||
|
11
spec/support/filesystem_helpers.rb
Normal file
11
spec/support/filesystem_helpers.rb
Normal file
@ -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
|
@ -148,6 +148,15 @@ module Uh
|
|||||||
end
|
end
|
||||||
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
|
context 'with require option' do
|
||||||
let(:arguments) { %w[-r abbrev] }
|
let(:arguments) { %w[-r abbrev] }
|
||||||
|
|
||||||
|
@ -13,6 +13,10 @@ module Uh
|
|||||||
expect(env).not_to be_debug
|
expect(env).not_to be_debug
|
||||||
end
|
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
|
it 'has no layout_class set' do
|
||||||
expect(env.layout_class).not_to be
|
expect(env.layout_class).not_to be
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
require 'support/filesystem_helpers'
|
||||||
|
|
||||||
SomeLayout = Class.new do
|
SomeLayout = Class.new do
|
||||||
define_method(:register) { |*args| }
|
define_method(:register) { |*args| }
|
||||||
end
|
end
|
||||||
@ -5,10 +7,15 @@ end
|
|||||||
module Uh
|
module Uh
|
||||||
module WM
|
module WM
|
||||||
RSpec.describe Runner do
|
RSpec.describe Runner do
|
||||||
let(:env) do
|
include FileSystemHelpers
|
||||||
Env.new(StringIO.new).tap { |o| o.layout_class = SomeLayout }
|
|
||||||
|
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
|
end
|
||||||
subject(:runner) { described_class.new env }
|
|
||||||
|
|
||||||
describe '#initialize' do
|
describe '#initialize' do
|
||||||
it 'assigns the env' do
|
it 'assigns the env' do
|
||||||
@ -52,6 +59,23 @@ module Uh
|
|||||||
end
|
end
|
||||||
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
|
describe '#register_event_hooks' do
|
||||||
it 'registers manager event hooks for logging' do
|
it 'registers manager event hooks for logging' do
|
||||||
runner.register_event_hooks
|
runner.register_event_hooks
|
||||||
|
Loading…
x
Reference in New Issue
Block a user