assert-rs / predicates-rs

Boolean-valued predicate functions in Rust
docs.rs/predicates
Apache License 2.0
173 stars 29 forks source link

Predicates showing one value of the comparison but not the other #116

Closed alpha-tango-kilo closed 2 years ago

alpha-tango-kilo commented 2 years ago

Hi there! This is my first time using asset_fs so forgive me if I'm using it wrong or misunderstanding the output.

I'm using ChildPath::assert with a byte slice to check if the byte-content of some files is as expected. The test is failing on the assertion, yet from the information being printed, I don't understand why the assertion failed - all the data output is the same

Unexpected file, failed var == [164, 108, 152, 89, 172, 190, 243, 194, 202, 143, 158, 187, 192, 211, 33, 195, 34, 27, 108, 57, 177, 144, 199, 135, 136, 143, 57, 246, 45, 100, 247, 59, 163]
└── var == [164, 108, 152, 89, 172, 190, 243, 194, 202, 143, 158, 187, 192, 211, 33, 195, 34, 27, 108, 57, 177, 144, 199, 135, 136, 143, 57, 246, 45, 100, 247, 59, 163]

path=C:\Users\Atk\AppData\Local\Temp\.tmpkmVDEm\split_me.p2
thread 'split' panicked at 'Unexpected file, failed var == [164, 108, 152, 89, 172, 190, 243, 194, 202, 143, 158, 187, 192, 211, 33, 195, 34, 27, 108, 57, 177, 144, 199, 135, 136, 143, 57, 246, 45, 100, 247, 59, 163]
└── var == [164, 108, 152, 89, 172, 190, 243, 194, 202, 143, 158, 187, 192, 211, 33, 195, 34, 27, 108, 57, 177, 144, 199, 135, 136, 143, 57, 246, 45, 100, 247, 59, 163]

For additional context, my project involves partitioning files and reconstructing them. I'm currently writing integration tests for the partitioning of files, so I create a file with a known set of bytes, split it into a known number of parts, then check the bytes of each file are correct. Repository here

Using assert_fs v1.0.6 on stable Rust. Let me know if you need any further information

epage commented 2 years ago

To reproduce, would I just clone that repository and run the linked test?

alpha-tango-kilo commented 2 years ago

Yep the repo currently has the failing test in it. Just clone and cargo test :) It's not a big program to compile

epage commented 2 years ago

Looks like its a bug in the predicates crate where it doesn't always report the actual value. In your case, its

[/home/epage/src/personal/predicates-rs/src/path/fc.rs:78] &buffer = Ok( 
    [   
        177,
        144,
        199,
        135,
        136,
        143,
        57,
        246,
        45,
        100,
        247,
        59,
        163,
        101,
        168,
        68,
        244,
        190,
        137,                                                             
        114,                                                                                                                                           ],       
)                                                                                                                                                  `
epage commented 2 years ago

The new error I'm preparing is:

---- exact_split stdout ----                                                                                                                       
thread 'exact_split' panicked at 'Unexpected file, failed var == [
    164,
    108, 
    152,       
    89,
    172,                                                                                                                                           
    190,
    243,                                                                 
    194,
    202,                           
    143,
    158,
    187,
    192,
    211,
    33,
    195,
    34,
    27,
    108,
    57,
]
├── var: [
|       177,
|       144,
|       199,
|       135,
|       136,
|       143,
|       57,
|       246,
|       45,
|       100,
|       247,
|       59,
|       163,
|       101,
|       168,
|       68,
|       244,
|       190,
|       137,
|       114,
|   ]
└── var: /tmp/.tmp6KtALq/split_me.p2
epage commented 2 years ago

predicates 2.1.0 is now out. If you just update your lock file, you should pick up the change.

I'd also recommend enabling the color feature for making it easier to parse the output (been tempted to make it a default feature, just haven't yet)

Also, I recommend seeing if my new testing crate would be of use: https://github.com/assert-rs/trycmd

alpha-tango-kilo commented 2 years ago

Thanks for fixing this so quickly! I guess I'll need assert_cmd to be updated to use the new version of predicates to be able to benefit from the update, given I don't pull in predicates directly

epage commented 2 years ago

assert_cmd only says to use any semver compatible version of predicates v2. Resolving that version requirement to a specific version happens in your crate when generating the Cargo.lock file. I'm sure there are ways to use cargo update to do this but I generally just delete my whole lock file and run cargo check to force it to re-generate.