Fix clippy warnings

This commit is contained in:
gwenn 2022-07-31 07:00:37 +02:00
parent 12fc73d122
commit d5110ced91
11 changed files with 59 additions and 64 deletions

View File

@ -473,14 +473,14 @@ mod test {
assert_eq!(&bytes, b"Clob5"); assert_eq!(&bytes, b"Clob5");
// should not be able to seek negative or past end // should not be able to seek negative or past end
assert!(blob.seek(SeekFrom::Current(-20)).is_err()); blob.seek(SeekFrom::Current(-20)).unwrap_err();
assert!(blob.seek(SeekFrom::End(0)).is_ok()); blob.seek(SeekFrom::End(0)).unwrap();
assert!(blob.seek(SeekFrom::Current(1)).is_err()); blob.seek(SeekFrom::Current(1)).unwrap_err();
// write_all should detect when we return Ok(0) because there is no space left, // write_all should detect when we return Ok(0) because there is no space left,
// and return a write error // and return a write error
blob.reopen(rowid)?; blob.reopen(rowid)?;
assert!(blob.write_all(b"0123456789x").is_err()); blob.write_all(b"0123456789x").unwrap_err();
Ok(()) Ok(())
} }
@ -519,7 +519,7 @@ mod test {
// trying to write too much and then flush should fail // trying to write too much and then flush should fail
assert_eq!(8, writer.write(b"01234567").unwrap()); assert_eq!(8, writer.write(b"01234567").unwrap());
assert_eq!(8, writer.write(b"01234567").unwrap()); assert_eq!(8, writer.write(b"01234567").unwrap());
assert!(writer.flush().is_err()); writer.flush().unwrap_err();
} }
{ {
@ -536,7 +536,7 @@ mod test {
// trying to write_all too much should fail // trying to write_all too much should fail
writer.write_all(b"aaaaaaaaaabbbbb").unwrap(); writer.write_all(b"aaaaaaaaaabbbbb").unwrap();
assert!(writer.flush().is_err()); writer.flush().unwrap_err();
} }
{ {

View File

@ -214,7 +214,7 @@ mod test {
let mut s = [0u8; 10]; let mut s = [0u8; 10];
blob.read_at_exact(&mut s, 0).unwrap(); blob.read_at_exact(&mut s, 0).unwrap();
assert_eq!(&s, &one2ten, "write should go through"); assert_eq!(&s, &one2ten, "write should go through");
assert!(blob.read_at_exact(&mut s, 1).is_err()); blob.read_at_exact(&mut s, 1).unwrap_err();
blob.read_at_exact(&mut s, 0).unwrap(); blob.read_at_exact(&mut s, 0).unwrap();
assert_eq!(&s, &one2ten, "should be unchanged"); assert_eq!(&s, &one2ten, "should be unchanged");
@ -225,13 +225,13 @@ mod test {
blob.read_at_exact(&mut fives, 5).unwrap(); blob.read_at_exact(&mut fives, 5).unwrap();
assert_eq!(&fives, &[6u8, 7, 8, 9, 10]); assert_eq!(&fives, &[6u8, 7, 8, 9, 10]);
assert!(blob.read_at_exact(&mut fives, 7).is_err()); blob.read_at_exact(&mut fives, 7).unwrap_err();
assert!(blob.read_at_exact(&mut fives, 12).is_err()); blob.read_at_exact(&mut fives, 12).unwrap_err();
assert!(blob.read_at_exact(&mut fives, 10).is_err()); blob.read_at_exact(&mut fives, 10).unwrap_err();
assert!(blob.read_at_exact(&mut fives, i32::MAX as usize).is_err()); blob.read_at_exact(&mut fives, i32::MAX as usize)
assert!(blob .unwrap_err();
.read_at_exact(&mut fives, i32::MAX as usize + 1) blob.read_at_exact(&mut fives, i32::MAX as usize + 1)
.is_err()); .unwrap_err();
// zero length writes are fine if in bounds // zero length writes are fine if in bounds
blob.read_at_exact(&mut [], 10).unwrap(); blob.read_at_exact(&mut [], 10).unwrap();
@ -242,13 +242,11 @@ mod test {
blob.read_at_exact(&mut s, 0).unwrap(); blob.read_at_exact(&mut s, 0).unwrap();
assert_eq!(&s, &[1u8, 2, 3, 4, 5, 16, 17, 18, 19, 20]); assert_eq!(&s, &[1u8, 2, 3, 4, 5, 16, 17, 18, 19, 20]);
assert!(blob.write_at(&[100, 99, 98, 97, 96], 6).is_err()); blob.write_at(&[100, 99, 98, 97, 96], 6).unwrap_err();
assert!(blob blob.write_at(&[100, 99, 98, 97, 96], i32::MAX as usize)
.write_at(&[100, 99, 98, 97, 96], i32::MAX as usize) .unwrap_err();
.is_err()); blob.write_at(&[100, 99, 98, 97, 96], i32::MAX as usize + 1)
assert!(blob .unwrap_err();
.write_at(&[100, 99, 98, 97, 96], i32::MAX as usize + 1)
.is_err());
blob.read_at_exact(&mut s, 0).unwrap(); blob.read_at_exact(&mut s, 0).unwrap();
assert_eq!(&s, &[1u8, 2, 3, 4, 5, 16, 17, 18, 19, 20]); assert_eq!(&s, &[1u8, 2, 3, 4, 5, 16, 17, 18, 19, 20]);
@ -265,7 +263,7 @@ mod test {
blob.raw_read_at_exact(&mut empty, 0).unwrap().as_ptr(), blob.raw_read_at_exact(&mut empty, 0).unwrap().as_ptr(),
empty.as_ptr().cast(), empty.as_ptr().cast(),
)); ));
assert!(blob.raw_read_at_exact(&mut s2, 5).is_err()); blob.raw_read_at_exact(&mut s2, 5).unwrap_err();
let end_pos = blob.seek(std::io::SeekFrom::Current(0)).unwrap(); let end_pos = blob.seek(std::io::SeekFrom::Current(0)).unwrap();
assert_eq!(end_pos, 1); assert_eq!(end_pos, 1);

View File

@ -849,7 +849,7 @@ mod test {
db.remove_function("half", 1)?; db.remove_function("half", 1)?;
let result: Result<f64> = db.query_row("SELECT half(6)", [], |r| r.get(0)); let result: Result<f64> = db.query_row("SELECT half(6)", [], |r| r.get(0));
assert!(result.is_err()); result.unwrap_err();
Ok(()) Ok(())
} }

View File

@ -1286,17 +1286,16 @@ mod test {
#[test] #[test]
fn test_open() { fn test_open() {
assert!(Connection::open_in_memory().is_ok()); Connection::open_in_memory().unwrap();
let db = checked_memory_handle(); let db = checked_memory_handle();
assert!(db.close().is_ok()); db.close().unwrap();
} }
#[test] #[test]
fn test_open_failure() { fn test_open_failure() {
let filename = "no_such_file.db"; let filename = "no_such_file.db";
let result = Connection::open_with_flags(filename, OpenFlags::SQLITE_OPEN_READ_ONLY); let result = Connection::open_with_flags(filename, OpenFlags::SQLITE_OPEN_READ_ONLY);
assert!(result.is_err());
let err = result.unwrap_err(); let err = result.unwrap_err();
if let Error::SqliteFailure(e, Some(msg)) = err { if let Error::SqliteFailure(e, Some(msg)) = err {
assert_eq!(ErrorCode::CannotOpen, e.code); assert_eq!(ErrorCode::CannotOpen, e.code);
@ -1391,7 +1390,7 @@ mod test {
OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_READ_WRITE, OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_READ_WRITE,
OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_CREATE, OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_CREATE,
] { ] {
assert!(Connection::open_in_memory_with_flags(*bad_flags).is_err()); Connection::open_in_memory_with_flags(*bad_flags).unwrap_err();
} }
} }
@ -1409,7 +1408,7 @@ mod test {
db.execute_batch("UPDATE foo SET x = 3 WHERE x < 3")?; db.execute_batch("UPDATE foo SET x = 3 WHERE x < 3")?;
assert!(db.execute_batch("INVALID SQL").is_err()); db.execute_batch("INVALID SQL").unwrap_err();
Ok(()) Ok(())
} }
@ -1572,7 +1571,7 @@ mod test {
let bad_query_result = db.query_row("NOT A PROPER QUERY; test123", [], |_| Ok(())); let bad_query_result = db.query_row("NOT A PROPER QUERY; test123", [], |_| Ok(()));
assert!(bad_query_result.is_err()); bad_query_result.unwrap_err();
Ok(()) Ok(())
} }
@ -1596,7 +1595,7 @@ mod test {
let bad_query_result: Result<i64> = db.query_row("NOT A PROPER QUERY", [], |r| r.get(0)); let bad_query_result: Result<i64> = db.query_row("NOT A PROPER QUERY", [], |r| r.get(0));
let bad_query_result = bad_query_result.optional(); let bad_query_result = bad_query_result.optional();
assert!(bad_query_result.is_err()); bad_query_result.unwrap_err();
Ok(()) Ok(())
} }
@ -1707,7 +1706,6 @@ mod test {
db.execute_batch("CREATE TABLE foo(x NOT NULL)")?; db.execute_batch("CREATE TABLE foo(x NOT NULL)")?;
let result = db.execute("INSERT INTO foo (x) VALUES (NULL)", []); let result = db.execute("INSERT INTO foo (x) VALUES (NULL)", []);
assert!(result.is_err());
match result.unwrap_err() { match result.unwrap_err() {
Error::SqliteFailure(err, _) => { Error::SqliteFailure(err, _) => {

View File

@ -391,7 +391,7 @@ impl RowIndex for usize {
impl RowIndex for &'_ str { impl RowIndex for &'_ str {
#[inline] #[inline]
fn idx(&self, stmt: &Statement<'_>) -> Result<usize> { fn idx(&self, stmt: &Statement<'_>) -> Result<usize> {
stmt.column_index(*self) stmt.column_index(self)
} }
} }
@ -448,7 +448,7 @@ mod tests {
let val = conn.query_row("SELECT a FROM test", [], |row| <(u32,)>::try_from(row))?; let val = conn.query_row("SELECT a FROM test", [], |row| <(u32,)>::try_from(row))?;
assert_eq!(val, (42,)); assert_eq!(val, (42,));
let fail = conn.query_row("SELECT a FROM test", [], |row| <(u32, u32)>::try_from(row)); let fail = conn.query_row("SELECT a FROM test", [], |row| <(u32, u32)>::try_from(row));
assert!(fail.is_err()); fail.unwrap_err();
Ok(()) Ok(())
} }
@ -466,7 +466,7 @@ mod tests {
let fail = conn.query_row("SELECT a, b FROM test", [], |row| { let fail = conn.query_row("SELECT a, b FROM test", [], |row| {
<(u32, u32, u32)>::try_from(row) <(u32, u32, u32)>::try_from(row)
}); });
assert!(fail.is_err()); fail.unwrap_err();
Ok(()) Ok(())
} }

View File

@ -1474,10 +1474,10 @@ mod test {
let conn = Connection::open_in_memory()?; let conn = Connection::open_in_memory()?;
let mut stmt = conn.prepare("")?; let mut stmt = conn.prepare("")?;
assert_eq!(0, stmt.column_count()); assert_eq!(0, stmt.column_count());
assert!(stmt.parameter_index("test").is_ok()); stmt.parameter_index("test").unwrap();
assert!(stmt.step().is_err()); stmt.step().unwrap_err();
stmt.reset(); stmt.reset();
assert!(stmt.execute([]).is_err()); stmt.execute([]).unwrap_err();
Ok(()) Ok(())
} }
@ -1542,7 +1542,6 @@ mod test {
use crate::ffi::ErrorCode; use crate::ffi::ErrorCode;
let db = Connection::open_in_memory()?; let db = Connection::open_in_memory()?;
let r = db.execute_batch("SELECT CURRENT_TIMESTANP;"); let r = db.execute_batch("SELECT CURRENT_TIMESTANP;");
assert!(r.is_err());
match r.unwrap_err() { match r.unwrap_err() {
Error::SqlInputError { error, offset, .. } => { Error::SqlInputError { error, offset, .. } => {
assert_eq!(error.code, ErrorCode::Unknown); assert_eq!(error.code, ErrorCode::Unknown);

View File

@ -287,15 +287,15 @@ mod test {
fn test_sqlite_functions() -> Result<()> { fn test_sqlite_functions() -> Result<()> {
let db = checked_memory_handle()?; let db = checked_memory_handle()?;
let result: Result<NaiveTime> = db.query_row("SELECT CURRENT_TIME", [], |r| r.get(0)); let result: Result<NaiveTime> = db.query_row("SELECT CURRENT_TIME", [], |r| r.get(0));
assert!(result.is_ok()); result.unwrap();
let result: Result<NaiveDate> = db.query_row("SELECT CURRENT_DATE", [], |r| r.get(0)); let result: Result<NaiveDate> = db.query_row("SELECT CURRENT_DATE", [], |r| r.get(0));
assert!(result.is_ok()); result.unwrap();
let result: Result<NaiveDateTime> = let result: Result<NaiveDateTime> =
db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0)); db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0));
assert!(result.is_ok()); result.unwrap();
let result: Result<DateTime<Utc>> = let result: Result<DateTime<Utc>> =
db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0)); db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0));
assert!(result.is_ok()); result.unwrap();
Ok(()) Ok(())
} }
@ -303,7 +303,7 @@ mod test {
fn test_naive_date_time_param() -> Result<()> { fn test_naive_date_time_param() -> Result<()> {
let db = checked_memory_handle()?; let db = checked_memory_handle()?;
let result: Result<bool> = db.query_row("SELECT 1 WHERE ? BETWEEN datetime('now', '-1 minute') AND datetime('now', '+1 minute')", [Utc::now().naive_utc()], |r| r.get(0)); let result: Result<bool> = db.query_row("SELECT 1 WHERE ? BETWEEN datetime('now', '-1 minute') AND datetime('now', '+1 minute')", [Utc::now().naive_utc()], |r| r.get(0));
assert!(result.is_ok()); result.unwrap();
Ok(()) Ok(())
} }
@ -311,13 +311,13 @@ mod test {
fn test_date_time_param() -> Result<()> { fn test_date_time_param() -> Result<()> {
let db = checked_memory_handle()?; let db = checked_memory_handle()?;
let result: Result<bool> = db.query_row("SELECT 1 WHERE ? BETWEEN datetime('now', '-1 minute') AND datetime('now', '+1 minute')", [Utc::now()], |r| r.get(0)); let result: Result<bool> = db.query_row("SELECT 1 WHERE ? BETWEEN datetime('now', '-1 minute') AND datetime('now', '+1 minute')", [Utc::now()], |r| r.get(0));
assert!(result.is_ok()); result.unwrap();
Ok(()) Ok(())
} }
#[test] #[test]
fn test_lenient_parse_timezone() { fn test_lenient_parse_timezone() {
assert!(DateTime::<Utc>::column_result(ValueRef::Text(b"1970-01-01T00:00:00Z")).is_ok()); DateTime::<Utc>::column_result(ValueRef::Text(b"1970-01-01T00:00:00Z")).unwrap();
assert!(DateTime::<Utc>::column_result(ValueRef::Text(b"1970-01-01T00:00:00+00")).is_ok()); DateTime::<Utc>::column_result(ValueRef::Text(b"1970-01-01T00:00:00+00")).unwrap();
} }
} }

View File

@ -154,7 +154,7 @@ mod test {
let db = Connection::open_in_memory()?; let db = Connection::open_in_memory()?;
let result: Result<OffsetDateTime> = let result: Result<OffsetDateTime> =
db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0)); db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0));
assert!(result.is_ok()); result.unwrap();
Ok(()) Ok(())
} }
@ -162,7 +162,7 @@ mod test {
fn test_param() -> Result<()> { fn test_param() -> Result<()> {
let db = Connection::open_in_memory()?; let db = Connection::open_in_memory()?;
let result: Result<bool> = db.query_row("SELECT 1 WHERE ? BETWEEN datetime('now', '-1 minute') AND datetime('now', '+1 minute')", [OffsetDateTime::now_utc()], |r| r.get(0)); let result: Result<bool> = db.query_row("SELECT 1 WHERE ? BETWEEN datetime('now', '-1 minute') AND datetime('now', '+1 minute')", [OffsetDateTime::now_utc()], |r| r.get(0));
assert!(result.is_ok()); result.unwrap();
Ok(()) Ok(())
} }
} }

View File

@ -278,7 +278,7 @@ mod test {
let _a: &[&dyn ToSql] = crate::params![a]; let _a: &[&dyn ToSql] = crate::params![a];
let r = ToSql::to_sql(&a); let r = ToSql::to_sql(&a);
assert!(r.is_ok()); r.unwrap();
} }
#[test] #[test]
@ -287,10 +287,10 @@ mod test {
let s = "str"; let s = "str";
let cow: Cow<str> = Cow::Borrowed(s); let cow: Cow<str> = Cow::Borrowed(s);
let r = cow.to_sql(); let r = cow.to_sql();
assert!(r.is_ok()); r.unwrap();
let cow: Cow<str> = Cow::Owned::<str>(String::from(s)); let cow: Cow<str> = Cow::Owned::<str>(String::from(s));
let r = cow.to_sql(); let r = cow.to_sql();
assert!(r.is_ok()); r.unwrap();
// Ensure this compiles. // Ensure this compiles.
let _p: &[&dyn ToSql] = crate::params![cow]; let _p: &[&dyn ToSql] = crate::params![cow];
} }
@ -301,7 +301,7 @@ mod test {
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = ToSql::to_sql(&s); let r = ToSql::to_sql(&s);
assert!(r.is_ok()); r.unwrap();
} }
#[test] #[test]
@ -310,7 +310,7 @@ mod test {
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); r.unwrap();
} }
#[test] #[test]
@ -319,7 +319,7 @@ mod test {
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = ToSql::to_sql(&s); let r = ToSql::to_sql(&s);
assert!(r.is_ok()); r.unwrap();
} }
#[test] #[test]
@ -331,32 +331,32 @@ mod test {
let s: Rc<Box<str>> = Rc::new(source_str.clone()); let s: Rc<Box<str>> = Rc::new(source_str.clone());
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); r.unwrap();
let s: Arc<Box<str>> = Arc::new(source_str.clone()); let s: Arc<Box<str>> = Arc::new(source_str.clone());
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); r.unwrap();
let s: Arc<str> = Arc::from(&*source_str); let s: Arc<str> = Arc::from(&*source_str);
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); r.unwrap();
let s: Arc<dyn ToSql> = Arc::new(source_str.clone()); let s: Arc<dyn ToSql> = Arc::new(source_str.clone());
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); r.unwrap();
let s: Rc<str> = Rc::from(&*source_str); let s: Rc<str> = Rc::from(&*source_str);
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); r.unwrap();
let s: Rc<dyn ToSql> = Rc::new(source_str); let s: Rc<dyn ToSql> = Rc::new(source_str);
let _s: &[&dyn ToSql] = crate::params![s]; let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); r.unwrap();
} }
#[cfg(feature = "i128_blob")] #[cfg(feature = "i128_blob")]

View File

@ -163,8 +163,8 @@ mod test {
assert_eq!(SmallCString::new("").unwrap().0.as_slice(), b"\0"); assert_eq!(SmallCString::new("").unwrap().0.as_slice(), b"\0");
assert_eq!(SmallCString::new("").unwrap().as_bytes_without_nul(), b""); assert_eq!(SmallCString::new("").unwrap().as_bytes_without_nul(), b"");
assert!(SmallCString::new("\0").is_err()); SmallCString::new("\0").unwrap_err();
assert!(SmallCString::new("\0abc").is_err()); SmallCString::new("\0abc").unwrap_err();
assert!(SmallCString::new("abc\0").is_err()); SmallCString::new("abc\0").unwrap_err();
} }
} }

View File

@ -16,5 +16,5 @@ fn test_error_when_singlethread_mode() {
assert_eq!(ffi::sqlite3_initialize(), ffi::SQLITE_OK); assert_eq!(ffi::sqlite3_initialize(), ffi::SQLITE_OK);
} }
let res = Connection::open_in_memory(); let res = Connection::open_in_memory();
assert!(res.is_err()); res.unwrap_err();
} }