diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index 1c8f0db28..d3ef3cd70 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -22,6 +22,7 @@ import re import pprint +import os.path def print_i(text, indent, error=False): @@ -101,3 +102,13 @@ def pattern_match(*, pattern, value): """ re_pattern = '.*'.join(re.escape(part) for part in pattern.split('*')) return re.fullmatch(re_pattern, value) is not None + + +def abs_datapath(): + """Get the absolute path to the integration data directory. + + Return: + The absolute path to the tests/integration/data directory. + """ + file_abs = os.path.abspath(os.path.dirname(__file__)) + return os.path.join(file_abs, '..', 'integration', 'data') diff --git a/tests/integration/data/userscripts/open_current_url b/tests/integration/data/userscripts/open_current_url new file mode 100755 index 000000000..6d7f6dc36 --- /dev/null +++ b/tests/integration/data/userscripts/open_current_url @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "open -t $QUTE_URL" >> "$QUTE_FIFO" diff --git a/tests/integration/features/conftest.py b/tests/integration/features/conftest.py index 03559ede7..a099a1887 100644 --- a/tests/integration/features/conftest.py +++ b/tests/integration/features/conftest.py @@ -129,9 +129,24 @@ def run_command(quteproc, httpbin, command): else: count = None command = command.replace('(port)', str(httpbin.port)) + quteproc.send_cmd(command, count=count) +@bdd.when(bdd.parsers.parse("I execute the userscript {userscript}")) +def run_userscript(quteproc, userscript): + """Run a userscript located in tests/integration/data/userscripts. + + Wrapper around :spawn --userscript {userscript} that uses an absolute + path. + """ + abs_userscript_path = os.path.join(utils.abs_datapath(), + 'userscripts', userscript) + + cmd = ':spawn --userscript {abs_userscript_path}' + quteproc.send_cmd(cmd.format(abs_userscript_path=abs_userscript_path)) + + @bdd.when(bdd.parsers.parse("I reload")) def reload(qtbot, httpbin, quteproc, command): """Reload and wait until a new request is received.""" @@ -334,8 +349,8 @@ def check_contents(quteproc, filename): The filename is interpreted relative to tests/integration/data. """ content = quteproc.get_content(plain=False) - path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', - 'data', os.path.join(*filename.split('/'))) + path = os.path.join(utils.abs_datapath(), + os.path.join(*filename.split('/'))) with open(path, 'r', encoding='utf-8') as f: file_content = f.read() assert content == file_content diff --git a/tests/integration/features/spawn.feature b/tests/integration/features/spawn.feature new file mode 100644 index 000000000..03506c18b --- /dev/null +++ b/tests/integration/features/spawn.feature @@ -0,0 +1,25 @@ +Feature: :spawn + + Scenario: Running :spawn + When I run :spawn -v echo "Hello" + Then the message "Command exited successfully." should be shown + + Scenario: Running :spawn with command that does not exist + When I run :spawn command_does_not_exist127623 + Then the error "Error while spawning command: The process failed to start." should be shown + + Scenario: Running :spawn with invalid quoting + When I run :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 + + @posix + Scenario: Running :spawn with userscript + When I execute the userscript open_current_url + And I wait until about:blank is loaded + Then the following tabs should be open: + - about:blank + - about:blank (active) diff --git a/tests/integration/features/test_spawn.py b/tests/integration/features/test_spawn.py new file mode 100644 index 000000000..e9ddf0301 --- /dev/null +++ b/tests/integration/features/test_spawn.py @@ -0,0 +1,21 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015-2016 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +import pytest_bdd as bdd +bdd.scenarios('spawn.feature')