[GH-ISSUE #138] cargo test fails #58

Closed
opened 2026-06-08 11:25:29 +03:00 by zhus · 14 comments
Owner

Originally created by @KSXGitHub on GitHub (Mar 23, 2021).
Original GitHub issue: https://github.com/bootandy/dust/issues/138

I cloned this repo to my machine and run cargo test, it gives the following errors:

warning: unused import: `std::panic`
 --> tests/tests_symlinks.rs:5:5
  |
5 | use std::panic;
  |     ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

warning: unused import: `std::panic`
 --> tests/tests_symlinks.rs:5:5
  |
5 | use std::panic;
  |     ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

    Finished test [unoptimized + debuginfo] target(s) in 0.03s
     Running target/debug/deps/dust-b9c46c4d4c140db8

running 13 tests
test display::tests::test_human_readable_number ... ok
test utils::tests::test_is_a_parent_of ... ok
test utils::tests::test_is_a_parent_of_root ... ok
test utils::tests::test_should_ignore_file ... ok
test utils::tests::test_should_ignore_file_on_different_device ... ok
test utils::tests::test_simplify_dir ... ok
test utils::tests::test_simplify_dir_dots ... ok
test utils::tests::test_simplify_dir_duplicates ... ok
test utils::tests::test_simplify_dir_rm_subdir ... ok
test utils::tests::test_simplify_dir_substring_names ... ok
test utils::tests::test_simplify_dir_rm_subdir_and_not_substrings ... ok
test display::tests::test_format_str_long_name ... ok
test display::tests::test_format_str ... ok

test result: ok. 13 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/integration-e9ab9987cbc75a52

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/test_exact_output-f8b1b747f15bb498

running 9 tests
test test_apparent_size ... FAILED
test test_main_basic ... FAILED
test test_main_multi_arg ... FAILED
test test_main_long_paths ... FAILED
test test_unicode_directories ... FAILED
test tests_symlinks::test_hard_sym_link ... ok
test tests_symlinks::test_recursive_sym_link ... ok
test test_substring_of_names_and_long_names ... FAILED
test tests_symlinks::test_soft_sym_link ... ok

failures:

---- test_apparent_size stdout ----
thread 'test_apparent_size' panicked at 'assertion failed: output.contains(&output_apparent_size())', tests/test_exact_output.rs:158:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- test_main_basic stdout ----
thread 'test_main_basic' panicked at 'assertion failed: output.contains(&main_output())', tests/test_exact_output.rs:57:5

---- test_main_multi_arg stdout ----
thread 'test_main_multi_arg' panicked at 'assertion failed: output.contains(&main_output())', tests/test_exact_output.rs:73:5

---- test_main_long_paths stdout ----
"0B     ┌── /tmp/test_dir/many/a_file    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │   0%\n 4.0K     ├── /tmp/test_dir/many/hello_file│█████████████████████████████ │ 100%\n 4.0K   ┌─┴ /tmp/test_dir/many             │█████████████████████████████ │ 100%\n 4.0K ┌─┴ /tmp/test_dir                    │█████████████████████████████ │ 100%"
"0B     ┌── /tmp/test_dir/many/a_file    │         ░░░░░░░░░░░░░░░░░░░█ │   0%\n 4.0K     ├── /tmp/test_dir/many/hello_file│         ░░░░░░░░░░██████████ │  33%\n 8.0K   ┌─┴ /tmp/test_dir/many             │         ████████████████████ │  67%\n  12K ┌─┴ /tmp/test_dir                    │█████████████████████████████ │ 100%"
thread 'test_main_long_paths' panicked at 'assertion failed: output.contains(&main_output_long_paths())', tests/test_exact_output.rs:119:5

---- test_unicode_directories stdout ----
thread 'test_unicode_directories' panicked at 'assertion failed: output.contains(&unicode_dir())', tests/test_exact_output.rs:243:5

---- test_substring_of_names_and_long_names stdout ----
thread 'test_substring_of_names_and_long_names' panicked at 'assertion failed: output.contains(&no_substring_of_names_output())', tests/test_exact_output.rs:198:5


failures:
    test_apparent_size
    test_main_basic
    test_main_long_paths
    test_main_multi_arg
    test_substring_of_names_and_long_names
    test_unicode_directories

test result: FAILED. 3 passed; 6 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s

error: test failed, to rerun pass '--test test_exact_output'

Commit: 1b3d0b2724.
OS: Arch Linux
Rust: 1.50.0

Is cargo test the correct way to test dust? If not, then it should be documented.

Originally created by @KSXGitHub on GitHub (Mar 23, 2021). Original GitHub issue: https://github.com/bootandy/dust/issues/138 I cloned this repo to my machine and run `cargo test`, it gives the following errors: ``` warning: unused import: `std::panic` --> tests/tests_symlinks.rs:5:5 | 5 | use std::panic; | ^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: 1 warning emitted warning: unused import: `std::panic` --> tests/tests_symlinks.rs:5:5 | 5 | use std::panic; | ^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: 1 warning emitted Finished test [unoptimized + debuginfo] target(s) in 0.03s Running target/debug/deps/dust-b9c46c4d4c140db8 running 13 tests test display::tests::test_human_readable_number ... ok test utils::tests::test_is_a_parent_of ... ok test utils::tests::test_is_a_parent_of_root ... ok test utils::tests::test_should_ignore_file ... ok test utils::tests::test_should_ignore_file_on_different_device ... ok test utils::tests::test_simplify_dir ... ok test utils::tests::test_simplify_dir_dots ... ok test utils::tests::test_simplify_dir_duplicates ... ok test utils::tests::test_simplify_dir_rm_subdir ... ok test utils::tests::test_simplify_dir_substring_names ... ok test utils::tests::test_simplify_dir_rm_subdir_and_not_substrings ... ok test display::tests::test_format_str_long_name ... ok test display::tests::test_format_str ... ok test result: ok. 13 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s Running target/debug/deps/integration-e9ab9987cbc75a52 running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s Running target/debug/deps/test_exact_output-f8b1b747f15bb498 running 9 tests test test_apparent_size ... FAILED test test_main_basic ... FAILED test test_main_multi_arg ... FAILED test test_main_long_paths ... FAILED test test_unicode_directories ... FAILED test tests_symlinks::test_hard_sym_link ... ok test tests_symlinks::test_recursive_sym_link ... ok test test_substring_of_names_and_long_names ... FAILED test tests_symlinks::test_soft_sym_link ... ok failures: ---- test_apparent_size stdout ---- thread 'test_apparent_size' panicked at 'assertion failed: output.contains(&output_apparent_size())', tests/test_exact_output.rs:158:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ---- test_main_basic stdout ---- thread 'test_main_basic' panicked at 'assertion failed: output.contains(&main_output())', tests/test_exact_output.rs:57:5 ---- test_main_multi_arg stdout ---- thread 'test_main_multi_arg' panicked at 'assertion failed: output.contains(&main_output())', tests/test_exact_output.rs:73:5 ---- test_main_long_paths stdout ---- "0B ┌── /tmp/test_dir/many/a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%\n 4.0K ├── /tmp/test_dir/many/hello_file│█████████████████████████████ │ 100%\n 4.0K ┌─┴ /tmp/test_dir/many │█████████████████████████████ │ 100%\n 4.0K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%" "0B ┌── /tmp/test_dir/many/a_file │ ░░░░░░░░░░░░░░░░░░░█ │ 0%\n 4.0K ├── /tmp/test_dir/many/hello_file│ ░░░░░░░░░░██████████ │ 33%\n 8.0K ┌─┴ /tmp/test_dir/many │ ████████████████████ │ 67%\n 12K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%" thread 'test_main_long_paths' panicked at 'assertion failed: output.contains(&main_output_long_paths())', tests/test_exact_output.rs:119:5 ---- test_unicode_directories stdout ---- thread 'test_unicode_directories' panicked at 'assertion failed: output.contains(&unicode_dir())', tests/test_exact_output.rs:243:5 ---- test_substring_of_names_and_long_names stdout ---- thread 'test_substring_of_names_and_long_names' panicked at 'assertion failed: output.contains(&no_substring_of_names_output())', tests/test_exact_output.rs:198:5 failures: test_apparent_size test_main_basic test_main_long_paths test_main_multi_arg test_substring_of_names_and_long_names test_unicode_directories test result: FAILED. 3 passed; 6 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s error: test failed, to rerun pass '--test test_exact_output' ``` **Commit:** 1b3d0b272401b2eaa196891766d03a7667ea6917. **OS:** Arch Linux **Rust:** 1.50.0 Is `cargo test` the correct way to test `dust`? If not, then it should be documented.
zhus closed this issue 2026-06-08 11:25:29 +03:00
Author
Owner

@bootandy commented on GitHub (Mar 27, 2021):

cargo test should work. The build last ran on CI on Jan 16.

I'll try running it on my local machine and see what happens.

It's the integration tests that are failing. Do you have any environment variables tweaking the width of your terminal?

Perhaps it is this issue: https://github.com/bootandy/dust/issues/132

Can you share your $TERM environment variable?

<!-- gh-comment-id:808702470 --> @bootandy commented on GitHub (Mar 27, 2021): cargo test should work. The build last ran on CI on Jan 16. I'll try running it on my local machine and see what happens. It's the integration tests that are failing. Do you have any environment variables tweaking the width of your terminal? Perhaps it is this issue: https://github.com/bootandy/dust/issues/132 Can you share your $TERM environment variable?
Author
Owner

@KSXGitHub commented on GitHub (Mar 27, 2021):

Can you share your $TERM environment variable?

xterm-256color.

It's the integration tests that are failing. Do you have any environment variables tweaking the width of your terminal?

I don't think there is.

I ran cargo test on a maximized Tilix windows.

<!-- gh-comment-id:808703783 --> @KSXGitHub commented on GitHub (Mar 27, 2021): > Can you share your $TERM environment variable? xterm-256color. > It's the integration tests that are failing. Do you have any environment variables tweaking the width of your terminal? I don't think there is. I ran `cargo test` on a maximized Tilix windows.
Author
Owner

@ibotty commented on GitHub (Jun 17, 2021):

The tests also fail on my system in tmux in gnome-terminal (TERM=screen-256color) as well as on gnome-terminal alone (TERM=xterm-256color).

It also happens with 80x24-sized terminal (tput cols = 80).

<!-- gh-comment-id:863203094 --> @ibotty commented on GitHub (Jun 17, 2021): The tests also fail on my system in tmux in gnome-terminal (`TERM=screen-256color`) as well as on gnome-terminal alone (`TERM=xterm-256color`). It also happens with 80x24-sized terminal (`tput cols` = 80).
Author
Owner

@baile320 commented on GitHub (Jul 8, 2021):

Not sure if this helps, and I can't test on windows or mac, but I'm testing on Manjaro and getting these results:

pub fn test_main_basic() {
    // -c is no color mode - This makes testing much simpler
    initialize();
    let mut cmd = Command::cargo_bin("dust").unwrap();
    let assert = cmd.arg("-c").arg("/tmp/test_dir/").unwrap().stdout;
    let output = str::from_utf8(&assert).unwrap();
    println!("{}", output);
    println!("{}", main_output());
    assert!(output.contains(&main_output()));
}

"output":

   0B     ┌── a_file    │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │   0%
 4.0K     ├── hello_file│████████████████████████████████████████████████ │ 100%
 4.0K   ┌─┴ many        │████████████████████████████████████████████████ │ 100%
 4.0K ┌─┴ test_dir      │████████████████████████████████████████████████ │ 100%

"main_output()":

0B     ┌── a_file    │               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │   0%
 4.0K     ├── hello_file│               ░░░░░░░░░░░░░░░░█████████████████ │  33%
 8.0K   ┌─┴ many        │               █████████████████████████████████ │  67%
  12K ┌─┴ test_dir      │████████████████████████████████████████████████ │ 100%

so it seems like the output i'm getting is actually similar to the the #[cfg(target_os = "macos")] fn main_output().

I also checked out and ran cargo test on commit id 1b3d0b2 (2021-01-16) and e15cf0c (2020-11-25) and the tests still failed... mysterious!

<!-- gh-comment-id:876735843 --> @baile320 commented on GitHub (Jul 8, 2021): Not sure if this helps, and I can't test on windows or mac, but I'm testing on Manjaro and getting these results: ```rust pub fn test_main_basic() { // -c is no color mode - This makes testing much simpler initialize(); let mut cmd = Command::cargo_bin("dust").unwrap(); let assert = cmd.arg("-c").arg("/tmp/test_dir/").unwrap().stdout; let output = str::from_utf8(&assert).unwrap(); println!("{}", output); println!("{}", main_output()); assert!(output.contains(&main_output())); } ``` "output": ``` 0B ┌── a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0% 4.0K ├── hello_file│████████████████████████████████████████████████ │ 100% 4.0K ┌─┴ many │████████████████████████████████████████████████ │ 100% 4.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100% ``` "main_output()": ``` 0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0% 4.0K ├── hello_file│ ░░░░░░░░░░░░░░░░█████████████████ │ 33% 8.0K ┌─┴ many │ █████████████████████████████████ │ 67% 12K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100% ``` so it seems like the output i'm getting is actually similar to the the #[cfg(target_os = "macos")] fn main_output(). I also checked out and ran ```cargo test``` on commit id ```1b3d0b2``` (2021-01-16) and ```e15cf0c``` (2020-11-25) and the tests still failed... mysterious!
Author
Owner

@bootandy commented on GitHub (Jul 9, 2021):

That's interesting - thanks.

I need to rethink how the integration tests are done as they clearly cause problems.

<!-- gh-comment-id:877127221 --> @bootandy commented on GitHub (Jul 9, 2021): That's interesting - thanks. I need to rethink how the integration tests are done as they clearly cause problems.
Author
Owner

@alerque commented on GitHub (Aug 5, 2021):

I just tried adding a check() function to the Arch Linux packaging and it fell pretty flat, failing 6 out of 9 tests. I'll be keeping that out of the packaging until this gets sorted out so that the tests are expected to be passing on different platforms.

cc @grawlinson

<!-- gh-comment-id:893371586 --> @alerque commented on GitHub (Aug 5, 2021): I just tried adding a `check()` function to the Arch Linux packaging and it fell pretty flat, failing 6 out of 9 tests. I'll be keeping that out of the packaging until this gets sorted out so that the tests are expected to be passing on different platforms. cc @grawlinson
Author
Owner

@bootandy commented on GitHub (Aug 5, 2021):

This might well be down to the filesystem type.

I am using ext4

What filesystem is this failing on ?

Can someone with a machine that has test failures tell me what there filesystem is

( For example run: sudo file -sL /dev/nv* and sudo file -sL /dev/sd*)

<!-- gh-comment-id:893426266 --> @bootandy commented on GitHub (Aug 5, 2021): This might well be down to the filesystem type. I am using `ext4` What filesystem is this failing on ? Can someone with a machine that has test failures tell me what there filesystem is ( For example run:` sudo file -sL /dev/nv*` and `sudo file -sL /dev/sd*`)
Author
Owner

@alerque commented on GitHub (Aug 5, 2021):

BTRFS for me.

<!-- gh-comment-id:893435076 --> @alerque commented on GitHub (Aug 5, 2021): BTRFS for me.
Author
Owner

@KSXGitHub commented on GitHub (Aug 5, 2021):

@bootandy I recently added integration tests to pdu. I do not compare the CLI's output to a constant string, instead, I compare it against library's output (pdu is both a binary crate and a library crate). To test the graph itself, I construct fake filesystem tree and compare its graph against a constant string. You may want to do something similar to this.

<!-- gh-comment-id:893435107 --> @KSXGitHub commented on GitHub (Aug 5, 2021): @bootandy I recently added [integration tests to `pdu`](https://github.com/KSXGitHub/parallel-disk-usage/blob/c77a5748fa9af001f6df3d707d760b8bb792c51c/tests/usual_cli.rs). I do not compare the CLI's output to a constant string, instead, I compare it against library's output (`pdu` is both a binary crate and a library crate). To test the graph itself, [I construct fake filesystem tree and compare its graph against a constant string](https://github.com/KSXGitHub/parallel-disk-usage/blob/c77a5748fa9af001f6df3d707d760b8bb792c51c/tests/visualizer.rs). You may want to do something similar to this.
Author
Owner

@bootandy commented on GitHub (Aug 5, 2021):

Does this branch result in the tests passing?

https://github.com/bootandy/dust/compare/fix_tests

Thanks,

<!-- gh-comment-id:893731007 --> @bootandy commented on GitHub (Aug 5, 2021): Does this branch result in the tests passing? https://github.com/bootandy/dust/compare/fix_tests Thanks,
Author
Owner

@alerque commented on GitHub (Aug 5, 2021):

No, but it is a lot closer! In my case it brings the test score up from "3 passed, 6 failed" to "8 passed 1 failed".

The straggler is:

test test_apparent_size ... FAILED

failures:

---- test_apparent_size stdout ----
thread 'test_apparent_size' panicked at 'assertion failed: we_match', tests/test_exact_output.rs:159:5
<!-- gh-comment-id:893757124 --> @alerque commented on GitHub (Aug 5, 2021): No, but it is a lot closer! In my case it brings the test score up from "3 passed, 6 failed" to "8 passed 1 failed". The straggler is: ``` test test_apparent_size ... FAILED failures: ---- test_apparent_size stdout ---- thread 'test_apparent_size' panicked at 'assertion failed: we_match', tests/test_exact_output.rs:159:5 ```
Author
Owner

@bootandy commented on GitHub (Aug 6, 2021):

Thanks for the suggestion, but I think I'd rather keep the tests running against a real filesystem. I know this gives more failures but it makes the tests more realistic.

<!-- gh-comment-id:894156183 --> @bootandy commented on GitHub (Aug 6, 2021): Thanks for the suggestion, but I think I'd rather keep the tests running against a real filesystem. I know this gives more failures but it makes the tests more realistic.
Author
Owner

@bootandy commented on GitHub (Aug 6, 2021):

I've now merged a fix that hopefully will stop the tests failing .

<!-- gh-comment-id:894156422 --> @bootandy commented on GitHub (Aug 6, 2021): I've now merged a fix that hopefully will stop the tests failing .
Author
Owner

@alerque commented on GitHub (Aug 6, 2021):

I can confirm the master branch HEAD currently passes tests for me on the same system setup I was using earlier.

<!-- gh-comment-id:894173969 --> @alerque commented on GitHub (Aug 6, 2021): I can confirm the *master* branch HEAD currently passes tests for me on the same system setup I was using earlier.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bootandy/archived-dust#58