diff --git a/features/cli/debug.feature b/features/cli/debug.feature index 19f1497..018f899 100644 --- a/features/cli/debug.feature +++ b/features/cli/debug.feature @@ -2,4 +2,4 @@ Feature: debug CLI option Scenario: raises the logger level to DEBUG When I run uhwm with option -d - Then the current output must match /log.+debug.+level/i + Then the output must match /log.+debug.+level/i diff --git a/features/cli/ruby_features.feature b/features/cli/ruby_features.feature index ff60e3d..da971fa 100644 --- a/features/cli/ruby_features.feature +++ b/features/cli/ruby_features.feature @@ -2,4 +2,4 @@ Feature: ruby feature require CLI option Scenario: requires a ruby feature When I run uhwm with option -v -r abbrev - Then the current output must match /load.+abbrev.+ruby feature/i + Then the output must match /load.+abbrev.+ruby feature/i diff --git a/features/cli/verbose.feature b/features/cli/verbose.feature index ff5b080..0e0ece5 100644 --- a/features/cli/verbose.feature +++ b/features/cli/verbose.feature @@ -2,4 +2,4 @@ Feature: verbose CLI option Scenario: raises the logger level to INFO When I run uhwm with option -v - Then the current output must match /log.+info.+level/i + Then the output must match /log.+info.+level/i diff --git a/features/layout/registration.feature b/features/layout/registration.feature index 5a71c60..8aae571 100644 --- a/features/layout/registration.feature +++ b/features/layout/registration.feature @@ -10,4 +10,4 @@ Feature: layout registration end """ When I run uhwm with option -r./layout -l Layout - Then the current output must contain current display + Then the output must contain current display diff --git a/features/manager/check_other_wm.feature b/features/manager/check_other_wm.feature index 3e71a0a..f5b4390 100644 --- a/features/manager/check_other_wm.feature +++ b/features/manager/check_other_wm.feature @@ -5,4 +5,4 @@ Feature: checking if another window manager is running Given another window manager is running When I start uhwm Then the exit status must be 70 - And the current output must match /error.+other.+window.+manager/i + And the output must match /error.+other.+window.+manager/i diff --git a/features/steps/output_steps.rb b/features/steps/output_steps.rb index bfad39a..21c51d4 100644 --- a/features/steps/output_steps.rb +++ b/features/steps/output_steps.rb @@ -1,20 +1,3 @@ -def uhwm_wait_output message, timeout: 1 - Timeout.timeout(timeout) do - loop do - break if case message - when Regexp then @process.stdout + @process.stderr =~ message - when String then assert_partial_output_interactive message - end - sleep 0.1 - end - end -rescue Timeout::Error - fail [ - "expected `#{message}' not seen after #{timeout} seconds in:", - " ```\n #{@process.stdout + @process.stderr} ```" - ].join "\n" -end - Then /^the output must contain exactly the usage$/ do assert_exact_output <<-eoh, all_output Usage: uhwm [options] @@ -29,17 +12,13 @@ options: end Then /^the output must match \/([^\/]+)\/([a-z]*)$/ do |pattern, options| - expect(@process.stdout).to match Regexp.new(pattern, options) -end - -Then /^the current output must match \/([^\/]+)\/([a-z]*)$/ do |pattern, options| uhwm_wait_output Regexp.new(pattern, options) end -Then /^the current output must contain:$/ do |content| +Then /^the output must contain:$/ do |content| uhwm_wait_output content.to_s end -Then /^the current output must contain current display$/ do +Then /^the output must contain current display$/ do uhwm_wait_output ENV['DISPLAY'] end diff --git a/features/steps/run_steps.rb b/features/steps/run_steps.rb index 534e20f..3470126 100644 --- a/features/steps/run_steps.rb +++ b/features/steps/run_steps.rb @@ -1,16 +1,5 @@ -def uhwm_run options = '-v' - command = %w[uhwm] - command << options if options - @interactive = @process = run command.join ' ' -end - -def uhwm_run_wait_ready - uhwm_run - uhwm_wait_output 'Connected to' -end - Given /^another window manager is running$/ do - expect(@other_wm).to be_alive + expect(other_wm).to be_alive end Given /^uhwm is running$/ do diff --git a/features/steps/x_steps.rb b/features/steps/x_steps.rb index 9db1e28..844d6c2 100644 --- a/features/steps/x_steps.rb +++ b/features/steps/x_steps.rb @@ -1,21 +1,8 @@ -def x_key key - fail "cannot simulate X key `#{key}'" unless system "xdotool key #{key}" -end - -def x_socket_check pid - case RbConfig::CONFIG['host_os'] - when /linux/ - `netstat -xp 2> /dev/null`.lines.grep /\s+#{pid}\/ruby/ - else - `sockstat -u`.lines.grep /\s+ruby.+\s+#{pid}/ - end.any? -end - When /^I press the default quit key binding$/ do x_key 'alt+q' end Then /^it must connect to X display$/ do uhwm_wait_output 'Connected to' - expect(x_socket_check @process.pid).to be true + expect(x_socket_check uhwm_pid).to be true end diff --git a/features/support/env.rb b/features/support/env.rb index b43e86b..e1ccd36 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,6 +1,8 @@ require 'aruba/cucumber' require 'headless' +require 'uh/wm/testing/acceptance_helpers' + module Aruba class SpawnProcess def pid @@ -9,15 +11,14 @@ module Aruba end end +World(Uh::WM::Testing::AcceptanceHelpers) + Headless.new.start After do |scenario| - @process and @process.terminate + uhwm_ensure_stop end Around '@other_wm_running' do |scenario, block| - @other_wm = ChildProcess.build('twm') - @other_wm.start - block.call - @other_wm.stop + with_other_wm { block.call } end diff --git a/lib/uh/wm/testing/acceptance_helpers.rb b/lib/uh/wm/testing/acceptance_helpers.rb new file mode 100644 index 0000000..c3135a0 --- /dev/null +++ b/lib/uh/wm/testing/acceptance_helpers.rb @@ -0,0 +1,69 @@ +module Uh + module WM + module Testing + module AcceptanceHelpers + def uhwm_run options = '-v' + command = %w[uhwm] + command << options if options + @interactive = @process = run command.join ' ' + end + + def uhwm_ensure_stop + @process and @process.terminate + end + + def uhwm_pid + @process.pid + end + + def uhwm_output + @process.stdout + end + + def uhwm_wait_output message, timeout: 1 + Timeout.timeout(timeout) do + loop do + break if case message + when Regexp then @process.stdout + @process.stderr =~ message + when String then assert_partial_output_interactive message + end + sleep 0.1 + end + end + rescue Timeout::Error + fail [ + "expected `#{message}' not seen after #{timeout} seconds in:", + " ```\n #{@process.stdout + @process.stderr} ```" + ].join "\n" + end + + def uhwm_run_wait_ready + uhwm_run + uhwm_wait_output 'Connected to' + end + + def with_other_wm + @other_wm = ChildProcess.build('twm').tap { |o| o.start } + @other_wm.stop + end + + def other_wm + @other_wm + end + + def x_key key + fail "cannot simulate X key `#{key}'" unless system "xdotool key #{key}" + end + + def x_socket_check pid + case RbConfig::CONFIG['host_os'] + when /linux/ + `netstat -xp 2> /dev/null`.lines.grep /\s+#{pid}\/ruby/ + else + `sockstat -u`.lines.grep /\s+ruby.+\s+#{pid}/ + end.any? + end + end + end + end +end