Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail when not connected to a terminal #318

Closed
ignatenkobrain opened this issue Nov 27, 2017 · 7 comments
Closed

Tests fail when not connected to a terminal #318

ignatenkobrain opened this issue Nov 27, 2017 · 7 comments
Assignees
Labels
errors › build error exa fails to build features › arguments Command-line argument parsing
Milestone

Comments

@ignatenkobrain
Copy link
Contributor

---- options::test::oneline_across stdout ----
	thread 'options::test::oneline_across' panicked at 'called `Result::unwrap_err()` on an `Ok` value: (Options { dir_action: List, filter: FileFilter { list_dirs_first: false, sort_field: Name(AaBbCc), reverse: false, dot_filter: JustFiles, ignore_patterns: IgnorePatterns { patterns: [] }, git_ignore: Off }, view: View { mode: Lines, colours: Colours { colourful: false, scale: false, filekinds: FileKinds { normal: Style {}, directory: Style {}, symlink: Style {}, pipe: Style {}, block_device: Style {}, char_device: Style {}, socket: Style {}, special: Style {}, executable: Style {} }, perms: Permissions { user_read: Style {}, user_write: Style {}, user_execute_file: Style {}, user_execute_other: Style {}, group_read: Style {}, group_write: Style {}, group_execute: Style {}, other_read: Style {}, other_write: Style {}, other_execute: Style {}, special_user_file: Style {}, special_other: Style {}, attribute: Style {} }, size: Size { numbers: Style {}, unit: Style {}, major: Style {}, minor: Style {}, scale_byte: Style {}, scale_kilo: Style {}, scale_mega: Style {}, scale_giga: Style {}, scale_huge: Style {} }, users: Users { user_you: Style {}, user_someone_else: Style {}, group_yours: Style {}, group_not_yours: Style {} }, links: Links { normal: Style {}, multi_link_file: Style {} }, git: Git { new: Style {}, modified: Style {}, deleted: Style {}, renamed: Style {}, typechange: Style {} }, punctuation: Style {}, date: Style {}, inode: Style {}, blocks: Style {}, header: Style {}, symlink_path: Style {}, broken_arrow: Style {}, broken_filename: Style {}, control_char: Style {} }, style: FileStyle { classify: JustFilenames, exts: NoFileColours } } }, [])', src/libcore/result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.
---- options::view::test::views::across stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::across' panicked at 'assertion failed: false', src/options/view.rs:526:8
---- options::view::test::views::empty stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::empty' panicked at 'assertion failed: false', src/options/view.rs:521:8
---- options::view::test::views::gracross stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::gracross' panicked at 'assertion failed: false', src/options/view.rs:527:8
---- options::view::test::views::grid stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::grid' panicked at 'assertion failed: false', src/options/view.rs:525:8
---- options::view::test::views::just_binary stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::just_binary' panicked at 'assertion failed: false', src/options/view.rs:548:8
---- options::view::test::views::just_blocks stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::just_blocks' panicked at 'assertion failed: false', src/options/view.rs:547:8
---- options::view::test::views::just_bytes stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::just_bytes' panicked at 'assertion failed: false', src/options/view.rs:549:8
---- options::view::test::views::just_git stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::just_git' panicked at 'assertion failed: false', src/options/view.rs:552:8
---- options::view::test::views::just_header stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::just_header' panicked at 'assertion failed: false', src/options/view.rs:543:8
---- options::view::test::views::just_group stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::just_group' panicked at 'assertion failed: false', src/options/view.rs:544:8
---- options::view::test::views::just_inode stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::just_inode' panicked at 'assertion failed: false', src/options/view.rs:545:8
---- options::view::test::views::just_links stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::just_links' panicked at 'assertion failed: false', src/options/view.rs:546:8
---- options::view::test::views::leg stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::leg' panicked at 'assertion failed: false', src/options/view.rs:539:8
---- options::view::test::views::original_g stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::original_g' panicked at 'assertion failed: false', src/options/view.rs:524:8
---- options::view::test::views::lid stdout ----
	Testing Ok(Lines)
thread 'options::view::test::views::lid' panicked at 'assertion failed: false', src/options/view.rs:538:8
failures:
    options::test::oneline_across
    options::view::test::views::across
    options::view::test::views::empty
    options::view::test::views::gracross
    options::view::test::views::grid
    options::view::test::views::just_binary
    options::view::test::views::just_blocks
    options::view::test::views::just_bytes
    options::view::test::views::just_git
    options::view::test::views::just_group
    options::view::test::views::just_header
    options::view::test::views::just_inode
    options::view::test::views::just_links
    options::view::test::views::leg
    options::view::test::views::lid
    options::view::test::views::original_g
test result: FAILED. 368 passed; 16 failed; 4 ignored; 0 measured; 0 filtered out

Not sure how to debug that...

@ogham
Copy link
Owner

ogham commented Dec 17, 2017

This is weird! When I read "some tests fail", I thought you'd stumbled into some weird OS behaviour, or an edge case in file names, or a security permissions issue, or something like that...

But your failing tests are options parsing tests which are basically just pure functions!

I did notice something suspicious, though. The only tests that are failing here are the ones that work out how to format the output, and they're all coming back as Ok(Lines) instead of the intended result. And the Lines type is the one used when standard output isn't connected to a terminal, because it doesn't depend on width.

Sure enough:

screen shot 2017-12-17 at 19 16 47

Turns out the tests fail when they're not connected to a terminal! I had no idea. I'm guessing you're running the tests from inside another program, such as an IDE or a text editor?

I think I know how to fix this, but it's messy: mock out the "terminal width getter" code for tests, and use the actual term_size crate when actually running. I thought I could get away without doing this, but apparently not.

@ogham ogham self-assigned this Dec 17, 2017
@ogham ogham added errors › build error exa fails to build features › arguments Command-line argument parsing labels Dec 17, 2017
@ogham ogham changed the title some tests fail Tests fail when not connected to a terminal Dec 17, 2017
@ignatenkobrain
Copy link
Contributor Author

I'm running them as part of building exa's RPM since I've packaged exa for Fedora. And yeah, it runs without tty.

@mssun
Copy link

mssun commented Feb 9, 2018

I have the same issue. It 's easy to reproduce:

cargo test  > test.txt
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running target/debug/deps/exa-2bd4cc43b44a5d95
error: test failed, to rerun pass '--lib'

The file with stdout is attached:
test.txt

@sylvestre
Copy link

Also happening in the Debian CI: http://bugs.debian.org/917225

@sylvestre
Copy link

@jsoo1
Copy link

jsoo1 commented Feb 1, 2020

I just bumped into this packaging for guix. I guess I will disable the offending tests for now.

@ogham
Copy link
Owner

ogham commented Oct 22, 2020

I just commited (not merged yet) a big refactor to the way options parsing is done. It no longer looks up the terminal width during options parsing, instead doing it later, so all the tests are now testing pure functions that aren't dependent on their environment. cargo test | cat even works.

So this issue is not long for this world

@ogham ogham added this to the v0.10.0 milestone Oct 22, 2020
@ogham ogham closed this as completed in 3419afa Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors › build error exa fails to build features › arguments Command-line argument parsing
Projects
None yet
Development

No branches or pull requests

5 participants