Skip to content

Commit 4670613

Browse files
specific toolchains, reformat code
1 parent 81be8d8 commit 4670613

File tree

17 files changed

+197
-132
lines changed

17 files changed

+197
-132
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
name: Tests
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
7-
branches: [main]
8-
merge_group:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
merge_group:
99

1010
jobs:
11-
test:
12-
strategy:
13-
matrix:
14-
os: [ubuntu-latest, macos-latest]
15-
runs-on: ${{ matrix.os }}
11+
test:
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest]
15+
runs-on: ${{ matrix.os }}
1616

17-
steps:
18-
- uses: actions/checkout@v4
19-
- name: Install tools
20-
uses: taiki-e/install-action@v2
21-
with:
22-
tool: cargo-hack,just,cargo-nextest
23-
- name: Run tests
24-
shell: bash
25-
run: |
26-
rustup toolchain install nightly --component miri,clippy
27-
just
28-
just miri
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Install tools
20+
uses: taiki-e/install-action@v2
21+
with:
22+
tool: cargo-hack,just,cargo-nextest
23+
- name: Run tests
24+
shell: bash
25+
run: |
26+
just ci

Justfile

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
1-
check:
2-
just install-nightly
3-
just clippy
4-
just nextest
5-
just doc-tests
6-
just absolve
1+
nightly_version := "nightly-2025-02-17"
72

8-
install-nightly:
9-
echo -e "\033[1;32m🔧 Installing nightly Rust toolchain...\033[0m"
10-
rustup toolchain install nightly || true
3+
quickcheck:
4+
just install-toolchains
5+
just rustfmt
6+
just clippy
7+
just nextest
8+
just doc-tests
9+
just absolve
10+
11+
ci:
12+
just quickcheck
13+
just miri
14+
15+
install-toolchains:
16+
echo -e "\033[1;32m🔧 Installing Rust toolchain specified in rust-toolchain.toml...\033[0m"
17+
rustup show
18+
rustup toolchain install {{nightly_version}} --profile default || true
19+
rustup component add miri rust-src --toolchain {{nightly_version}} || true
1120

1221
absolve:
13-
#!/bin/bash
14-
if ! cargo +nightly tree -i syn 2>/dev/null | grep -q .; then
15-
echo -e "\033[38;2;255;255;255;48;2;0;0;0m free of \033[38;2;255;255;255;48;2;255;105;180m syn \033[38;2;255;255;255;48;2;0;0;0m\033[0m"
16-
else
22+
#!/bin/bash
23+
if ! cargo tree -i syn 2>/dev/null | grep -q .; then
24+
echo -e "\033[38;2;255;255;255;48;2;0;0;0m free of \033[38;2;255;255;255;48;2;255;105;180m syn \033[38;2;255;255;255;48;2;0;0;0m\033[0m"
25+
else
1726
echo -e "\033[1;31m❌ 'syn' found in dependency tree. Here's what's using 'syn':\033[0m"
18-
cargo +nightly tree -i syn -e features
27+
cargo tree -i syn -e features
1928
exit 1
20-
fi
29+
fi
30+
31+
rustfmt:
32+
echo -e "\033[1;34m📝 Checking code formatting...\033[0m"
33+
cargo fmt --all -- --check
34+
35+
rustfmt-fix:
36+
echo -e "\033[1;34m📝 Fixing code formatting...\033[0m"
37+
cargo fmt --all
2138

2239
clippy:
23-
echo -e "\033[1;35m🔍 Running Clippy on all targets...\033[0m"
24-
cargo +nightly clippy --all-targets -- -D warnings
40+
echo -e "\033[1;35m🔍 Running Clippy on all targets...\033[0m"
41+
cargo clippy --all-targets -- -D warnings
2542

2643
nextest:
27-
echo -e "\033[1;33m🏃 Running all but doc-tests with nextest...\033[0m"
28-
cargo +nightly nextest run
44+
echo -e "\033[1;33m🏃 Running all but doc-tests with nextest...\033[0m"
45+
cargo nextest run
2946

3047
doc-tests:
31-
echo -e "\033[1;36m📚 Running documentation tests...\033[0m"
32-
RUSTDOCFLAGS="-D warnings" cargo +nightly test --doc
48+
echo -e "\033[1;36m📚 Running documentation tests...\033[0m"
49+
RUSTDOCFLAGS="-D warnings" cargo test --doc
3350

3451
miri:
35-
echo -e "\033[1;31m🧪 Running tests under Miri...\033[0m"
36-
cargo +nightly miri nextest run
37-
38-
publish:
39-
cargo +nightly publish --workspace -Zpackage-workspace
52+
echo -e "\033[1;31m🧪 Running tests under Miri in a separate target directory...\033[0m"
53+
cargo +{{nightly_version}} miri nextest run --target-dir=target/miri

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "1.85.0"

shapely-core/src/hashmap_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{alloc::Layout, collections::HashMap, fmt};
22

3-
use crate::{mini_typeid, Innards, Shape, Shapely};
3+
use crate::{Innards, Shape, Shapely, mini_typeid};
44

55
impl<V> Shapely for HashMap<String, V>
66
where

shapely-core/src/partial.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{trace, FieldError, ShapeDesc, Shapely, Slot};
1+
use crate::{FieldError, ShapeDesc, Shapely, Slot, trace};
22
use std::{alloc, ptr::NonNull};
33

44
/// Origin of the partial — did we allocate it? Or is it borrowed?
@@ -242,8 +242,7 @@ impl Partial<'_> {
242242

243243
panic!(
244244
"This is a partial \x1b[1;34m{}\x1b[0m, you can't build a \x1b[1;32m{}\x1b[0m out of it",
245-
partial_shape,
246-
target_shape,
245+
partial_shape, target_shape,
247246
);
248247
}
249248
}

shapely-core/src/scalar_contents_tests.rs

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ macro_rules! test_scalar_type {
99
fn $test_name() {
1010
// Create a value
1111
let v: $type = $value;
12-
12+
1313
// Get a pointer to the value
1414
let v_addr: *const u8 = &v as *const $type as *const u8;
15-
15+
1616
// Get the shape for the type
1717
let v_shape = <$type>::shape();
18-
18+
1919
// Get the scalar contents (this is unsafe)
2020
let scalar_contents = unsafe { v_shape.get_scalar_contents(v_addr) };
21-
21+
2222
// Verify the contents
2323
assert_eq!(scalar_contents, $expected);
2424
}
@@ -27,26 +27,76 @@ macro_rules! test_scalar_type {
2727

2828
// Integer types
2929
test_scalar_type!(test_i8_scalar_contents, i8, -42, ScalarContents::I8(-42));
30-
test_scalar_type!(test_i16_scalar_contents, i16, -1000, ScalarContents::I16(-1000));
30+
test_scalar_type!(
31+
test_i16_scalar_contents,
32+
i16,
33+
-1000,
34+
ScalarContents::I16(-1000)
35+
);
3136
test_scalar_type!(test_i32_scalar_contents, i32, 23, ScalarContents::I32(23));
32-
test_scalar_type!(test_i64_scalar_contents, i64, -1_000_000, ScalarContents::I64(-1_000_000));
33-
test_scalar_type!(test_i128_scalar_contents, i128, 123_456_789, ScalarContents::I128(123_456_789));
37+
test_scalar_type!(
38+
test_i64_scalar_contents,
39+
i64,
40+
-1_000_000,
41+
ScalarContents::I64(-1_000_000)
42+
);
43+
test_scalar_type!(
44+
test_i128_scalar_contents,
45+
i128,
46+
123_456_789,
47+
ScalarContents::I128(123_456_789)
48+
);
3449

3550
// Unsigned integer types
3651
test_scalar_type!(test_u8_scalar_contents, u8, 255, ScalarContents::U8(255));
37-
test_scalar_type!(test_u16_scalar_contents, u16, 65535, ScalarContents::U16(65535));
38-
test_scalar_type!(test_u32_scalar_contents, u32, 4_294_967_295, ScalarContents::U32(4_294_967_295));
39-
test_scalar_type!(test_u64_scalar_contents, u64, 18_446_744_073_709_551_615, ScalarContents::U64(18_446_744_073_709_551_615));
52+
test_scalar_type!(
53+
test_u16_scalar_contents,
54+
u16,
55+
65535,
56+
ScalarContents::U16(65535)
57+
);
58+
test_scalar_type!(
59+
test_u32_scalar_contents,
60+
u32,
61+
4_294_967_295,
62+
ScalarContents::U32(4_294_967_295)
63+
);
64+
test_scalar_type!(
65+
test_u64_scalar_contents,
66+
u64,
67+
18_446_744_073_709_551_615,
68+
ScalarContents::U64(18_446_744_073_709_551_615)
69+
);
4070

4171
// Floating point types
42-
test_scalar_type!(test_f32_scalar_contents, f32, PI_F32, ScalarContents::F32(PI_F32));
43-
test_scalar_type!(test_f64_scalar_contents, f64, E_F64, ScalarContents::F64(E_F64));
72+
test_scalar_type!(
73+
test_f32_scalar_contents,
74+
f32,
75+
PI_F32,
76+
ScalarContents::F32(PI_F32)
77+
);
78+
test_scalar_type!(
79+
test_f64_scalar_contents,
80+
f64,
81+
E_F64,
82+
ScalarContents::F64(E_F64)
83+
);
4484

4585
// Boolean type
46-
test_scalar_type!(test_bool_scalar_contents, bool, true, ScalarContents::Boolean(true));
86+
test_scalar_type!(
87+
test_bool_scalar_contents,
88+
bool,
89+
true,
90+
ScalarContents::Boolean(true)
91+
);
4792

4893
// Nothing type (unit)
49-
test_scalar_type!(test_nothing_scalar_contents, (), (), ScalarContents::Nothing);
94+
test_scalar_type!(
95+
test_nothing_scalar_contents,
96+
(),
97+
(),
98+
ScalarContents::Nothing
99+
);
50100

51101
// String and Bytes types need special handling due to Cow
52102
#[test]
@@ -55,7 +105,7 @@ fn test_string_scalar_contents() {
55105
let v_addr: *const u8 = &v as *const String as *const u8;
56106
let v_shape = String::shape();
57107
let scalar_contents = unsafe { v_shape.get_scalar_contents(v_addr) };
58-
108+
59109
// We can't directly compare with ScalarContents::String because of Cow, so we match and compare the string content
60110
match scalar_contents {
61111
ScalarContents::String(s) => assert_eq!(s, "hello"),
@@ -69,7 +119,7 @@ fn test_bytes_scalar_contents() {
69119
let v_addr: *const u8 = &v as *const Bytes as *const u8;
70120
let v_shape = Bytes::shape();
71121
let scalar_contents = unsafe { v_shape.get_scalar_contents(v_addr) };
72-
122+
73123
// We can't directly compare with ScalarContents::Bytes because of Cow, so we match and compare the bytes content
74124
match scalar_contents {
75125
ScalarContents::Bytes(b) => assert_eq!(b.as_ref(), &[72, 101, 108, 108, 111]),

shapely-core/src/slot.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22
use std::ptr::NonNull;
33

4-
use crate::{trace, InitMark, ShapeDesc, Shapely};
4+
use crate::{InitMark, ShapeDesc, Shapely, trace};
55

66
/// Where to write the value
77
enum Destination<'s> {
@@ -79,13 +79,20 @@ impl<'s> Slot<'s> {
7979
}
8080
}
8181

82-
trace!("Filling struct field at address: \x1b[33m{:?}\x1b[0m with type: \x1b[33m{}\x1b[0m", ptr, T::shape());
82+
trace!(
83+
"Filling struct field at address: \x1b[33m{:?}\x1b[0m with type: \x1b[33m{}\x1b[0m",
84+
ptr,
85+
T::shape()
86+
);
8387
unsafe { std::ptr::write(ptr.as_ptr() as *mut T, value) };
8488
init_mark.set();
8589
}
8690
Destination::HashMap { map, key } => {
8791
let map = unsafe { &mut *(map.as_ptr() as *mut HashMap<String, T>) };
88-
trace!("Inserting value of type: \x1b[33m{}\x1b[0m into HashMap with key: \x1b[33m{key}\x1b[0m", T::shape());
92+
trace!(
93+
"Inserting value of type: \x1b[33m{}\x1b[0m into HashMap with key: \x1b[33m{key}\x1b[0m",
94+
T::shape()
95+
);
8996
map.insert(key, value);
9097
}
9198
}

shapely-core/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{mini_typeid, Shape, Shapely};
1+
use crate::{Shape, Shapely, mini_typeid};
22

33
#[derive(Debug, PartialEq, Eq)]
44
struct FooBar {

shapely-json/src/from_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::parser::{JsonParseErrorKind, JsonParseErrorWithContext, JsonParser};
2-
use shapely::{error, trace, warn, Partial};
2+
use shapely::{Partial, error, trace, warn};
33

44
pub fn from_json<'input>(
55
partial: &mut Partial,

shapely-json/src/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl std::fmt::Display for JsonParseError {
5050
JsonParseErrorKind::ExpectedOpeningQuote => "Expected opening quote for string",
5151
JsonParseErrorKind::UnterminatedString => "Unterminated string",
5252
JsonParseErrorKind::InvalidEscapeSequence(ch) => {
53-
return write!(f, "Invalid escape sequence: \\{}", ch)
53+
return write!(f, "Invalid escape sequence: \\{}", ch);
5454
}
5555
JsonParseErrorKind::IncompleteUnicodeEscape => "Incomplete Unicode escape sequence",
5656
JsonParseErrorKind::InvalidUnicodeEscape => "Invalid Unicode escape sequence",
@@ -61,7 +61,7 @@ impl std::fmt::Display for JsonParseError {
6161
JsonParseErrorKind::InvalidValue => "Invalid value",
6262
JsonParseErrorKind::ExpectedClosingBrace => "Expected closing brace for object",
6363
JsonParseErrorKind::UnknownField(field) => {
64-
return write!(f, "Unknown field: {}", field)
64+
return write!(f, "Unknown field: {}", field);
6565
}
6666
JsonParseErrorKind::Custom(msg) => msg,
6767
};
@@ -142,7 +142,7 @@ impl<'a> JsonParser<'a> {
142142
_ => {
143143
return Err(
144144
self.make_error(JsonParseErrorKind::InvalidEscapeSequence(ch as char))
145-
)
145+
);
146146
}
147147
}
148148
escaped = false;

0 commit comments

Comments
 (0)