Skip to content

Commit 0b44d4a

Browse files
Update run-snapshot-tests.sh
1 parent 3a316bb commit 0b44d4a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

app/engine/src/parser.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,4 +1207,30 @@ mod test_get_decorators {
12071207

12081208
assert!(decorators.is_redacted());
12091209
}
1210+
1211+
#[test]
1212+
fn test_field_decorator_cfg_attr() {
1213+
let item_struct: ItemStruct = syn::parse_quote! {
1214+
#[cfg_attr(feature = "typeshare-support", typeshare)]
1215+
pub struct Test {
1216+
#[cfg_attr(feature = "typeshare-support", typeshare(serialized_as = "i54"))]
1217+
pub field_1: i64
1218+
}
1219+
};
1220+
1221+
let RustItem::Struct(rust_struct) =
1222+
parse_struct(&item_struct, None).expect("Failed to parse struct")
1223+
else {
1224+
panic!("Not a struct");
1225+
};
1226+
1227+
let field_decorators = &rust_struct.fields[0].decorators;
1228+
1229+
let value = field_decorators
1230+
.get_all("serialized_as")
1231+
.first()
1232+
.expect("No serialized_as decorator");
1233+
1234+
assert_eq!(value, &Value::String("i54".into()));
1235+
}
12101236
}

run-snapshot-tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
#!/bin/bash
2+
23
# This bash script will run all our snapshot tests using the
34
# new snapshot test runner. The test runner only runs for a
45
# single output language so this script loops through all the
56
# supported languages. The test runner requires a pre-built
67
# typeshare binary to run, so this script starts by building
78
# a release profile of the binary.
89

10+
# Check bash version.
11+
./bin/bash --version | head -n 1 | awk '{ if ($4 < "4") print "Bash 4+ is required. Your version is", $4; exit(1) }'
12+
if [ $? -ne 0 ]; then
13+
exit 1
14+
fi
15+
916
# Test runner.
1017
TEST="cargo run --release --bin typeshare-snapshot-test --"
1118
# Location of our snapshot tests.

0 commit comments

Comments
 (0)