summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2020-11-20 08:04:52 +0000
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2020-11-20 08:04:52 +0000
commit9eee3353a9342ff697e0260ffa58700b857b6288 (patch)
tree3625ffa9c9faa1f963473ac46f6bfdf7cee46289 /tests
parentf6ee38f5b61073b27b94f0fecb8258dc942f5ddd (diff)
parent84e964af45ae9faf2e3d8309eba3a31f58c5b7b9 (diff)
downloadbuildstream-9eee3353a9342ff697e0260ffa58700b857b6288.tar.gz
Merge branch 'tristan/fix-glob-handling' into 'master'
Fix glob handling in the CLI Closes #959 See merge request BuildStream/buildstream!2102
Diffstat (limited to 'tests')
-rw-r--r--tests/frontend/artifact_delete.py4
-rw-r--r--tests/frontend/artifact_list_contents.py2
-rw-r--r--tests/frontend/artifact_show.py67
-rw-r--r--tests/frontend/buildcheckout.py2
-rw-r--r--tests/frontend/push.py4
-rw-r--r--tests/frontend/show.py46
-rw-r--r--tests/frontend/simple/elements/compose-all.bst12
-rw-r--r--tests/frontend/simple/elements/import-bin.bst4
-rw-r--r--tests/frontend/simple/elements/import-dev.bst4
-rw-r--r--tests/frontend/simple/elements/subdir/target.bst7
-rw-r--r--tests/frontend/simple/elements/target.bst8
-rwxr-xr-xtests/frontend/simple/files/bin-files/usr/bin/hello3
-rw-r--r--tests/frontend/simple/files/dev-files/usr/include/pony.h12
-rw-r--r--tests/frontend/simple/project.conf4
14 files changed, 171 insertions, 8 deletions
diff --git a/tests/frontend/artifact_delete.py b/tests/frontend/artifact_delete.py
index 2651f567e..7b26a7644 100644
--- a/tests/frontend/artifact_delete.py
+++ b/tests/frontend/artifact_delete.py
@@ -256,6 +256,4 @@ def test_artifact_delete_artifact_with_deps_all_fails(cli, tmpdir, datafiles):
# Try to delete the artifact with all of its dependencies
result = cli.run(project=project, args=["artifact", "delete", "--deps", "all", artifact])
- result.assert_main_error(ErrorDomain.STREAM, None)
-
- assert "Error: '--deps all' is not supported for artifact refs" in result.stderr
+ result.assert_main_error(ErrorDomain.STREAM, "deps-not-supported")
diff --git a/tests/frontend/artifact_list_contents.py b/tests/frontend/artifact_list_contents.py
index 8bd7bdeff..ee129cc9f 100644
--- a/tests/frontend/artifact_list_contents.py
+++ b/tests/frontend/artifact_list_contents.py
@@ -71,7 +71,7 @@ def test_artifact_list_exact_contents_glob(cli, datafiles):
assert result.exit_code == 0
# List the contents via glob
- result = cli.run(project=project, args=["artifact", "list-contents", "test/*"])
+ result = cli.run(project=project, args=["artifact", "list-contents", "test/**"])
assert result.exit_code == 0
# get the cahe keys for each element in the glob
diff --git a/tests/frontend/artifact_show.py b/tests/frontend/artifact_show.py
index de9b78c45..ebea7cf33 100644
--- a/tests/frontend/artifact_show.py
+++ b/tests/frontend/artifact_show.py
@@ -28,6 +28,7 @@ from tests.testutils import create_artifact_share
# Project directory
DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project",)
+SIMPLE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "simple",)
# Test artifact show
@@ -102,6 +103,72 @@ def test_artifact_show_artifact_ref(cli, tmpdir, datafiles):
assert "cached {}".format(artifact_ref) in result.output
+# Test artifact show glob behaviors
+@pytest.mark.datafiles(SIMPLE_DIR)
+@pytest.mark.parametrize(
+ "pattern,expected_prefixes",
+ [
+ # List only artifact results in the test/project
+ #
+ ("test/**", ["test/target/", "test/target/", "test/compose-all/", "test/import-bin", "test/import-dev"]),
+ # List only artifact results by their .bst element names
+ #
+ ("**.bst", ["import-bin.bst", "import-dev.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]),
+ # List only the import artifact results
+ #
+ ("import*.bst", ["import-bin.bst", "import-dev.bst"]),
+ ],
+ ids=["test/**", "**.bst", "import*.bst"],
+)
+def test_artifact_show_glob(cli, tmpdir, datafiles, pattern, expected_prefixes):
+ project = str(datafiles)
+
+ result = cli.run(project=project, args=["build", "target.bst"])
+ result.assert_success()
+
+ result = cli.run(project=project, args=["artifact", "show", pattern])
+ result.assert_success()
+
+ output = result.output.strip().splitlines()
+
+ # Assert that the number of results match the number of expected results
+ assert len(output) == len(expected_prefixes)
+
+ # Assert that each expected result was found.
+ for expected_prefix in expected_prefixes:
+ found = False
+ for result_line in output:
+ result_split = result_line.split()
+ if result_split[-1].startswith(expected_prefix):
+ found = True
+ break
+ assert found, "Expected result {} not found".format(expected_prefix)
+
+
+# Test artifact show glob behaviors
+@pytest.mark.datafiles(SIMPLE_DIR)
+@pytest.mark.parametrize(
+ "pattern",
+ [
+ # Catch all glob will match everything, that is an error since the glob matches
+ # both elements and artifacts
+ #
+ "**",
+ # This glob is more selective but will also match both artifacts and elements
+ #
+ "**import-bin**",
+ ],
+)
+def test_artifact_show_doubly_matched_glob_error(cli, tmpdir, datafiles, pattern):
+ project = str(datafiles)
+
+ result = cli.run(project=project, args=["build", "target.bst"])
+ result.assert_success()
+
+ result = cli.run(project=project, args=["artifact", "show", pattern])
+ result.assert_main_error(ErrorDomain.STREAM, "glob-elements-and-artifacts")
+
+
# Test artifact show artifact in remote
@pytest.mark.datafiles(DATA_DIR)
def test_artifact_show_element_available_remotely(cli, tmpdir, datafiles):
diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py
index 5afa5216d..709259397 100644
--- a/tests/frontend/buildcheckout.py
+++ b/tests/frontend/buildcheckout.py
@@ -451,7 +451,7 @@ def test_build_checkout_runtime_deps_using_ref_fails(datafiles, cli):
checkout_args = ["artifact", "checkout", "--directory", checkout, "--deps", "run", "test/checkout-deps/" + key]
result = cli.run(project=project, args=checkout_args)
- result.assert_main_error(ErrorDomain.STREAM, None)
+ result.assert_main_error(ErrorDomain.STREAM, "deps-not-supported")
@pytest.mark.datafiles(DATA_DIR)
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index 4b10b5bcd..31b0b7ec3 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -335,9 +335,7 @@ def test_push_artifacts_all_deps_fails(cli, tmpdir, datafiles):
# Now try bst artifact push all the deps
result = cli.run(project=project, args=["artifact", "push", "--deps", "all", artifact_ref])
- result.assert_main_error(ErrorDomain.STREAM, None)
-
- assert "Error: '--deps all' is not supported for artifact refs" in result.stderr
+ result.assert_main_error(ErrorDomain.STREAM, "deps-not-supported")
# Tests that `bst build` won't push artifacts to the cache it just pulled from.
diff --git a/tests/frontend/show.py b/tests/frontend/show.py
index 4be4b72e9..81e1e629c 100644
--- a/tests/frontend/show.py
+++ b/tests/frontend/show.py
@@ -50,6 +50,52 @@ def test_show_fail(cli, datafiles):
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
+# Test behaviors of user supplied glob patterns
+@pytest.mark.datafiles(os.path.join(DATA_DIR, "simple"))
+@pytest.mark.parametrize(
+ "pattern,expected_elements",
+ [
+ # Use catch all glob. This should report all elements.
+ #
+ ("**", ["import-bin.bst", "import-dev.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]),
+ # Only bst files, same as "**" for `bst show`
+ #
+ ("**.bst", ["import-bin.bst", "import-dev.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]),
+ # Use regular globbing without matching path separators, this should exclude
+ # the target in the subdirectory.
+ #
+ ("*.bst", ["import-bin.bst", "import-dev.bst", "compose-all.bst", "target.bst"]),
+ # Report only targets in the subdirectory
+ #
+ ("subdir/*", ["subdir/target.bst"]),
+ # Report both targets which end in "target.bst"
+ #
+ ("**target.bst", ["target.bst", "subdir/target.bst"]),
+ # All elements starting with the prefix "import"
+ #
+ ("import*", ["import-bin.bst", "import-dev.bst"]),
+ # Glob would match artifact refs, but `bst show` does not accept these as input.
+ #
+ ("test/**", []),
+ ],
+ ids=["**", "**.bst", "*.bst", "subdir/*", "**target.bst", "import*", "test/**"],
+)
+def test_show_glob(cli, tmpdir, datafiles, pattern, expected_elements):
+ project = str(datafiles)
+
+ result = cli.run(project=project, args=["show", "--deps", "none", "--format", "%{name}", pattern])
+ result.assert_success()
+
+ output = result.output.strip().splitlines()
+
+ # Assert that the number of results match the number of expected results
+ assert len(output) == len(expected_elements)
+
+ # Assert that each expected result was found.
+ for expected in expected_elements:
+ assert expected in output, "Expected result {} not found".format(expected)
+
+
@pytest.mark.datafiles(os.path.join(DATA_DIR, "project"))
@pytest.mark.parametrize(
"target,except_,expected",
diff --git a/tests/frontend/simple/elements/compose-all.bst b/tests/frontend/simple/elements/compose-all.bst
new file mode 100644
index 000000000..ba47081b3
--- /dev/null
+++ b/tests/frontend/simple/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/frontend/simple/elements/import-bin.bst b/tests/frontend/simple/elements/import-bin.bst
new file mode 100644
index 000000000..a847c0c23
--- /dev/null
+++ b/tests/frontend/simple/elements/import-bin.bst
@@ -0,0 +1,4 @@
+kind: import
+sources:
+- kind: local
+ path: files/bin-files
diff --git a/tests/frontend/simple/elements/import-dev.bst b/tests/frontend/simple/elements/import-dev.bst
new file mode 100644
index 000000000..152a54667
--- /dev/null
+++ b/tests/frontend/simple/elements/import-dev.bst
@@ -0,0 +1,4 @@
+kind: import
+sources:
+- kind: local
+ path: files/dev-files
diff --git a/tests/frontend/simple/elements/subdir/target.bst b/tests/frontend/simple/elements/subdir/target.bst
new file mode 100644
index 000000000..411206787
--- /dev/null
+++ b/tests/frontend/simple/elements/subdir/target.bst
@@ -0,0 +1,7 @@
+kind: stack
+description: |
+
+ Another target in a subdirectory
+
+depends:
+- import-dev.bst
diff --git a/tests/frontend/simple/elements/target.bst b/tests/frontend/simple/elements/target.bst
new file mode 100644
index 000000000..b9432fafa
--- /dev/null
+++ b/tests/frontend/simple/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/frontend/simple/files/bin-files/usr/bin/hello b/tests/frontend/simple/files/bin-files/usr/bin/hello
new file mode 100755
index 000000000..f534a4083
--- /dev/null
+++ b/tests/frontend/simple/files/bin-files/usr/bin/hello
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "Hello !"
diff --git a/tests/frontend/simple/files/dev-files/usr/include/pony.h b/tests/frontend/simple/files/dev-files/usr/include/pony.h
new file mode 100644
index 000000000..40bd0c2e7
--- /dev/null
+++ b/tests/frontend/simple/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/frontend/simple/project.conf b/tests/frontend/simple/project.conf
new file mode 100644
index 000000000..5ba316874
--- /dev/null
+++ b/tests/frontend/simple/project.conf
@@ -0,0 +1,4 @@
+# Project config for frontend build test
+name: test
+min-version: 2.0
+element-path: elements