|
1 | | -//! Host runtimes keep Core's version probe; any other runtime names the tool |
2 | | -//! definition with the same ID, which checks the version itself. |
| 1 | +//! A runtime without executables names the tool definition with the same ID, |
| 2 | +//! which finds the executable and checks the version itself. Core knows no |
| 3 | +//! runtime by name: `go` and `node` follow the same rules as any other ID. |
3 | 4 |
|
4 | 5 | use crate::build::{build_check_tool_version_command, build_invocation_plan_command}; |
5 | 6 | use lithe_plugin_manifest::DeclarativePluginManifest as Manifest; |
@@ -31,126 +32,93 @@ fn check(manifest: Value, runtime: &str, output: &str) -> Value { |
31 | 32 | .expect("version request is valid") |
32 | 33 | } |
33 | 34 |
|
| 35 | +/// A published manifest that names a runtime without executables keeps |
| 36 | +/// validating; the plan resolves it through the tool definition with that |
| 37 | +/// ID. `go` and `node` get no host candidate and no Core probe. |
34 | 38 | #[test] |
35 | | -fn host_runtime_probe_arguments_are_portable_across_platforms() { |
| 39 | +fn runtime_without_executables_becomes_a_toolchain_candidate() { |
36 | 40 | for platform in ["macos", "linux", "windows"] { |
37 | | - let mut manifest = manifest(); |
38 | | - manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] = json!([ |
39 | | - { "id": "node", "minimumVersion": "20" }, |
40 | | - { "id": "go", "minimumVersion": "1.22" } |
41 | | - ]); |
42 | | - let result = plan(manifest, platform); |
43 | | - assert_eq!(result["status"], "ok", "{platform}: {result}"); |
44 | | - let runtimes = &result["invocation"]["runtimeDependencies"]; |
45 | | - for (index, arguments) in [json!(["--version"]), json!(["version"])] |
46 | | - .into_iter() |
47 | | - .enumerate() |
48 | | - { |
49 | | - assert_eq!(runtimes[index]["hostManaged"], true, "{platform}"); |
50 | | - let id = if index == 0 { "node" } else { "go" }; |
51 | | - assert_eq!( |
52 | | - runtimes[index]["executables"], |
53 | | - json!([{"kind":"runtime","runtime":id}]), |
54 | | - "{platform}" |
55 | | - ); |
| 41 | + for (id, minimum, path_variable) in [ |
| 42 | + ("vm", "8", "LITHE_VM_PATH"), |
| 43 | + ("go", "1.22", "LITHE_GO_PATH"), |
| 44 | + ("node", "20", "LITHE_NODE_PATH"), |
| 45 | + ] { |
| 46 | + let mut manifest = manifest(); |
| 47 | + manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] = |
| 48 | + json!([{ "id": id, "minimumVersion": minimum }]); |
| 49 | + let result = plan(manifest, platform); |
| 50 | + assert_eq!(result["status"], "ok", "{platform} {id}: {result}"); |
56 | 51 | assert_eq!( |
57 | | - runtimes[index]["pathVariable"], |
58 | | - format!("LITHE_{}_PATH", id.to_ascii_uppercase()) |
| 52 | + result["invocation"]["runtimeDependencies"][0], |
| 53 | + json!({ |
| 54 | + "id": id, |
| 55 | + "displayName": null, |
| 56 | + "pathVariable": path_variable, |
| 57 | + "executables": [ |
| 58 | + { "kind": "toolchain", "toolchainID": id, "root": "." } |
| 59 | + ], |
| 60 | + "version": null, |
| 61 | + "minimumVersion": minimum |
| 62 | + }), |
| 63 | + "{platform} {id}" |
59 | 64 | ); |
| 65 | + // The build tool's own probe stays independent of its runtimes. |
60 | 66 | assert_eq!( |
61 | | - runtimes[index]["version"]["arguments"], arguments, |
62 | | - "{platform}" |
| 67 | + result["invocation"]["version"]["arguments"], |
| 68 | + json!(["--version"]) |
63 | 69 | ); |
64 | 70 | } |
65 | | - // The build tool's own probe stays independent of its runtimes. |
66 | | - assert_eq!( |
67 | | - result["invocation"]["version"]["arguments"], |
68 | | - json!(["--version"]) |
69 | | - ); |
70 | 71 | } |
71 | 72 | } |
72 | 73 |
|
73 | | -/// A published manifest that names `vm` without executables keeps |
74 | | -/// validating; the plan resolves it through the tool definition `vm`. |
75 | 74 | #[test] |
76 | | -fn runtime_without_executables_becomes_a_toolchain_candidate() { |
77 | | - for platform in ["macos", "linux", "windows"] { |
| 75 | +fn runtime_named_by_tool_definition_has_no_core_probe() { |
| 76 | + for (id, output) in [ |
| 77 | + ("vm", "21.0.4\n"), |
| 78 | + ("go", "go version go1.22.3 darwin/arm64\n"), |
| 79 | + ("node", "v20.11.0\n"), |
| 80 | + ] { |
78 | 81 | let mut manifest = manifest(); |
79 | 82 | manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] = |
80 | | - json!([{ "id": "vm", "minimumVersion": "8" }]); |
81 | | - let result = plan(manifest, platform); |
82 | | - assert_eq!(result["status"], "ok", "{platform}: {result}"); |
| 83 | + json!([{ "id": id, "minimumVersion": "8" }]); |
| 84 | + let result = check(manifest, id, output); |
83 | 85 | assert_eq!( |
84 | | - result["invocation"]["runtimeDependencies"][0], |
| 86 | + result, |
85 | 87 | json!({ |
86 | | - "id": "vm", |
87 | | - "displayName": null, |
88 | | - "hostManaged": false, |
89 | | - "pathVariable":"LITHE_VM_PATH", |
90 | | - "executables": [ |
91 | | - { "kind": "toolchain", "toolchainID": "vm", "root": "." } |
92 | | - ], |
93 | | - "version": null, |
94 | | - "minimumVersion": "8" |
| 88 | + "status": "rejected", |
| 89 | + "error": { |
| 90 | + "code": "plugin.build.unavailable", |
| 91 | + "message": format!( |
| 92 | + "Cargo declares no version probe for {id}; its tool definition checks the version." |
| 93 | + ) |
| 94 | + } |
95 | 95 | }), |
96 | | - "{platform}" |
| 96 | + "{id}" |
97 | 97 | ); |
98 | 98 | } |
99 | 99 | } |
100 | 100 |
|
| 101 | +/// A runtime the plugin describes itself reads its version with its own |
| 102 | +/// pattern, whatever its ID. |
101 | 103 | #[test] |
102 | | -fn runtime_named_by_tool_definition_has_no_core_probe() { |
103 | | - let mut manifest = manifest(); |
104 | | - manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] = |
105 | | - json!([{ "id": "vm", "minimumVersion": "8" }]); |
106 | | - let result = check(manifest, "vm", "21.0.4\n"); |
107 | | - assert_eq!( |
108 | | - result, |
109 | | - json!({ |
110 | | - "status": "rejected", |
111 | | - "error": { |
112 | | - "code": "plugin.build.unavailable", |
113 | | - "message": "Cargo declares no version probe for vm; its tool definition checks the version." |
114 | | - } |
115 | | - }) |
116 | | - ); |
117 | | -} |
118 | | - |
119 | | -#[test] |
120 | | -fn host_runtime_output_reads_the_first_dotted_number() { |
121 | | - for (runtime, minimum, output, satisfied, version) in [ |
122 | | - ("node", "20", "v20.11.0\n", true, "20.11.0"), |
123 | | - ( |
124 | | - "node", |
125 | | - "20", |
126 | | - "warning: custom build\nv18.20.4\n", |
127 | | - false, |
128 | | - "18.20.4", |
129 | | - ), |
130 | | - ( |
131 | | - "go", |
132 | | - "1.22", |
133 | | - "go version go1.22.3 darwin/arm64\n", |
134 | | - true, |
135 | | - "1.22.3", |
136 | | - ), |
137 | | - ( |
138 | | - "go", |
139 | | - "1.22", |
140 | | - "go version go1.21.9 linux/amd64\n", |
141 | | - false, |
142 | | - "1.21.9", |
143 | | - ), |
| 104 | +fn described_runtime_reads_its_own_probe() { |
| 105 | + for (output, satisfied, version) in [ |
| 106 | + ("go version go1.22.3 darwin/arm64\n", true, "1.22.3"), |
| 107 | + ("go version go1.21.9 linux/amd64\n", false, "1.21.9"), |
144 | 108 | ] { |
145 | 109 | let mut manifest = manifest(); |
146 | | - manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] = |
147 | | - json!([{ "id": runtime, "minimumVersion": minimum }]); |
148 | | - let result = check(manifest, runtime, output); |
| 110 | + manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] = json!([{ |
| 111 | + "id": "go", |
| 112 | + "minimumVersion": "1.22", |
| 113 | + "executables": [{ "kind": "command", "command": "go" }], |
| 114 | + "version": { "arguments": ["version"], "pattern": "go(\\d+\\.\\d+(?:\\.\\d+)?)" } |
| 115 | + }]); |
| 116 | + let result = check(manifest, "go", output); |
149 | 117 | assert_eq!(result["status"], "ok", "{result}"); |
150 | 118 | assert_eq!( |
151 | 119 | result["version"], |
152 | 120 | json!({ "satisfied": satisfied, "version": version }), |
153 | | - "{runtime} {output}" |
| 121 | + "{output}" |
154 | 122 | ); |
155 | 123 | } |
156 | 124 | } |
|
0 commit comments