summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-09-05 00:25:01 -0400
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-09-05 01:59:34 -0400
commitbbba6052808e5a729ba8cc0c63c3e232e1b204ef (patch)
tree614cd866f1e7e5cbf975b3e4de07d8bffb5c504c
parent5d6370169c145f3e21d823abd997145137ff6ae3 (diff)
downloadbuildstream-bbba6052808e5a729ba8cc0c63c3e232e1b204ef.tar.gz
tests/completions/completions.py: Adding new test for bash completions
-rw-r--r--tests/completions/completions.py193
-rw-r--r--tests/completions/project/elements/compose-all.bst12
-rw-r--r--tests/completions/project/elements/compose-exclude-dev.bst16
-rw-r--r--tests/completions/project/elements/compose-include-bin.bst16
-rw-r--r--tests/completions/project/elements/import-bin.bst4
-rw-r--r--tests/completions/project/elements/import-dev.bst4
-rw-r--r--tests/completions/project/elements/target.bst8
-rwxr-xr-xtests/completions/project/files/bin-files/usr/bin/hello3
-rw-r--r--tests/completions/project/files/dev-files/usr/include/pony.h12
-rw-r--r--tests/completions/project/project.conf4
10 files changed, 272 insertions, 0 deletions
diff --git a/tests/completions/completions.py b/tests/completions/completions.py
new file mode 100644
index 000000000..4dbb68519
--- /dev/null
+++ b/tests/completions/completions.py
@@ -0,0 +1,193 @@
+import os
+import pytest
+from tests.testutils import cli
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project",
+)
+
+MAIN_COMMANDS = [
+ 'build ',
+ 'checkout ',
+ 'fetch ',
+ 'pull ',
+ 'push ',
+ 'shell ',
+ 'show ',
+ 'source-bundle ',
+ 'track ',
+ 'workspace '
+]
+
+MAIN_OPTIONS = [
+ "-a ",
+ "--arch ",
+ "--builders ",
+ "-c ",
+ "-C ",
+ "--colors ",
+ "--config ",
+ "--debug ",
+ "--directory ",
+ "--error-lines ",
+ "--fetchers ",
+ "--host-arch ",
+ "--log-file ",
+ "--message-lines ",
+ "--network-retries ",
+ "--no-colors ",
+ "--no-debug ",
+ "--no-interactive ",
+ "--no-strict ",
+ "--no-verbose ",
+ "--on-error ",
+ "--pushers ",
+ "--strict ",
+ "--target-arch ",
+ "--verbose ",
+ "--version ",
+]
+
+WORKSPACE_COMMANDS = [
+ 'close ',
+ 'list ',
+ 'open ',
+ 'reset '
+]
+
+PROJECT_ELEMENTS = [
+ "compose-all.bst",
+ "compose-exclude-dev.bst",
+ "compose-include-bin.bst",
+ "import-bin.bst",
+ "import-dev.bst",
+ "target.bst"
+]
+
+
+def assert_completion(cli, cmd, word_idx, expected, cwd=None):
+ result = cli.run(cwd=cwd, env={
+ '_BST_COMPLETION': 'complete',
+ 'COMP_WORDS': cmd,
+ 'COMP_CWORD': str(word_idx)
+ })
+ words = []
+ if result.output:
+ words = result.output.splitlines()
+
+ # The order is meaningless, bash will
+ # take the results and order it by it's
+ # own little heuristics
+ words = sorted(words)
+ expected = sorted(expected)
+ assert words == expected
+
+
+@pytest.mark.parametrize("cmd,word_idx,expected", [
+ ('bst', 0, []),
+ ('bst ', 1, MAIN_COMMANDS),
+ ('bst pu', 1, ['pull ', 'push ']),
+ ('bst pul', 1, ['pull ']),
+ ('bst w ', 1, ['workspace ']),
+ ('bst workspace ', 2, WORKSPACE_COMMANDS),
+])
+def test_commands(cli, cmd, word_idx, expected):
+ assert_completion(cli, cmd, word_idx, expected)
+
+
+@pytest.mark.parametrize("cmd,word_idx,expected", [
+ ('bst -', 1, MAIN_OPTIONS),
+ ('bst --l', 1, ['--log-file ']),
+
+ # Test that options of subcommands also complete
+ ('bst --no-colors build -', 3, ['--all ', '--track ', '--variant ']),
+
+ # Test the behavior of completing after an option that has a
+ # parameter that cannot be completed, vs an option that has
+ # no parameter
+ ('bst --fetchers ', 2, []),
+ ('bst --no-colors ', 2, MAIN_COMMANDS),
+])
+def test_options(cli, cmd, word_idx, expected):
+ assert_completion(cli, cmd, word_idx, expected)
+
+
+@pytest.mark.parametrize("cmd,word_idx,expected", [
+ ('bst --on-error ', 2, ['continue ', 'quit ', 'terminate ']),
+ ('bst show --deps ', 3, ['all ', 'build ', 'none ', 'plan ', 'run ']),
+ ('bst show --deps=', 2, ['all ', 'build ', 'none ', 'plan ', 'run ']),
+ ('bst show --deps b', 3, ['build ']),
+ ('bst show --deps=b', 2, ['build ']),
+ ('bst show --deps r', 3, ['run ']),
+ ('bst track --deps ', 3, ['all ', 'none ']),
+])
+def test_option_choice(cli, cmd, word_idx, expected):
+ assert_completion(cli, cmd, word_idx, expected)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("cmd,word_idx,expected,subdir", [
+ # Note that elements/ and files/ are partial completions and
+ # as such do not come with trailing whitespace
+ ('bst --config ', 2, ['cache/', 'elements/', 'files/', 'project.conf '], None),
+ ('bst --log-file ', 2, ['cache/', 'elements/', 'files/', 'project.conf '], None),
+ ('bst --config f', 2, ['files/'], None),
+ ('bst --log-file f', 2, ['files/'], None),
+ ('bst --config files', 2, ['files/bin-files/', 'files/dev-files/'], None),
+ ('bst --log-file files', 2, ['files/bin-files/', 'files/dev-files/'], None),
+ ('bst --config files/', 2, ['files/bin-files/', 'files/dev-files/'], None),
+ ('bst --log-file elements/', 2, [os.path.join('elements', e) + ' ' for e in PROJECT_ELEMENTS], None),
+ ('bst --config ../', 2, ['../cache/', '../elements/', '../files/', '../project.conf '], 'files'),
+ ('bst --config ../elements/', 2, [os.path.join('..', 'elements', e) + ' ' for e in PROJECT_ELEMENTS], 'files'),
+ ('bst --config ../nofile', 2, [], 'files'),
+ ('bst --config /pony/rainbow/nobodyhas/this/file', 2, [], 'files'),
+])
+def test_option_file(datafiles, cli, cmd, word_idx, expected, subdir):
+ cwd = str(datafiles)
+ if subdir:
+ cwd = os.path.join(cwd, subdir)
+ assert_completion(cli, cmd, word_idx, expected, cwd=cwd)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("cmd,word_idx,expected,subdir", [
+ # Note that regular files like project.conf are not returned when
+ # completing for a directory
+ ('bst --directory ', 2, ['cache/', 'elements/', 'files/'], None),
+ ('bst --directory elements/', 2, [], None),
+ ('bst --directory ', 2, ['dev-files/', 'bin-files/'], 'files'),
+ ('bst --directory ../', 2, ['../cache/', '../elements/', '../files/'], 'files'),
+])
+def test_option_directory(datafiles, cli, cmd, word_idx, expected, subdir):
+ cwd = str(datafiles)
+ if subdir:
+ cwd = os.path.join(cwd, subdir)
+ assert_completion(cli, cmd, word_idx, expected, cwd=cwd)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("cmd,word_idx,expected,subdir", [
+ # When running in the project directory
+ ('bst show ', 2, [e + ' ' for e in PROJECT_ELEMENTS], None),
+ ('bst build com', 2, ['compose-all.bst ', 'compose-include-bin.bst ', 'compose-exclude-dev.bst '], None),
+
+ # When running from the files subdir
+ ('bst show ', 2, [], 'files'),
+ ('bst build com', 2, [], 'files'),
+
+ # When passing the project directory
+ ('bst --directory ../ show ', 4, [e + ' ' for e in PROJECT_ELEMENTS], 'files'),
+ ('bst --directory ../ build com', 4,
+ ['compose-all.bst ', 'compose-include-bin.bst ', 'compose-exclude-dev.bst '], 'files'),
+
+ # Also try multi arguments together
+ ('bst --directory ../ checkout t ', 4, ['target.bst '], 'files'),
+ ('bst --directory ../ checkout target.bst ', 5, ['bin-files/', 'dev-files/'], 'files'),
+])
+def test_argument_element(datafiles, cli, cmd, word_idx, expected, subdir):
+ cwd = str(datafiles)
+ if subdir:
+ cwd = os.path.join(cwd, subdir)
+ assert_completion(cli, cmd, word_idx, expected, cwd=cwd)
diff --git a/tests/completions/project/elements/compose-all.bst b/tests/completions/project/elements/compose-all.bst
new file mode 100644
index 000000000..ba47081b3
--- /dev/null
+++ b/tests/completions/project/elements/compose-all.bst
@@ -0,0 +1,12 @@
+kind: compose
+
+depends:
+- filename: import-bin.bst
+ type: build
+- filename: import-dev.bst
+ type: build
+
+config:
+ # Dont try running the sandbox, we dont have a
+ # runtime to run anything in this context.
+ integrate: False
diff --git a/tests/completions/project/elements/compose-exclude-dev.bst b/tests/completions/project/elements/compose-exclude-dev.bst
new file mode 100644
index 000000000..75c14378c
--- /dev/null
+++ b/tests/completions/project/elements/compose-exclude-dev.bst
@@ -0,0 +1,16 @@
+kind: compose
+
+depends:
+- filename: import-bin.bst
+ type: build
+- filename: import-dev.bst
+ type: build
+
+config:
+ # Dont try running the sandbox, we dont have a
+ # runtime to run anything in this context.
+ integrate: False
+
+ # Exclude the dev domain
+ exclude:
+ - devel
diff --git a/tests/completions/project/elements/compose-include-bin.bst b/tests/completions/project/elements/compose-include-bin.bst
new file mode 100644
index 000000000..9571203c6
--- /dev/null
+++ b/tests/completions/project/elements/compose-include-bin.bst
@@ -0,0 +1,16 @@
+kind: compose
+
+depends:
+- filename: import-bin.bst
+ type: build
+- filename: import-dev.bst
+ type: build
+
+config:
+ # Dont try running the sandbox, we dont have a
+ # runtime to run anything in this context.
+ integrate: False
+
+ # Only include the runtim
+ include:
+ - runtime
diff --git a/tests/completions/project/elements/import-bin.bst b/tests/completions/project/elements/import-bin.bst
new file mode 100644
index 000000000..a847c0c23
--- /dev/null
+++ b/tests/completions/project/elements/import-bin.bst
@@ -0,0 +1,4 @@
+kind: import
+sources:
+- kind: local
+ path: files/bin-files
diff --git a/tests/completions/project/elements/import-dev.bst b/tests/completions/project/elements/import-dev.bst
new file mode 100644
index 000000000..152a54667
--- /dev/null
+++ b/tests/completions/project/elements/import-dev.bst
@@ -0,0 +1,4 @@
+kind: import
+sources:
+- kind: local
+ path: files/dev-files
diff --git a/tests/completions/project/elements/target.bst b/tests/completions/project/elements/target.bst
new file mode 100644
index 000000000..b9432fafa
--- /dev/null
+++ b/tests/completions/project/elements/target.bst
@@ -0,0 +1,8 @@
+kind: stack
+description: |
+
+ Main stack target for the bst build test
+
+depends:
+- import-bin.bst
+- compose-all.bst
diff --git a/tests/completions/project/files/bin-files/usr/bin/hello b/tests/completions/project/files/bin-files/usr/bin/hello
new file mode 100755
index 000000000..f534a4083
--- /dev/null
+++ b/tests/completions/project/files/bin-files/usr/bin/hello
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "Hello !"
diff --git a/tests/completions/project/files/dev-files/usr/include/pony.h b/tests/completions/project/files/dev-files/usr/include/pony.h
new file mode 100644
index 000000000..40bd0c2e7
--- /dev/null
+++ b/tests/completions/project/files/dev-files/usr/include/pony.h
@@ -0,0 +1,12 @@
+#ifndef __PONY_H__
+#define __PONY_H__
+
+#define PONY_BEGIN "Once upon a time, there was a pony."
+#define PONY_END "And they lived happily ever after, the end."
+
+#define MAKE_PONY(story) \
+ PONY_BEGIN \
+ story \
+ PONY_END
+
+#endif /* __PONY_H__ */
diff --git a/tests/completions/project/project.conf b/tests/completions/project/project.conf
new file mode 100644
index 000000000..854e38693
--- /dev/null
+++ b/tests/completions/project/project.conf
@@ -0,0 +1,4 @@
+# Project config for frontend build test
+name: test
+
+element-path: elements