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: reshim of plugins installed by path #1287

Merged
merged 4 commits into from Apr 5, 2023
Merged

Conversation

alexezio
Copy link
Contributor

@alexezio alexezio commented Jul 4, 2022

Summary

change sed delimiter character from / to |

to prevent reshim local path error(sed delimiter character conflict)

Fixes: #1286

Other Information

maybe we could use a better delimiter character for this scenario?

@alexezio alexezio requested a review from a team as a code owner July 4, 2022 14:59
@jthegedus
Copy link
Contributor

Can you add a test case for regression testing?

@alexezio
Copy link
Contributor Author

alexezio commented Jul 5, 2022

Can you add a test case for regression testing?

Hi, I add a test case for testing, could you please review the change?

@@ -90,7 +90,7 @@ write_shim_script() {

if [ -f "$shim_path" ]; then
if ! grep -x "# asdf-plugin: ${plugin_name} ${version}" "$shim_path" >/dev/null; then
sed -i.bak -e "s/exec /# asdf-plugin: ${plugin_name} ${version}\\"$'\n''exec /' "$shim_path"
sed -i.bak -e "s|exec |# asdf-plugin: ${plugin_name} ${version}\\"$'\n''exec |' "$shim_path"
Copy link
Member

Choose a reason for hiding this comment

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

The | pipe character is permitted in file names so this fix may not be sufficient for all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't allowed filename special character:

so I think | may not be the best character in this scenario, but I can't find the better one~, and most of us won't use | as a part of filename

Copy link
Contributor

Choose a reason for hiding this comment

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

We started validating plugin names in #1010, perhaps we should be validating dir names before we create/modify them in asdf so we can be more confident about which special char we use here.

I also think once we decide which to use we should use it consistently across the project (a follow up PR seems best)

Copy link
Member

Choose a reason for hiding this comment

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

What if we used Bash substring replacement for this? The Bash expression can be parameterized. (see https://tldp.org/LDP/abs/html/string-manipulation.html and scroll down to the Substring Replacement header).

Something like this (I haven't had a chance to test it):

line=$(...)
match='exec '
replacement="# asdf-plugin: ${plugin_name} ${version}\\"$'\n''exec "
updated_line=${line/$match/$repl}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Stratus3D @jthegedus
Hi guys:
Maybe I have found a better way to solve this problem.
Insert a new line before the last line rather than regex and replace the previous line with multi-lines.
the code below:

sed -i.bak -e '$i\'$'\n'"# asdf-plugin: ${plugin_name} ${version}" "$shim_path"

$i\'$'\n' means inserting a new line before the last line. this flag works on both Linux and macOS. so we insert the plugin info to the new line without regex.
We could avoid the conflict problem with sed delimiter character by using this approach.
could you guys review this change? thx.

@alexezio
Copy link
Contributor Author

alexezio commented Jul 6, 2022

another question need help~
I pass the test suite case in my MacBook, but can't be passed here, is there any approach to solve this issue?
WeChatc0ee071bb577f9c09804984839ed7244

@Stratus3D
Copy link
Member

another question need help~ I pass the test suite case in my MacBook, but can't be passed here, is there any approach to solve this issue? WeChatc0ee071bb577f9c09804984839ed7244

This can be challenging. It looks like the new test is failing in Github actions because one of the commands it runs exited with a non-zero exit status. I typically echo the $output of the command before asserting the exit code is 0 when debugging issues like that. Usually $output holds the answer to the issue, and BATS will take whatever you print and render it to the test output so it will be visible in the runner output. Hope this helps!

@alexezio
Copy link
Contributor Author

can anyone review the new change?

@jthegedus jthegedus added the priority asdf core intend to resolve soon label Jul 13, 2022
@jthegedus
Copy link
Contributor

@alexezio please review the failed status checks

@alexezio
Copy link
Contributor Author

@jthegedus
hello, jthegedus:
I fix the unit-test issue, could you please approve for auto-test again?

@alexezio
Copy link
Contributor Author

alexezio commented Aug 4, 2022

It seems like all unit-test are passed, so could this pr be approved?

@jthegedus
Copy link
Contributor

@alexezio Sorry for my absence and delay here. Can you address the Shellcheck issue?

In lib/commands/reshim.bash line 93:
sed -i.bak -e '$i\'$'\n'"# asdf-plugin: ${plugin_name} ${version}" "$shim_path"
^-- SC1003 (info): Want to escape a single quote? echo 'This is how it'\''s done'.

For more information:
https://www.shellcheck.net/wiki/SC1003 -- Want to escape a single quote? ec...

@alexezio
Copy link
Contributor Author

alexezio commented Dec 1, 2022

@jthegedus hi, sorry for my absence. I check the shellcheck error, and I think that is not a issue.
The backslash \ after $i means that insert the text after the backslash to the last line without needed a /pattern/ for the last line. so it can't be quoted. the $ symol that surrended with single quote string represent the end of old lines.
And I try to solve the shell format, but it doesn't work. So could you pelease review this?

@jthegedus
Copy link
Contributor

From @dylan-chong from - #1311 (comment)

@alexezio This means that the change to the sed pattern in your PR #1287 is not longer required. But it would still be great to merge the test that you wrote in your PR. I have checked and that test passes in this branch, but I don't want to steal your contribution so I'll let you commit that :)

Let's:

  • remove the changes here to lib/commands/reshim.bash
  • rebase
  • resolve conflicts for test/

and get this test case in and close out this PR.

@jthegedus jthegedus changed the title fix: reshim local path (#1286) test: reshim of plugins installed by path (#1286) Apr 5, 2023
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.

Updated this to just be a new test case as per #1287 (comment)

Thanks 🙇

@jthegedus jthegedus changed the title test: reshim of plugins installed by path (#1286) test: reshim of plugins installed by path Apr 5, 2023
@jthegedus jthegedus merged commit d28b13a into asdf-vm:master Apr 5, 2023
10 checks passed
@Stratus3D
Copy link
Member

Thanks for writing the test for this @alexezio ! And thanks for getting this merged @jthegedus !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority asdf core intend to resolve soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: asdf reshim cann't work with local path
4 participants