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/more: run all tests with terminal_simulation #6121

Closed

Conversation

tertsdiepraam
Copy link
Member

@tertsdiepraam tertsdiepraam commented Mar 24, 2024

Closes #6100

@cakebaker @BenWiederhake, could you check whether this solves the problem for you too?

I think that with this change, we can run the tests in the CI too, but I first want to check whether the issue is fixed. I could also clean this up, but I went with a quick and dirty solution first.

@BenWiederhake
Copy link
Collaborator

Huh, this is weird. The terminal is fixed (even running it several times and in various ways, the terminal never breaks), but now test_more::test_more_no_arg is failing:

---- test_more::test_more_no_arg stdout ----
run: /home/nattiff/workspace/coreutils-rs/target/debug/coreutils more
thread 'test_more::test_more_no_arg' panicked at 'Command was expected to fail.


 stderr = ', tests/by-util/test_more.rs:13:14


failures:
    test_more::test_more_no_arg

@cakebaker
Copy link
Contributor

I get the same result as @BenWiederhake: the terminal is fixed and test_more_no_arg fails.

@tertsdiepraam
Copy link
Member Author

Looks like the terminal simulation is broken then, I'll take another look...

@tertsdiepraam
Copy link
Member Author

@cre4ture since you implemented the terminal simulation, do you know what could be wrong with stdin? It looks like it keeps hanging.

This is also a bug in more by the way. The util-linux more can exit immediately, but uutils more waits for ctrl+d.

@cre4ture
Copy link
Contributor

@tertsdiepraam I will take a look into the tests. Afterwards, maybe I can help.

@cre4ture
Copy link
Contributor

cre4ture commented Mar 24, 2024

after investigation, I think the issue is on uu_more side and not the test-utils.

I compared the behaviour of GNU with uutils:

uli@hp13-ulix:~/dev_rust/coreutils$ echo -n "" | more ; echo $?
0
uli@hp13-ulix:~/dev_rust/coreutils$ echo -n "" | target/debug/coreutils more ; echo $?
more: bad usage
Try 'target/debug/coreutils more --help' for more information.
1
uli@hp13-ulix:~/dev_rust/coreutils$ 

I did some more tests in a similar direction (using /dev/null as input, pipe outputs to tee, ...).
I even used the GNU more in our test-suite to compare behaviour.
I concluded that the only condition that more needs to put out the error message is that stdin is connected to a terminal.

The following patch fixes the issue for me. I would have pushed it directly to this PR, but I don't know how to do this.

diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs
index 0b8c838f2..987b48998 100644
--- a/src/uu/more/src/more.rs
+++ b/src/uu/more/src/more.rs
@@ -5,7 +5,7 @@
 
 use std::{
     fs::File,
-    io::{stdin, stdout, BufReader, Read, Stdout, Write},
+    io::{stdin, stdout, BufReader, IsTerminal, Read, Stdout, Write},
     panic::set_hook,
     path::Path,
     time::Duration,
@@ -158,10 +158,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
         }
         reset_term(&mut stdout);
     } else {
-        stdin().read_to_string(&mut buff).unwrap();
-        if buff.is_empty() {
+        if stdin().is_terminal() {
             return Err(UUsageError::new(1, "bad usage"));
         }
+        stdin().read_to_string(&mut buff).unwrap();
         let mut stdout = setup_term();
         more(&buff, &mut stdout, false, None, None, &mut options)?;
         reset_term(&mut stdout);

@tertsdiepraam
Copy link
Member Author

@cre4ture Sounds good! Could you put that up as a PR?

I do think that somethings up with the terminal simulation though. Or at least some additional configuration might be necessary, where it's possible to simulate a terminal only for output or something like that. Would that make sense?

@cre4ture
Copy link
Contributor

where it's possible to simulate a terminal only for output or something like that. Would that make sense?

true, especially for tools like more it does makes sense. Here the condition is that the only the output is allowed to be a terminal. I will create another PR for adding some destiction possibilitiy.

@sylvestre sylvestre force-pushed the no-raw-mode-after-more-tests branch from 88d0a4d to 52ed61f Compare September 14, 2024 07:35
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/mv/mv-n is no longer failing!
Congrats! The gnu test tests/mv/update is no longer failing!
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

@sylvestre
Copy link
Contributor

inactive for a while, closing. cc @tertsdiepraam

@sylvestre sylvestre closed this Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

more: test output often looks messy and input is no longer shown afterwards
5 participants