Skip to content

Commit deff3a4

Browse files
committed
fix cargo tests
1 parent f565e17 commit deff3a4

File tree

10 files changed

+108
-42
lines changed

10 files changed

+108
-42
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/metagen/src/client_py/selections.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ impl PySelectionsPage {
206206
}
207207
}
208208

209-
ManifestPage::with_extras(map, Extras { input_types })
209+
let res = ManifestPage::with_extras(map, Extras { input_types });
210+
res.cache_references();
211+
212+
res
210213
}
211214
}

src/typegraph/graph/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ enum_dispatch.workspace = true
1111
indexmap.workspace = true
1212
paste.workspace = true
1313
color-eyre.workspace = true
14+
15+
[dev-dependencies]
16+
insta.workspace = true

src/typegraph/graph/src/conv/map.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::collections::HashMap;
1111
use super::dedup::DuplicationKey;
1212
use super::{RelativePath, TypeKey};
1313

14-
#[derive(Clone, Debug)]
14+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1515
pub enum ValueTypeKind {
1616
Input,
1717
Output,
@@ -232,12 +232,12 @@ impl ConversionMap {
232232
let item = value_type.get_mut(variant).ok_or_else(|| {
233233
eyre!("value type not found: local index out of bound: {:?}", key)
234234
})?;
235-
let added = item.relative_paths.insert(
236-
rpath
237-
.clone()
238-
.try_into()
239-
.map_err(|e| eyre!("relative path is not a value type: {:?}", e))?,
240-
);
235+
let vtype_path = rpath
236+
.clone()
237+
.try_into()
238+
.map_err(|e| eyre!("relative path is not a value type: {:?}", e))?;
239+
let added = item.relative_paths.insert(vtype_path);
240+
241241
if !added {
242242
return Ok(false);
243243
}

src/typegraph/graph/src/path.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ impl PartialEq for ValueTypePath {
202202
let left = self.owner.upgrade().expect("no strong pointer for type");
203203
let right = other.owner.upgrade().expect("no strong pointer for type");
204204

205-
left.base.type_idx == right.base.type_idx && self.path == other.path
205+
self.branch == other.branch
206+
&& left.base.type_idx == right.base.type_idx
207+
&& self.path == other.path
206208
}
207209
}
208210

src/typegraph/graph/tests/expanded.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
use std::{path::Path, process::Command, sync::Arc};
4+
use std::{collections::BTreeMap, path::Path, process::Command, sync::Arc};
55

66
use typegraph::{TypeNode as _, TypeNodeExt as _};
77

88
#[test]
99
fn test_expanded_graph() -> color_eyre::Result<()> {
1010
let project_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
11-
eprintln!("project_dir={:?}", project_dir);
1211
let path = project_dir
1312
.join("../../../tests/metagen/typegraphs/metagen.ts")
1413
.canonicalize()?;
15-
eprintln!("path={:?}", path);
1614
let output = Command::new("cargo")
1715
.args(
1816
"run -p meta-cli -- serialize -1 -f"
@@ -21,42 +19,37 @@ fn test_expanded_graph() -> color_eyre::Result<()> {
2119
)
2220
.arg(path)
2321
.output()?;
24-
eprintln!("status={}", output.status);
25-
if !output.status.success() {
26-
eprintln!("stderr={}", String::from_utf8_lossy(&output.stderr));
27-
color_eyre::eyre::bail!("error running meta-cli");
28-
}
22+
assert!(output.status.success());
23+
2924
let schema = String::from_utf8(output.stdout)?;
3025
let schema: tg_schema::Typegraph = serde_json::from_str(&schema)?;
3126
let schema: Arc<_> = schema.into();
3227

3328
let tg = typegraph::Typegraph::try_from(schema.clone())?;
3429

35-
println!("namespaces");
36-
for (ns, obj) in tg.namespace_objects.iter() {
37-
println!(" /{}: {}", ns.join("/"), obj.name());
38-
}
39-
40-
println!("functions");
41-
for (idx, func) in tg.functions.iter() {
42-
println!(" {:2}: {}", idx, func.name());
43-
}
44-
45-
println!("input_types");
46-
for (key, ty) in tg.input_types.iter() {
47-
println!(" {:?}({}): {}", key, ty.tag(), ty.name());
48-
}
49-
50-
println!("output_types");
51-
for (key, ty) in tg.output_types.iter() {
52-
println!(
53-
" {:?}({}): {} parent_idx={}",
54-
key,
55-
ty.tag(),
56-
ty.name(),
57-
ty.parent().unwrap().idx()
58-
);
59-
}
30+
insta::assert_debug_snapshot!(tg
31+
.namespace_objects
32+
.iter()
33+
.map(|(ns, obj)| { (ns.join("/"), obj.name()) })
34+
.collect::<BTreeMap<_, _>>());
35+
36+
insta::assert_debug_snapshot!(tg
37+
.functions
38+
.iter()
39+
.map(|(idx, func)| { (idx, func.name()) })
40+
.collect::<BTreeMap<_, _>>());
41+
42+
insta::assert_debug_snapshot!(tg
43+
.input_types
44+
.iter()
45+
.map(|(idx, ty)| { (idx, (ty.tag(), ty.name())) })
46+
.collect::<BTreeMap<_, _>>());
47+
48+
insta::assert_debug_snapshot!(tg
49+
.output_types
50+
.iter()
51+
.map(|(idx, ty)| { (idx, (ty.tag(), ty.name())) })
52+
.collect::<BTreeMap<_, _>>());
6053

6154
Ok(())
6255
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
source: src/typegraph/graph/tests/expanded.rs
3+
expression: "tg.functions.iter().map(|(idx, func)|\n { (idx, func.name()) }).collect::<BTreeMap<_, _>>()"
4+
---
5+
{
6+
1: "root_one_fn",
7+
8: "root_two_fn",
8+
10: "root_three_fn",
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: src/typegraph/graph/tests/expanded.rs
3+
expression: "tg.input_types.iter().map(|(idx, ty)|\n { (idx, (ty.tag(), ty.name())) }).collect::<BTreeMap<_, _>>()"
4+
---
5+
{
6+
Ty_2/0: (
7+
"object",
8+
"OneInput",
9+
),
10+
Ty_3/0: (
11+
"string",
12+
"string_3fb09",
13+
),
14+
Ty_9/0: (
15+
"object",
16+
"TwoInput",
17+
),
18+
Ty_11/0: (
19+
"object",
20+
"root_three_fn_input",
21+
),
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
source: src/typegraph/graph/tests/expanded.rs
3+
expression: "tg.output_types.iter().map(|(idx, ty)|\n { (idx, (ty.tag(), ty.name())) }).collect::<BTreeMap<_, _>>()"
4+
---
5+
{
6+
Ty_3/0: (
7+
"string",
8+
"string_3fb09",
9+
),
10+
Ty_4/0: (
11+
"list",
12+
"root_one_fn_output",
13+
),
14+
Ty_5/0: (
15+
"object",
16+
"Student",
17+
),
18+
Ty_6/0: (
19+
"integer",
20+
"Student_id_integer",
21+
),
22+
Ty_7/0: (
23+
"optional",
24+
"Student_peers_placeholder_optional",
25+
),
26+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
source: src/typegraph/graph/tests/expanded.rs
3+
expression: "tg.namespace_objects.iter().map(|(ns, obj)|\n { (ns.join(\"/\"), obj.name()) }).collect::<BTreeMap<_, _>>()"
4+
---
5+
{
6+
"": "example-metagen",
7+
}

0 commit comments

Comments
 (0)