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

[test/spec] Split history builtin tests from builtins2 tests #1593

Merged
merged 6 commits into from
Apr 30, 2023

Conversation

PossiblyAShrub
Copy link
Collaborator

@PossiblyAShrub PossiblyAShrub commented Apr 30, 2023

As per #1587 (comment).


While working on this I realized we were missing the case where HISTFILE does not point to a file (even if it's a valid string). This should return an error code if a user tries to then history -r.

history_filename = self.GetHistoryFilename()
history_file_exists = path_stat.exists(history_filename)
if not history_file_exists:
raise error.ErrExit(1, "The file '%s' ($HISTFILE) does not exist" % history_filename, loc.Missing())
Copy link
Contributor

Choose a reason for hiding this comment

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

hm actually ErrExit is intended for use with set -o errexit

I think simply return 1 will do what you want here?

Also I would just say if not path_stat.exists() instead of the extra var


Is this intended to be friendlier than bash? I think bash just ignores the error?

I tried bash -i -c 'HISTFILE=a; history -r

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. I still want to provide some information about the failure. I see that we use a self.errfmt.Print_ pattern in other builtins. Would that be appropriate here?

Is this intended to be friendlier than bash? I think bash just ignores the error?

I tried bash -i -c 'HISTFILE=a; history -r

I do get an error code on my machine (no message though)

$ HISTFILE=_tmp/dne
$ history -r
$ echo $?
1

@andychu
Copy link
Contributor

andychu commented Apr 30, 2023

Ah OK , makes sense.

Yes errfmt.Print_ is consistent


I changed the error message to use %r because that will quote the filename properly (e.g. in the rare case that the filename contains a single quote)

In the C++ runtime we have a format string implementation that supports %s %r %d and that's it basically

  • %s and %r must be strings (unfortunately you get a runtime error if not, not compile time
  • %d must be an integer

@andychu andychu merged commit 3de0fea into soil-staging Apr 30, 2023
@andychu
Copy link
Contributor

andychu commented Apr 30, 2023

Merged, thanks for doing this!

@PossiblyAShrub PossiblyAShrub deleted the split-builtins-tests branch April 30, 2023 04:19
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