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

Bash Strict Mode: Part 1 of 3 #817

Closed
wants to merge 13 commits into from
Closed

Bash Strict Mode: Part 1 of 3 #817

wants to merge 13 commits into from

Conversation

Stratus3D
Copy link
Member

Summary

Instead of implementing Bash strict mode in one pull request (as I tried to do with #520 and failed) I am going to do it in three parts:

  • Don't allow unset variables (this PR)
  • Exit on non-zero exit codes (including in pipes)
  • Set a stricter IFS

This PR addresses part of #160

@Stratus3D Stratus3D requested a review from a team as a code owner October 16, 2020 15:14
generate_shims_for_version "$plugin_name" "$full_version"
asdf_run_hook "post_asdf_reshim_$plugin_name" "$full_version"
generate_shims_for_version "$plugin_name" "$full_version_name"
asdf_run_hook "post_asdf_reshim_$plugin_name" "$full_version_name"
Copy link
Member Author

Choose a reason for hiding this comment

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

This was actually a bug! These functions were invoked in a way that was inconsistent with the code in the else block below.

@@ -80,5 +80,5 @@ teardown() {

# Should not contain duplicate colon
run grep '::' <(echo "$path_line")
[ "$duplicate_colon" == "" ]
Copy link
Member Author

Choose a reason for hiding this comment

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

Another bug. This variable was never set so this line wasn't actually testing anything.

@@ -119,7 +119,7 @@ teardown() {
@test "parse_asdf_version_file should output path on project with spaces" {
PROJECT_DIR="$PROJECT_DIR/outer space"
mkdir -p "$PROJECT_DIR"
cd $outer
Copy link
Member Author

Choose a reason for hiding this comment

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

Another test that wasn't testing what it was suppose to because of an unset variable.

@jthegedus
Copy link
Contributor

looking over this now :)

@Stratus3D
Copy link
Member Author

@jthegedus build is failing right now. I created this PR on my OSX machine but it looks like things aren't working on Ubuntu. I'm going pull these changes down on my Ubuntu machine and resume working through the remaining issues. I probably won't get to this until late next week though.

@jthegedus
Copy link
Contributor

No problem. This is a good start to enabling strict mode. I like this process has revealed bugs, proves the effort is valid 😄

Comment on lines +19 to +22
# Yes, the syntax for the expansion is ugly and confusing, but it is what we
# need to do to make it work with the nounset option. See
# https://stackoverflow.com/q/7577052/ for the details
"$env_cmd" ${env_args[@]+"${env_args[@]}"}
Copy link
Contributor

Choose a reason for hiding this comment

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

In an effort to capture minimum versions we support, I would like capture the min Bash version that supports this in the docs if we could

Copy link
Contributor

@jthegedus jthegedus left a comment

Choose a reason for hiding this comment

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

Hey mate, can this be re-based? If I recall it was pretty close to done.

@Stratus3D
Copy link
Member Author

Hey mate, can this be re-based? If I recall it was pretty close to done.

Yes, this is next on my agenda. I will rebase and try to fix the failing tests on Ubuntu tomorrow.

@Stratus3D
Copy link
Member Author

I just rebased this PR onto latest master. I'm hoping to finish this PR update and get it merged soon.

@jthegedus
Copy link
Contributor

Tag me when you wish to have a review.

@jthegedus
Copy link
Contributor

I am not sure if we can automate some of these fixes with Shellcheck/Shfmt, but perhaps these proposed changes can be enforced (and potentially auto-fixed) by expanding scripts/stylecheck.py?

@jthegedus
Copy link
Contributor

@Stratus3D should we close this?

@hyperupcall
Copy link
Contributor

We can definitely add some stuff to checkstyle.py to prepare things for set -u, and I feel reluctant to say this to a 3-year old PR adding this stuff, but in my opinion, errunset is more trouble than it's worth, especially with ShellCheck.

Unfortunately, I can't think of any way to add the latter two to checkstyle.py, but maybe there is a way.

@jthegedus
Copy link
Contributor

@hyperupcall I'm very happy with the level of code quality improvements you have brought to the project over the past year. I don't think this is worth tackling (and assumed Stratus would agree), so thought I would just ask before closing it.

I will just close it though as I think we're all better off spending our time on other issues than this in the short term. We can always dig it back up should we want.

@jthegedus jthegedus closed this Jun 22, 2023
@Stratus3D
Copy link
Member Author

Thanks @jthegedus. I don't have plans to tackle this anymore. I'm focusing my effort on the Rust rewrite.

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.

None yet

3 participants