Describe the bug
Running Homebrew tests that require binaries managed by asdf can fail, in this instance with this message:
unknown command: node. Perhaps you have to reshim?
This appears to be because in the test environment the HOME environment variable is changed by Homebrew. It appears as though asdf depends on this.
Homebrew Node.js installations and nvm do not have this problem, but as mentioned in https://github.com/asdf-vm/asdf/issues/785 maybe this is unavoidable and should just be added to the Common Homebrew Issues section?
To Reproduce
Expected behavior
The test to run.
Actual behavior
The node command was not found.
Thanks for reporting @dnicolson
If the ASDF_DATA_DIR env var was used would this issue be resolved? Perhaps we should recommend as much to Homebrew users if this is the case? 馃
Can you perform a test of this?
We should also have a test case for this since we have many Homebrew users.
Setting the ASDF_DATA_DIR environment variable doesn't seem to have any effect.
There is a predefined list (Java, Go, Rust, CURL) of environment variables that are included in the Homebrew test environment.
Adding ASDF_DATA_DIR to that list resolves the issue, but then there is the familiar warning:
asdf: No version set for command node
This is only an issue with locally developing Homebrew test methods though (CI works fine), so maybe it should just be documented as a caveat.
This is only an issue with locally developing Homebrew test methods
This seems very odd.
asdf only relies upon $HOME/.asdf as the default location to lookup shims/plugins etc, so if ASDF_DATA_DIR is set outside of $HOME then Homebrew shouldn't be able to affect this and the lookup of the tool should work.
Can you ensure your test is with ASDF_DATA_DIR outside of $HOME?
maybe it should just be documented as a caveat
We should document this, yes, but I would like to investigate and understand the root cause completely
Can you ensure your test is with ASDF_DATA_DIR outside of $HOME?
I tried setting ASDF_DATA_DIR to /tmp but it made no difference.
The environment variables seem to be ignored in the test sandbox. Only by manually adding ASDF_DATA_DIR to the Homebrew formula.rb file was I able to see any results.
was I able to see any results.
But those results were the asdf: No version set for command node error you mentioned above? Is this completely resolved if you were to set a local node version in the test environment also?
Running asdf local nodejs 12.16.1 didn't change anything.
Sorry, I wasn't very clear. In the Homebrew test environment, where you added asdf_data_dir, can you also have it set the node version there?
Running system("asdf local nodejs 12.16.1") in formula.rb results in the following output:
asdf local nodejs 12.16.1
sed: /Users/dave/Dropbox/Mackup/.tool-versions: Operation not permitted
rm: /Users/dave/Dropbox/Mackup/.tool-versions.bak: No such file or directory
Okay then, seems like this is going to be an annoying issue to document. So what workarounds should we document that will allow users to get brew test <xyz> to work?
More investigation would be needed on how the Homebrew test environment works. I simply uninstalled asdf to get the tests to work.
I simply uninstalled
asdf
Hardly an ideal solution.
Interesting that sed was not permitted. For documentation purposes, that sed call occurs in https://github.com/asdf-vm/asdf/blob/master/lib/commands/version_commands.bash#L44 as a downstream call from https://github.com/asdf-vm/asdf/blob/master/lib/commands/command-local.bash
Would you consider me adding this to the Homebrew caveats Issue a resolution for this Issue and thus able to be closed?
Sure, I think that's the best outcome for now.