summaryrefslogtreecommitdiff
path: root/tests/test_rules
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2023-01-25 19:01:44 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2023-01-26 13:30:53 +0100
commit859ecb6b4b9845006c14a20da21f5ec8c4fb085e (patch)
treea94072963ba017a51dc767f147fd6f8aa7fcb19d /tests/test_rules
parent3979ba259fe932c408844c5b43a9fdf77067230d (diff)
downloadrules-cc-859ecb6b4b9845006c14a20da21f5ec8c4fb085e.tar.gz
Test creating libraries from CMake project
Diffstat (limited to 'tests/test_rules')
-rw-r--r--tests/test_rules/README.md5
-rw-r--r--tests/test_rules/RULES95
2 files changed, 93 insertions, 7 deletions
diff --git a/tests/test_rules/README.md b/tests/test_rules/README.md
index 8ed8f91..5a1baed 100644
--- a/tests/test_rules/README.md
+++ b/tests/test_rules/README.md
@@ -7,11 +7,13 @@ should fail or succeed. After processing all targets, additional assertions
## Setup
-The test rules expect to find the following two bindings:
+The test rules expect to find the following three bindings:
- `[["@", "test-rules", "", "tree"]]`, which contains a single tree artifact
with the rules to test.
- `[["@", "test-just", "", ""]]`, which contains a single executable artifact
that is the JustBuild binary to use for the tests.
+ - `[["@", "test-libs", "", "tree"]]`, which contains a single tree artifact
+ that holds the file trees of external libraries.
## Rule `["test_rules", "test_case"]`
@@ -20,6 +22,7 @@ Define a test case for rule tests.
| Field | Description |
| ----- | ----------- |
| `"name"` | Name of the test (multiple entries are joined). |
+| `"libs"` | Paths to external libraries' trees provided by the `"test-libs"` repository. From within a test cases, the library's tree can be accessed via `["@", "<libname>", "", "tree"]`. |
| `"targets"` | Target names to build and install. Each target name is prefixed by `"+"` or `"-"`, indicating if the build should fail or not. Targets that build successfully will be installed to a directory named identical to the target name (without the prefix). |
| `"asserts"` | List of commands to execute after all targets were processed. To access artifacts from installed targets, use the corresponding target name as prefix dir (e.g., target `"+foo"` installs to `"./foo/"`). |
| `"data"` | The directory that contains the project with the targets to test. |
diff --git a/tests/test_rules/RULES b/tests/test_rules/RULES
index 1a65ec8..f53efba 100644
--- a/tests/test_rules/RULES
+++ b/tests/test_rules/RULES
@@ -1,9 +1,14 @@
{ "test_case":
{ "doc": ["Define a test case for rule tests."]
- , "string_fields": ["name", "targets", "asserts"]
+ , "string_fields": ["name", "libs", "targets", "asserts"]
, "target_fields": ["data"]
, "field_doc":
{ "name": ["Name of the test (multiple entries are joined)."]
+ , "libs":
+ [ "Paths to external libraries' trees provided by the \"test-libs\""
+ , "repository. From within a test cases, the library's tree can be"
+ , "accessed via [\"@\", \"<libpath>\", \"\", \"tree\"]."
+ ]
, "targets":
[ "Target names to build and install. Each target name is prefixed by"
, "\"+\" or \"-\", indicating if the build should fail or not."
@@ -23,6 +28,7 @@
{ "runner": ["test_runner.py"]
, "rules": [["@", "test-rules", "", "tree"]]
, "just": [["@", "test-just", "", ""]]
+ , "libs_tree": [["@", "test-libs", "", "tree"]]
}
, "imports": {"stage_artifact": "stage_singleton_field"}
, "expression":
@@ -35,6 +41,18 @@
, ["fieldname", "rules"]
, ["location", "rules"]
, ["rules", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}]
+ , [ "imports"
+ , { "type": "singleton_map"
+ , "key": "imports/TARGETS"
+ , "value":
+ { "type": "BLOB"
+ , "data": "{\"tree\":{\"type\":\"install\",\"dirs\":[[[\"TREE\",null,\".\"],\".\"]]}}"
+ }
+ }
+ ]
+ , ["fieldname", "libs_tree"]
+ , ["location", "libs"]
+ , ["libs", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}]
, ["fieldname", "data"]
, ["location", "work"]
, ["work", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}]
@@ -43,6 +61,67 @@
, ["runner", {"type": "CALL_EXPRESSION", "name": "stage_artifact"}]
, ["targets", {"type": "FIELD", "name": "targets"}]
, ["asserts", {"type": "FIELD", "name": "asserts"}]
+ , [ "work_bindings"
+ , { "type": "map_union"
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ [{"type": "singleton_map", "key": "rules", "value": "rules"}]
+ , { "type": "foreach"
+ , "range": {"type": "FIELD", "name": "libs"}
+ , "var": "libpath"
+ , "body":
+ { "type": "singleton_map"
+ , "key": {"type": "var", "name": "libpath"}
+ , "value": {"type": "var", "name": "libpath"}
+ }
+ }
+ ]
+ }
+ }
+ ]
+ , [ "work_deps"
+ , { "type": "map_union"
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ [ { "type": "let*"
+ , "bindings":
+ [ ["workspace_root", ["file", "rules"]]
+ , ["rules", {"type": "env", "vars": ["workspace_root"]}]
+ ]
+ , "body": {"type": "env", "vars": ["rules"]}
+ }
+ ]
+ , { "type": "foreach"
+ , "range": {"type": "FIELD", "name": "libs"}
+ , "var": "libpath"
+ , "body":
+ { "type": "let*"
+ , "bindings":
+ [ [ "workspace_root"
+ , [ "file"
+ , { "type": "join"
+ , "$1": ["libs/", {"type": "var", "name": "libpath"}]
+ }
+ ]
+ ]
+ , ["target_root", ["file", "imports"]]
+ ]
+ , "body":
+ { "type": "singleton_map"
+ , "key": {"type": "var", "name": "libpath"}
+ , "value":
+ { "type": "env"
+ , "vars": ["workspace_root", "target_root"]
+ }
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
, [ "repos"
, { "type": "singleton_map"
, "key": "repos.json"
@@ -54,15 +133,17 @@
{ "type": "let*"
, "bindings":
[ ["workspace_root", ["file", "work"]]
- , ["rules", "rules"]
- , ["bindings", {"type": "env", "vars": ["rules"]}]
+ , ["bindings", {"type": "var", "name": "work_bindings"}]
, [ "work"
, {"type": "env", "vars": ["workspace_root", "bindings"]}
]
- , ["workspace_root", ["file", "rules"]]
- , ["rules", {"type": "env", "vars": ["workspace_root"]}]
, [ "repositories"
- , {"type": "env", "vars": ["rules", "work"]}
+ , { "type": "map_union"
+ , "$1":
+ [ {"type": "env", "vars": ["work"]}
+ , {"type": "var", "name": "work_deps"}
+ ]
+ }
]
, ["main", "work"]
]
@@ -92,6 +173,8 @@
[ {"type": "var", "name": "runner"}
, {"type": "var", "name": "rules"}
, {"type": "var", "name": "just"}
+ , {"type": "var", "name": "imports"}
+ , {"type": "var", "name": "libs"}
, {"type": "var", "name": "repos"}
, {"type": "var", "name": "work"}
, {"type": "var", "name": "config"}