Skip to content

Commit 440ea6b

Browse files
committed
clippy fixes
refactor: improve test assertions and streamline SQLx workflow - Removed unnecessary test thread specification in the SQLx CI workflow. - Updated test assertions in various modules to use `assert!` for boolean checks instead of `assert_eq!`. - Enhanced ODBC row conversion to `AnyRow` by moving the implementation outside the tests for better organization. - Corrected integer literals in tests to remove leading zeros for clarity.
1 parent 82df55d commit 440ea6b

File tree

8 files changed

+45
-47
lines changed

8 files changed

+45
-47
lines changed

.github/workflows/sqlx.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ jobs:
122122
- run: cargo test
123123
--no-default-features
124124
--features any,macros,migrate,sqlite,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
125-
--
126-
--test-threads=1
127125
env:
128126
DATABASE_URL: sqlite://tests/sqlite/sqlite.db
129127
RUSTFLAGS: --cfg sqlite_ipaddr

sqlx-core/src/mysql/io/buf_mut.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,71 +40,71 @@ impl MySqlBufMutExt for Vec<u8> {
4040
#[test]
4141
fn test_encodes_int_lenenc_u8() {
4242
let mut buf = Vec::with_capacity(1024);
43-
buf.put_uint_lenenc(0xFA as u64);
43+
buf.put_uint_lenenc(0xFA_u64);
4444

4545
assert_eq!(&buf[..], b"\xFA");
4646
}
4747

4848
#[test]
4949
fn test_encodes_int_lenenc_u16() {
5050
let mut buf = Vec::with_capacity(1024);
51-
buf.put_uint_lenenc(std::u16::MAX as u64);
51+
buf.put_uint_lenenc(u16::MAX as u64);
5252

5353
assert_eq!(&buf[..], b"\xFC\xFF\xFF");
5454
}
5555

5656
#[test]
5757
fn test_encodes_int_lenenc_u24() {
5858
let mut buf = Vec::with_capacity(1024);
59-
buf.put_uint_lenenc(0xFF_FF_FF as u64);
59+
buf.put_uint_lenenc(0xFF_FF_FF_u64);
6060

6161
assert_eq!(&buf[..], b"\xFD\xFF\xFF\xFF");
6262
}
6363

6464
#[test]
6565
fn test_encodes_int_lenenc_u64() {
6666
let mut buf = Vec::with_capacity(1024);
67-
buf.put_uint_lenenc(std::u64::MAX);
67+
buf.put_uint_lenenc(u64::MAX);
6868

6969
assert_eq!(&buf[..], b"\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF");
7070
}
7171

7272
#[test]
7373
fn test_encodes_int_lenenc_fb() {
7474
let mut buf = Vec::with_capacity(1024);
75-
buf.put_uint_lenenc(0xFB as u64);
75+
buf.put_uint_lenenc(0xFB_u64);
7676

7777
assert_eq!(&buf[..], b"\xFC\xFB\x00");
7878
}
7979

8080
#[test]
8181
fn test_encodes_int_lenenc_fc() {
8282
let mut buf = Vec::with_capacity(1024);
83-
buf.put_uint_lenenc(0xFC as u64);
83+
buf.put_uint_lenenc(0xFC_u64);
8484

8585
assert_eq!(&buf[..], b"\xFC\xFC\x00");
8686
}
8787

8888
#[test]
8989
fn test_encodes_int_lenenc_fd() {
9090
let mut buf = Vec::with_capacity(1024);
91-
buf.put_uint_lenenc(0xFD as u64);
91+
buf.put_uint_lenenc(0xFD_u64);
9292

9393
assert_eq!(&buf[..], b"\xFC\xFD\x00");
9494
}
9595

9696
#[test]
9797
fn test_encodes_int_lenenc_fe() {
9898
let mut buf = Vec::with_capacity(1024);
99-
buf.put_uint_lenenc(0xFE as u64);
99+
buf.put_uint_lenenc(0xFE_u64);
100100

101101
assert_eq!(&buf[..], b"\xFC\xFE\x00");
102102
}
103103

104104
#[test]
105105
fn test_encodes_int_lenenc_ff() {
106106
let mut buf = Vec::with_capacity(1024);
107-
buf.put_uint_lenenc(0xFF as u64);
107+
buf.put_uint_lenenc(0xFF_u64);
108108

109109
assert_eq!(&buf[..], b"\xFC\xFF\x00");
110110
}

sqlx-core/src/odbc/row.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ mod private {
5252
impl Sealed for OdbcRow {}
5353
}
5454

55+
#[cfg(feature = "any")]
56+
impl From<OdbcRow> for crate::any::AnyRow {
57+
fn from(row: OdbcRow) -> Self {
58+
let columns = row
59+
.columns
60+
.iter()
61+
.map(|col| crate::any::AnyColumn {
62+
kind: crate::any::column::AnyColumnKind::Odbc(col.clone()),
63+
type_info: crate::any::AnyTypeInfo::from(col.type_info.clone()),
64+
})
65+
.collect();
66+
67+
crate::any::AnyRow {
68+
kind: crate::any::row::AnyRowKind::Odbc(row),
69+
columns,
70+
}
71+
}
72+
}
73+
5574
#[cfg(test)]
5675
mod tests {
5776
use super::*;
@@ -177,22 +196,3 @@ mod tests {
177196
assert_eq!(columns[2].name, "MixedCase_Col");
178197
}
179198
}
180-
181-
#[cfg(feature = "any")]
182-
impl From<OdbcRow> for crate::any::AnyRow {
183-
fn from(row: OdbcRow) -> Self {
184-
let columns = row
185-
.columns
186-
.iter()
187-
.map(|col| crate::any::AnyColumn {
188-
kind: crate::any::column::AnyColumnKind::Odbc(col.clone()),
189-
type_info: crate::any::AnyTypeInfo::from(col.type_info.clone()),
190-
})
191-
.collect();
192-
193-
crate::any::AnyRow {
194-
kind: crate::any::row::AnyRowKind::Odbc(row),
195-
columns,
196-
}
197-
}
198-
}

sqlx-core/src/odbc/types/bool.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ mod tests {
172172
},
173173
);
174174
let decoded = <bool as Decode<Odbc>>::decode(value)?;
175-
assert_eq!(decoded, true);
175+
assert!(decoded);
176176

177177
let value = create_test_value_text(
178178
"0",
@@ -182,7 +182,7 @@ mod tests {
182182
},
183183
);
184184
let decoded = <bool as Decode<Odbc>>::decode(value)?;
185-
assert_eq!(decoded, false);
185+
assert!(!decoded);
186186

187187
// Test with decimal values
188188
let value = create_test_value_text(
@@ -193,7 +193,7 @@ mod tests {
193193
},
194194
);
195195
let decoded = <bool as Decode<Odbc>>::decode(value)?;
196-
assert_eq!(decoded, true);
196+
assert!(decoded);
197197

198198
let value = create_test_value_text(
199199
"0.0",
@@ -203,7 +203,7 @@ mod tests {
203203
},
204204
);
205205
let decoded = <bool as Decode<Odbc>>::decode(value)?;
206-
assert_eq!(decoded, false);
206+
assert!(!decoded);
207207

208208
Ok(())
209209
}
@@ -212,15 +212,15 @@ mod tests {
212212
fn test_bool_decode_from_float() -> Result<(), BoxDynError> {
213213
let value = create_test_value_float(1.0, DataType::Double);
214214
let decoded = <bool as Decode<Odbc>>::decode(value)?;
215-
assert_eq!(decoded, true);
215+
assert!(decoded);
216216

217217
let value = create_test_value_float(0.0, DataType::Double);
218218
let decoded = <bool as Decode<Odbc>>::decode(value)?;
219-
assert_eq!(decoded, false);
219+
assert!(!decoded);
220220

221221
let value = create_test_value_float(42.5, DataType::Double);
222222
let decoded = <bool as Decode<Odbc>>::decode(value)?;
223-
assert_eq!(decoded, true);
223+
assert!(decoded);
224224

225225
Ok(())
226226
}
@@ -229,15 +229,15 @@ mod tests {
229229
fn test_bool_decode_from_int() -> Result<(), BoxDynError> {
230230
let value = create_test_value_int(1, DataType::Integer);
231231
let decoded = <bool as Decode<Odbc>>::decode(value)?;
232-
assert_eq!(decoded, true);
232+
assert!(decoded);
233233

234234
let value = create_test_value_int(0, DataType::Integer);
235235
let decoded = <bool as Decode<Odbc>>::decode(value)?;
236-
assert_eq!(decoded, false);
236+
assert!(!decoded);
237237

238238
let value = create_test_value_int(-1, DataType::Integer);
239239
let decoded = <bool as Decode<Odbc>>::decode(value)?;
240-
assert_eq!(decoded, true);
240+
assert!(decoded);
241241

242242
Ok(())
243243
}
@@ -275,7 +275,7 @@ mod tests {
275275
},
276276
);
277277
let decoded = <bool as Decode<Odbc>>::decode(value)?;
278-
assert_eq!(decoded, true);
278+
assert!(decoded);
279279

280280
let value = create_test_value_text(
281281
" 0 ",
@@ -285,7 +285,7 @@ mod tests {
285285
},
286286
);
287287
let decoded = <bool as Decode<Odbc>>::decode(value)?;
288-
assert_eq!(decoded, false);
288+
assert!(!decoded);
289289

290290
Ok(())
291291
}

sqlx-core/src/postgres/listener.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,12 @@ fn build_listen_all_query(channels: impl IntoIterator<Item = impl AsRef<str>>) -
450450

451451
#[test]
452452
fn test_build_listen_all_query_with_single_channel() {
453-
let output = build_listen_all_query(&["test"]);
453+
let output = build_listen_all_query(["test"]);
454454
assert_eq!(output.as_str(), r#"LISTEN "test";"#);
455455
}
456456

457457
#[test]
458458
fn test_build_listen_all_query_with_multiple_channels() {
459-
let output = build_listen_all_query(&["channel.0", "channel.1"]);
459+
let output = build_listen_all_query(["channel.0", "channel.1"]);
460460
assert_eq!(output.as_str(), r#"LISTEN "channel.0";LISTEN "channel.1";"#);
461461
}

sqlx-core/src/postgres/types/bigdecimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ mod bigdecimal_to_pgnumeric {
339339
sign: PgNumericSign::Positive,
340340
scale: 5,
341341
weight: -1,
342-
digits: vec![0123, 4000]
342+
digits: vec![123, 4000]
343343
}
344344
);
345345
}

sqlx-core/src/postgres/types/decimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ mod decimal_to_pgnumeric {
313313
sign: PgNumericSign::Positive,
314314
scale: 5,
315315
weight: -1,
316-
digits: vec![0123, 4000]
316+
digits: vec![123, 4000]
317317
}
318318
);
319319
}

sqlx-core/src/query_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ mod test {
599599
query.statement.unwrap_left(),
600600
"SELECT * FROM users WHERE id = $1"
601601
);
602-
assert_eq!(query.persistent, true);
602+
assert!(query.persistent);
603603
}
604604

605605
#[test]

0 commit comments

Comments
 (0)