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

add tests for all bash prompt special characters #2236

Conversation

simonLeary42
Copy link
Collaborator


#### \l for TTY device basename
PS1='foo \l bar'
tty_device_basename="$(basename "$(tty)")"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok to rely on external programs basename and tty?

spec/prompt.test.sh Outdated Show resolved Hide resolved
@andychu
Copy link
Contributor

andychu commented Jan 24, 2025

Thanks, this looks very helpful!

I let the CI run, but the spec tests timed out after 15 minutes. Then I cloned locally and noticed that test case 27 for \j hangs on my machine ?

If I do

test/spec.sh prompt -r 27 

then it hangs


Though I am not sure why, because when I run it manually it doesn't hang

$ cat _tmp/27
#### \j for number of jobs
PS1='foo \j bar'
echo "${PS1@P}" | egrep -q 'foo 0 bar'
echo matched=$?
sleep 999 &
echo "${PS1@P}" | egrep -q 'foo 1 bar'
echo matched=$?
kill %%
fg
echo "${PS1@P}" | egrep -q 'foo 0 bar'



andy@hoover:~/git/oils-for-unix/simonLeary42/oils$ bash _tmp/27
matched=0
matched=0
_tmp/27: line 9: fg: no job control

@andychu
Copy link
Contributor

andychu commented Jan 24, 2025

Here is the CI dashboard

https://mb.oilshell.org/uuu/github-jobs/9010/

and then if you click through you can see a timeout after 15 minutes, which is the max we let it run:

https://mb.oilshell.org/uuu/github-jobs/9010/#job-ovm-tarball


The tests aren't really sandboxed, so we basically use a Docker container I build as a source of truth ... (could be improved at some point)


To make progress, I might just comment out test case 27 for now, and then we can see if the others pass?

If there are a bunch of green tests for bash, and a red ones for OSH, and it runs reliably in the CI, then that is good progress, and can be merged


I tend to break things up in steps, so we can do \j last I guess

https://github.com/oils-for-unix/oils/wiki/Spec-Tests

@andychu
Copy link
Contributor

andychu commented Jan 24, 2025

BTW the way I "extract" the test case is test/spec.sh prompt -r 27 -p > _tmp/27 -- that prints it instead of running it

And I either run with bash on my machine, or a specific versions of bash that we have in build/dev-shell.sh , i.e. compiled from source


How many of the tests pass locally on bash, on your machine? I am seeing a few failures other than the \j one, which I haven't diagnosed yet

@simonLeary42
Copy link
Collaborator Author

simonLeary42 commented Jan 26, 2025

$ sleep 999 &
[%1] PID 12220 Started
$ echo %%
%%
$ kill %%
kill: ‘%%’: invalid process id
$ fg
fg: PID 12220 Continued
^C
$

since %% isn't expanded since osh doesn't provide a kill shell builtin that supports job IDs with the % syntax, osh pulls the sleep 999 process into foreground and sleeps for 999 seconds. I just turned down the sleep time to 5 seconds

@simonLeary42
Copy link
Collaborator Author

I'm struggling to come up with a good way to run the "command number" prompt test. I have to either find a reliable way to get the current "command number", which I'm not sure is even implemented in osh, and then just test that the next "command number" is the previous "command number" +1, or find a reliable way to spawn a subprocess of the current shell. I can't use $0 because -bash isn't a valid path, I can't use $SHELL because osh doesn't set that variable as far as I can tell, and the "command number" doesn't reset when using parentheses. I could try and use other clues to figure out what the current shell is and then hard code the path to each shell, but I don't like that...

@simonLeary42
Copy link
Collaborator Author

on my machine, all the prompt test cases pass for bash except 0 and 32.

@andychu
Copy link
Contributor

andychu commented Jan 27, 2025

OK looks like 9 tests fail on OSH, and they pass on bash:

https://mb.oilshell.org/uuu/github-jobs/9023/ovm-tarball.wwz/_tmp/spec/osh-py/prompt.html

Thanks!

I pushed a change to add this metadata line, which lets the CI pass

## oils_failures_allowed: 9

and then we can "whittle down" the errors as we go

@andychu
Copy link
Contributor

andychu commented Jan 27, 2025

I also added you as a collaborator, so you can run the CI yourself, and don't have to wait for me to hit "approve"

Most contributors directly modify a branch of oils-for-unix/oils for that reason, instead of having their own fork

It is a weird github limitation - https://github.com/oils-for-unix/oils/wiki/Contributing

@andychu andychu changed the base branch from master to soil-staging January 27, 2025 15:07
@andychu
Copy link
Contributor

andychu commented Jan 27, 2025

OK let me see what hapepns if I try to merge ... the CI checks didn't finish because of the permission issue, but maybe it will go through on soil-staging (confused about github's rules)

@andychu andychu merged commit 89fc3bc into oils-for-unix:soil-staging Jan 27, 2025
17 of 18 checks passed
@andychu
Copy link
Contributor

andychu commented Jan 27, 2025

(The merged worked! But from now on, please work in the upstream repo, so then you can see the CI results immediately without waiting for approval )


Thanks for the tests! I was able to knock off \v and \V very quickly

b2da0db

And it worked in C++ transparently

Let me look at some others

@andychu
Copy link
Contributor

andychu commented Jan 27, 2025

I think \D{} is actually more general than \t \T \@ \d

I mean I can understand why we should have them, but it annoys me to carry that over, since it is more readable to use \D{} and an explicit format IMO

rather than remembering what those mean

@andychu
Copy link
Contributor

andychu commented Jan 27, 2025

I am not quite sure how to get history number or command number, and what the exact difference is

I think the history number should come from GNU readline -- if we already have an API, then it shouldn't be too hard to add

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.

2 participants