4 ms·
asdf banned_commands
- ryan-duve 4y agoAre these meant to be programmatically enforced via CI? If so, I wonder if adding an Alpine-based build to the pipeline would cover all the unsupported commands automatically.
- MetricMike 4y agoThat'd be a great addition! Historically, the list of architectures that public github action runners make available has been quite limited. Having an alpine runner to surface unsupported commands would be a huge win. That being said, it's very useful as a plugin dev to have this test suite while working on a WSL2/Ubuntu so that I don't need to run a full CI build every time
- nvllsvm 4y agoAlpine uses busybox for its shell and core utils. While closer to pure POSIX than bash or GNU, it has support for a few non-POSIX features (the shell supports the source command and brace expansion, and iirc some of the utils support non-standard flags). It would be better to ensure POSIX shell script compliance by running the scripts with dash shell instead.
- Game_Ender 4y agoIt's interesting they banned the "echo" command but then use it in the tests [0]. 0 - https://github.com/asdf-vm/asdf/blob/master/test/banned_commands.bats#L76 https://github.com/asdf-vm/asdf/blob/master/test/banned_comm...
- qbasic_forever 4y agoBanned is a bad term, these commands are non-portable or unpredictable and therefore not allowed in asdf scripts. Tests are totally different and might be constrained to run on specific platforms where you can and should use all the platform features to better run tests.
- nequo 4y agoThis is a valuable effort for portability. I had no idea `source` was not POSIX compliant but `.` was, or what flags `grep` doesn’t support on macOS. But it is ironic that the script uses `echo` to show a message that `printf` is preferred to `echo`. I guess what is meant is that `printf` is preferred to `echo -[en]`.
- remram 4y agoecho is fine when its argument is not a variable.
- hvdijk 4y agoThe script does echo variables: echo "banned command $cmd: $output" This is non-portable if there is any possibility that these variables contain backslashes.
- nequo 4y agoTIL: dash$ x="foo\nasd" dash$ echo "$x" foo asd dash$ printf "%s\n" "$x" foo\nasd dash$ zsh% x="foo\nasd" zsh% echo "$x" foo asd zsh% printf "%s\n" "$x" foo\nasd zsh% bash$ x="foo\nasd" bash$ echo "$x" foo\nasd bash$ printf "%s\n" "$x" foo\nasd bash$
- js2 4y agoIf you were as confused as I was where "run" is defined and how "output" gets set, and what the heck the bats extension is: (1) https://github.com/bats-core/bats-core/blob/ca5a2dce94/lib/bats-core/test_functions.bash#L182 https://github.com/bats-core/bats-core/blob/ca5a2dce94/lib/b... (2) https://github.com/bats-core/bats-core/blob/ca5a2dce94/lib/bats-core/test_functions.bash#L246 https://github.com/bats-core/bats-core/blob/ca5a2dce94/lib/b... (3) bash automatic testing system.
- rbongers 4y agoCheck out also shellcheck. It's been an invaluable tool keeping my scripts portable.
- heynowheynow 4y agoWhere does asdf hide bats? I don't see the source of it. Austin maybe?
- nvllsvm 4y agoI've spent a lot of time writing portable shell scripts which needed to run on Arch Linux (GNU coreutils), Alpine Linux (busybox), and MacOS (whatever their defaults are). Even used shellcheck to lint and ran all scripts with dash shell to validate POSIX-compliance. Now? I just pick a minimum version of Python and limit myself to the standard library (Python package management still sucks) and occasional subprocesses (ex. preferring to invoke the zstd cli vs installing the Python package). This tends to be more verbose than shell scripting, but also much clearer - especially when compared to using single-letter flag arguments for options I seldom use. I also don't generally trust those I share my scripts with to have a deep enough understanding of shell scripting to ensure portability and safety (argument parsing, quoting, and iterating over paths).
- SOLAR_FIELDS 4y agoI also find myself reaching for Python if it’s more than a terse, readable 1-2 line script. A colleague of mine said it pretty well - if your script is doing even minutely complex with jq, it’s probably time to reach for Python.