Skip to content

Commit 897ea82

Browse files
authored
Address most Clippy warnings in test code (#3691)
1 parent eb4c560 commit 897ea82

File tree

24 files changed

+55
-33
lines changed

24 files changed

+55
-33
lines changed

crates/libs/version/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl OSVERSIONINFOEXW {
7878
}
7979

8080
#[cfg(test)]
81+
#[allow(clippy::nonminimal_bool)] // explicit logic is intentionally being tested
8182
mod test {
8283
use super::OsVersion;
8384
use std::sync::RwLock;

crates/tests/libs/bindgen/tests/deps.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use test_bindgen::deps::*;
22

33
#[test]
4+
#[allow(clippy::manual_c_str_literals)] // false positive
45
fn test() {
56
unsafe {
67
let library = LoadLibraryExA(
@@ -11,7 +12,10 @@ fn test() {
1112

1213
assert!(!library.is_null());
1314
let address = GetProcAddress(library, "GetTickCount\0".as_ptr()).unwrap();
14-
let fp = core::mem::transmute::<_, extern "system" fn() -> u32>(address);
15+
let fp = core::mem::transmute::<
16+
unsafe extern "system" fn() -> isize,
17+
extern "system" fn() -> u32,
18+
>(address);
1519
assert_ne!(fp(), 0);
1620
FreeLibrary(library);
1721
}

crates/tests/libs/future/tests/futures.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn stream_async() -> Result<()> {
4545
}
4646

4747
#[test]
48+
#[allow(clippy::async_yields_async)] // don't want to disturb concurrency testing
4849
fn switch_context() -> Result<()> {
4950
use futures::{executor::LocalPool, future, task::SpawnExt};
5051
use std::future::IntoFuture;

crates/tests/libs/implement/tests/generic_primitive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl IIterable_Impl<i32> for Thing_Impl {
3838
#[test]
3939
fn test_implement() -> Result<()> {
4040
let v: IVectorView<i32> = Thing().into();
41-
assert_eq!(012, v.GetAt(012)?);
41+
assert_eq!(12, v.GetAt(12)?);
4242
assert_eq!(123, v.Size()?);
4343
let mut index = 0;
4444
assert!(v.IndexOf(456, &mut index)?);

crates/tests/libs/registry/tests/string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use windows_registry::*;
33
use windows_strings::*;
44

55
#[test]
6+
#[allow(clippy::unnecessary_to_owned)] // intentionally testing convertible types
67
fn string() -> Result<()> {
78
let test_key = "software\\windows-rs\\tests\\string";
89
_ = CURRENT_USER.remove_tree(test_key);

crates/tests/libs/strings/tests/bstr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ fn clone() {
1919

2020
let a = BSTR::default();
2121
assert!(a.is_empty());
22-
assert!(a.len() == 0);
22+
assert_eq!(a.len(), 0);
2323
let b = a.clone();
2424
assert_eq!(a, "");
2525
assert_eq!(b, "");
2626

2727
let a = BSTR::new();
2828
assert!(a.is_empty());
29-
assert!(a.len() == 0);
29+
assert_eq!(a.len(), 0);
3030
assert_eq!(a.len(), 0);
3131
assert_eq!(a.len(), 0);
3232

@@ -40,11 +40,11 @@ fn clone() {
4040

4141
let a: BSTR = "".into();
4242
assert!(a.is_empty());
43-
assert!(a.len() == 0);
43+
assert_eq!(a.len(), 0);
4444

4545
let a: BSTR = unsafe { SysAllocStringLen(None) };
4646
assert!(a.is_empty());
47-
assert!(a.len() == 0);
47+
assert_eq!(a.len(), 0);
4848

4949
let a = BSTR::from("a");
5050
assert_eq!(a, String::from("a"));

crates/tests/libs/strings/tests/hstring.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use windows::core::Result;
22
use windows_strings::*;
33

44
#[test]
5+
#[allow(clippy::cmp_owned)] // intentionally testing how operations work
56
fn hstring_works() {
67
assert_eq!(std::mem::size_of::<HSTRING>(), std::mem::size_of::<usize>());
78
let empty = HSTRING::new();
@@ -321,6 +322,7 @@ extern "C" {
321322
pub fn wcslen(s: *const u16) -> usize;
322323
}
323324

325+
#[allow(clippy::upper_case_acronyms)]
324326
mod sys {
325327
windows_link::link!("api-ms-win-core-winrt-string-l1-1-0.dll" "system" fn WindowsCreateStringReference(sourcestring: PCWSTR, length: u32, hstringheader: *mut HSTRING_HEADER, string: *mut HSTRING) -> HRESULT);
326328
windows_link::link!("api-ms-win-core-winrt-string-l1-1-0.dll" "system" fn WindowsDeleteString(string: HSTRING) -> HRESULT);

crates/tests/libs/targets/tests/symbol.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ fn symbol() {
1111
unsafe {
1212
use windows::Win32::Security::Authentication::Identity::RtlGenRandom;
1313
let mut buffer = [0u8; 8];
14-
assert_eq!(
15-
RtlGenRandom(buffer.as_mut_ptr() as _, buffer.len() as u32),
16-
true
17-
);
14+
assert!(RtlGenRandom(buffer.as_mut_ptr() as _, buffer.len() as u32),);
1815
assert_ne!(&buffer, &[0u8; 8]);
1916
}
2017
}

crates/tests/misc/arch_feature/tests/sys.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[test]
22
#[cfg(target_arch = "x86_64")]
3+
#[allow(clippy::unnecessary_literal_unwrap)] // callback type is intentionally being tested
34
fn test() {
45
use windows_sys::{
56
Win32::System::Diagnostics::Debug::CONTEXT,

crates/tests/misc/arch_feature/tests/win.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[test]
22
#[cfg(target_arch = "x86_64")]
3+
#[allow(clippy::unnecessary_literal_unwrap)] // callback type is intentionally being tested
34
fn test() {
45
use windows::{
56
Win32::System::Diagnostics::Debug::CONTEXT,

0 commit comments

Comments
 (0)