From b0114768c754a8ed598adc90fe725ae08ebfaa3f Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 8 Sep 2016 23:14:10 +0200 Subject: [PATCH] fix spawn tests on Windows On Windows, no echo.exe exists normally, so calling echo from the tests is no good idea, since it relies on Cygwin to be installed and in %PATH% (so that echo.exe is available). This fixes this by providing a small echo.bat which is callable from the tests, and then using a platform-specific path to the executable instead of the hardcoded "echo". This should ensure that the tests pass even on systems where echo.exe is not installed. Note that we can't simply use a do-nothing exe (like rundll or hh.exe), as we're passing parameters, and those executables may behave differently in the presence of those parameters. --- tests/end2end/data/userscripts/echo.bat | 6 ++++++ tests/end2end/features/conftest.py | 14 ++++++++++++++ tests/end2end/features/spawn.feature | 14 +++++++------- 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 tests/end2end/data/userscripts/echo.bat diff --git a/tests/end2end/data/userscripts/echo.bat b/tests/end2end/data/userscripts/echo.bat new file mode 100644 index 000000000..0f37ae2cd --- /dev/null +++ b/tests/end2end/data/userscripts/echo.bat @@ -0,0 +1,6 @@ +@echo off +rem This is needed because echo does not exist as an external program on +rem Windows, so we can't call echo(.exe) from qutebrowser, but it's useful for +rem tests. This little file is callable via :spawn and mimics (in a very naive +rem way) the echo command line utility. +echo %* diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py index 100c15f0c..1dccf6d6e 100644 --- a/tests/end2end/features/conftest.py +++ b/tests/end2end/features/conftest.py @@ -19,6 +19,7 @@ """Steps for bdd-like tests.""" +import os import re import sys import time @@ -34,6 +35,18 @@ from qutebrowser.utils import log from helpers import utils +def get_echo_exe_path(): + """Return the path to an echo-like command, depending on the system. + + Return: + Path to the "echo"-utility. + """ + if sys.platform == "win32": + return os.path.join(utils.abs_datapath(), 'userscripts', 'echo.bat') + else: + return 'echo' + + @pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item, call): """Add a BDD section to the test output.""" @@ -215,6 +228,7 @@ def run_command(quteproc, httpbin, tmpdir, command): command = command.replace('(port)', str(httpbin.port)) command = command.replace('(testdata)', utils.abs_datapath()) command = command.replace('(tmpdir)', str(tmpdir)) + command = command.replace('(echo-exe)', get_echo_exe_path()) quteproc.send_cmd(command, count=count, invalid=invalid) diff --git a/tests/end2end/features/spawn.feature b/tests/end2end/features/spawn.feature index 469120cc2..5cdeac029 100644 --- a/tests/end2end/features/spawn.feature +++ b/tests/end2end/features/spawn.feature @@ -1,7 +1,7 @@ Feature: :spawn Scenario: Running :spawn - When I run :spawn -v echo "Hello" + When I run :spawn -v (echo-exe) "Hello" Then the message "Command exited successfully." should be shown Scenario: Running :spawn with command that does not exist @@ -19,18 +19,18 @@ Feature: :spawn Then the error "Error while splitting command: No closing quotation" should be shown Scenario: Running :spawn with url variable - When I run :spawn echo {url} - Then "Executing echo with args ['about:blank'], userscript=False" should be logged + When I run :spawn (echo-exe) {url} + Then "Executing * with args ['about:blank'], userscript=False" should be logged Scenario: Running :spawn with url variable in fully encoded format When I open data/title with spaces.html - And I run :spawn echo {url} - Then "Executing echo with args ['http://localhost:(port)/data/title%20with%20spaces.html'], userscript=False" should be logged + And I run :spawn (echo-exe) {url} + Then "Executing * with args ['http://localhost:(port)/data/title%20with%20spaces.html'], userscript=False" should be logged Scenario: Running :spawn with url variable in pretty decoded format When I open data/title with spaces.html - And I run :spawn echo {url:pretty} - Then "Executing echo with args ['http://localhost:(port)/data/title with spaces.html'], userscript=False" should be logged + And I run :spawn (echo-exe) {url:pretty} + Then "Executing * with args ['http://localhost:(port)/data/title with spaces.html'], userscript=False" should be logged @posix Scenario: Running :spawn with userscript