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.
This commit is contained in:
Daniel Schadt 2016-09-08 23:14:10 +02:00
parent f6c6f766cd
commit b0114768c7
3 changed files with 27 additions and 7 deletions

View File

@ -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 %*

View File

@ -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)

View File

@ -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