https://github.com/asdf-vm/asdf/blob/master/test/banned_commands.bats Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + By Plan + Enterprise + Teams + Compare all + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} asdf-vm / asdf Public * Notifications * Fork 616 * Star 15.9k * Code * Issues 115 * Pull requests 23 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights Permalink master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create asdf/test/banned_commands.bats Go to file * Go to file T * Go to line L * * Copy path * Copy permalink This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. @jsoref jsoref chore: Fix spelling (#1289) ... Latest commit eaf2215 Jul 5, 2022 History chore: Fix spelling 8 contributors Users who have contributed to this file @Stratus3D @jthegedus @vic @maxnordlund @elijahr @danhper @threkk @jsoref 99 lines (86 sloc) 3.12 KB Raw Blame Edit this file E Open in GitHub Desktop * Open with Desktop * View raw * * View blame This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters #!/usr/bin/env bats load test_helpers banned_commands=( # Process substitution isn't POSIX compliant and cause trouble "<(" # Command isn't included in the Ubuntu packages asdf depends on. Also not # defined in POSIX column # echo isn't consistent across operating systems, and sometimes output can # be confused with echo flags. printf does everything echo does and more. echo # It's best to avoid eval as it makes it easier to accidentally execute # arbitrary strings eval # realpath not available by default on OSX. realpath # readlink on OSX behaves differently from readlink on other Unix systems readlink # source isn't POSIX compliant. . behaves the same and is POSIX compliant # Except in fish, where . is deprecated, and will be removed in the future. source ) banned_commands_regex=( # grep -y does not work on alpine and should be "grep -i" either way "grep.* -y" # grep -P is not a valid option in OSX. "grep.* -P" # Ban grep long commands as they do not work on alpine "grep[^|]+--\w{2,}" # sort --sort-version isn't supported everywhere "sort.*-V" "sort.*--sort-versions" # ls often gets used when we want to glob for files that match a pattern # or when we want to find all files/directories that match a pattern or are # found in a certain location. Using shell globs is preferred over ls, and # find is better at locating files that are in a certain location or that # match certain filename patterns. # https://github-wiki-see.page/m/koalaman/shellcheck/wiki/SC2012 '\bls ' # Ban recursive asdf calls as they are inefficient and may introduce bugs. # If you find yourself needing to invoke an `asdf` command from within # asdf code, please source the appropriate file and invoke the # corresponding function. '\basdf ' ) setup() { setup_asdf_dir } teardown() { clean_asdf_dir } @test "banned commands are not found in source code" { # Assert command is not used in the lib and bin dirs # or expect an explicit comment at end of line, allowing it. # Also ignore matches that are contained in comments or a string or # followed by an underscore (indicating it's a variable and not a # command). for cmd in "${banned_commands[@]}"; do run bash -c "grep -nHR --include \*.bash --include \*.sh '$cmd' asdf.* lib bin\ | grep -v '#.*$cmd'\ | grep -v '\".*$cmd.*\"' \ | grep -v '${cmd}_'\ | grep -v '# asdf_allow: $cmd'" # Only print output if we've found a banned command #if [ "$status" -ne 1 ]; then if [ "" != "$output" ]; then echo "banned command $cmd: $output" fi [ "$status" -eq 1 ] [ "" == "$output" ] done for cmd in "${banned_commands_regex[@]}"; do run bash -c "grep -nHRE --include \*.bash --include \*.sh '$cmd' asdf.* lib bin\ | grep -v '#.*$cmd'\ | grep -v '\".*$cmd.*\"' \ | grep -v '${cmd}_'\ | grep -v '# asdf_allow: $cmd'" # Only print output if we've found a banned command #if [ "$status" -ne 1 ]; then if [ "" != "$output" ]; then echo "banned command $cmd: $output" fi [ "$status" -eq 1 ] [ "" == "$output" ] done } * Copy lines * Copy permalink * View git blame * Reference in new issue [ ] Go Footer (c) 2022 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.