summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTristan van Berkom <tristan@codethink.co.uk>2020-11-13 18:27:01 +0900
committerTristan van Berkom <tristan@codethink.co.uk>2020-11-19 15:41:28 +0900
commit524c2c00080ce76b12c0c7e492b2d45c83e5d9c1 (patch)
treea4cc20d58fc4e69c981bca72d496043320598c3b /tests
parent8aadb611f38162c8345d480e944ee48b736cc0f4 (diff)
downloadbuildstream-524c2c00080ce76b12c0c7e492b2d45c83e5d9c1.tar.gz
tests/frontend/artifact_show.py: Added tests for glob pattern matches.
This tests a few glob patterns through `bst artifact show` and also asserts that globs which match both elements and artifacts will produce an error.
Diffstat (limited to 'tests')
-rw-r--r--tests/frontend/artifact_show.py67
-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
9 files changed, 121 insertions, 0 deletions
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/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