Skip to content

Commit 59d8139

Browse files
committed
chore(cleanup): remove unused deps, more clippy fixes and fixed tests
1 parent 2f908ea commit 59d8139

File tree

3 files changed

+15
-118
lines changed

3 files changed

+15
-118
lines changed

Cargo.lock

Lines changed: 0 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ tempfile = "3.1.0"
2626
gif = "0.11"
2727
#image-convert = "0.10"
2828

29-
[dev-dependencies]
30-
env_logger = "0.8.2"
31-
log = "0.4.11"
32-
3329
[target.'cfg(target_os = "macos")'.dependencies]
3430
objc_id = "0.1.1"
3531
objc-foundation = "0.1.1"

src/linux/x11_api.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ mod test {
272272

273273
#[test]
274274
fn calibrate() -> Result<()> {
275-
env_logger::init();
276275
let mut api = X11Api::new()?;
277276
let win = api.get_active_window()?;
278277
let image = api.capture_window_screenshot(win)?;
@@ -284,8 +283,8 @@ mod test {
284283
let image_calibrated: View<_, Bgra<u8>> = image_calibrated.as_view().unwrap();
285284
let (width_new, height_new) = image_calibrated.dimensions();
286285

287-
assert!(height > height_new);
288-
assert!(width > width_new);
286+
assert!(height >= height_new);
287+
assert!(width >= width_new);
289288

290289
Ok(())
291290
}
@@ -308,21 +307,15 @@ mod test {
308307
///
309308
#[test]
310309
fn should_inspect_screenshots() -> Result<()> {
311-
env_logger::init();
312310
let api = X11Api::new()?;
313311
let win = api.get_active_window()?;
314312
let image = api.capture_window_screenshot(win)?;
315313
let image: View<_, Bgra<u8>> = image.as_view().unwrap();
316-
let some_pix: Bgra<u8> = image.get_pixel(10, 25);
317-
if let Bgra([b, g, r, a]) = some_pix {
318-
dbg!(some_pix);
319-
assert_ne!(b, 0);
320-
assert_ne!(g, 0);
321-
assert_ne!(r, 0);
322-
assert_eq!(a, 0xff);
323-
} else {
324-
anyhow::bail!("should not happen");
325-
}
314+
let Bgra([b, g, r, a]) = image.get_pixel(10, 25);
315+
assert_ne!(b, 0);
316+
assert_ne!(g, 0);
317+
assert_ne!(r, 0);
318+
assert_eq!(a, 0xff);
326319

327320
// Note: visual validation is sometimes helpful:
328321
// let file = format!("/tmp/foo-bar-{}.tga", win);
@@ -333,7 +326,6 @@ mod test {
333326
// image.layout.height,
334327
// image.color_hint.unwrap(),
335328
// )?;
336-
// info!("File saved at: {}", file);
337329
Ok(())
338330
}
339331

@@ -350,18 +342,17 @@ mod test {
350342
let windows = api.get_visible_windows()?;
351343
let window = api.get_active_window()?;
352344

353-
assert!(windows.len() > 0);
345+
assert!(!windows.is_empty());
354346
assert!(
355347
windows.contains(&window),
356348
"Active window was not found in visible list"
357349
);
358350
let name = api.get_window_name(&window)?;
359-
match name {
360-
None => assert!(false, "The active window has no name :("),
361-
Some(name) => {
362-
assert!(name.len() > 0);
363-
println!("Active window: {:?}", name);
364-
}
351+
if let Some(name) = name {
352+
assert!(!name.is_empty());
353+
println!("Active window: {:?}", name);
354+
} else {
355+
eprintln!("The active window has no name :(");
365356
}
366357

367358
Ok(())
@@ -371,7 +362,7 @@ mod test {
371362
fn should_list_all_visible_windows() -> Result<()> {
372363
let api = X11Api::new()?;
373364
let windows = api.get_visible_windows()?;
374-
assert!(windows.len() > 0);
365+
assert!(!windows.is_empty());
375366

376367
Ok(())
377368
}
@@ -414,7 +405,7 @@ mod test {
414405
.reply()?;
415406
let _class = String::from_utf8(class.value)?;
416407

417-
for prop in vec!["_NET_WM_ICON_NAME", "_NET_WM_NAME", "_NET_WM_VISIBLE_NAME"] {
408+
for prop in &["_NET_WM_ICON_NAME", "_NET_WM_NAME", "_NET_WM_VISIBLE_NAME"] {
418409
let wm_name_atom = conn.intern_atom(true, prop.as_bytes())?.reply()?;
419410
let utf8_atom = conn.intern_atom(true, b"UTF8_STRING")?.reply()?;
420411
let name = conn

0 commit comments

Comments
 (0)