diff --git a/README.md b/README.md index baf3091..436a421 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ options: -f, --run-control PATH specify alternate run control file -r, --require PATH require ruby feature -l, --layout LAYOUT specify layout + -w, --worker WORKER specify worker ``` diff --git a/features/cli/worker.feature b/features/cli/worker.feature new file mode 100644 index 0000000..94162e7 --- /dev/null +++ b/features/cli/worker.feature @@ -0,0 +1,9 @@ +Feature: worker CLI option + + Scenario: uses the blocking worker when `block' is given + When I run uhwm with option -v -w block + Then the output must match /work.+event.+block/i + + Scenario: uses the multiplexing worker when `mux' is given + When I run uhwm with option -v -w mux + Then the output must match /work.+event.+mux/i diff --git a/features/steps/output_steps.rb b/features/steps/output_steps.rb index 73cd67f..875bf1a 100644 --- a/features/steps/output_steps.rb +++ b/features/steps/output_steps.rb @@ -9,6 +9,7 @@ options: -f, --run-control PATH specify alternate run control file -r, --require PATH require ruby feature -l, --layout LAYOUT specify layout + -w, --worker WORKER specify worker eoh end diff --git a/lib/uh/wm/cli.rb b/lib/uh/wm/cli.rb index 8853582..12631d9 100644 --- a/lib/uh/wm/cli.rb +++ b/lib/uh/wm/cli.rb @@ -77,6 +77,11 @@ module Uh opts.on '-l', '--layout LAYOUT', 'specify layout' do |layout| @env.layout_class = self.class.const_get layout.to_sym end + + opts.on '-w', Workers.types, '--worker WORKER', + 'specify worker' do |worker| + @env.worker = worker.to_sym + end end end end diff --git a/lib/uh/wm/runner.rb b/lib/uh/wm/runner.rb index 8bee78b..582869a 100644 --- a/lib/uh/wm/runner.rb +++ b/lib/uh/wm/runner.rb @@ -73,7 +73,9 @@ module Uh end def run_until &block - manager.handle_pending_events until block.call + worker.watch @manager + @env.log "Working events with `#{worker.class}'" + worker.work_events until block.call end def terminate diff --git a/spec/uh/wm/cli_spec.rb b/spec/uh/wm/cli_spec.rb index 6bcf551..027546c 100644 --- a/spec/uh/wm/cli_spec.rb +++ b/spec/uh/wm/cli_spec.rb @@ -176,6 +176,15 @@ module Uh end end + context 'with worker option' do + let(:arguments) { %w[-w mux] } + + it 'assigns the worker type in the env' do + cli.parse_arguments! + expect(cli.env.worker).to eq :mux + end + end + context 'with invalid option' do let(:arguments) { %w[--unknown-option] } diff --git a/spec/uh/wm/runner_spec.rb b/spec/uh/wm/runner_spec.rb index 863abba..bda4bef 100644 --- a/spec/uh/wm/runner_spec.rb +++ b/spec/uh/wm/runner_spec.rb @@ -144,10 +144,15 @@ module Uh end describe '#run_until' do - it 'tells the manager to handle events until given block is true' do + it 'tells the worker to watch the manager' do + expect(runner.worker).to receive(:watch).with runner.manager + runner.run_until { true } + end + + it 'tells the worker to work events until given block is true' do block = proc { } allow(block).to receive(:call).and_return(false, false, false, true) - expect(runner.manager).to receive(:handle_pending_events).exactly(3).times + expect(runner.worker).to receive(:work_events).exactly(3).times runner.run_until &block end end