Add shellcheck to bats files#2549
Merged
mrunalp merged 13 commits intoopencontainers:masterfrom Aug 18, 2020
Merged
Conversation
303f1d5 to
c1e8fa1
Compare
AkihiroSuda
reviewed
Aug 10, 2020
c1e8fa1 to
c17d539
Compare
The ending EOF should be - all by itself (i.e. no extra characters on the same line); - with no whitespace before it. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
It's not a regex but a substring, so use a substring match.
Fixes the following warning by shellcheck:
> In mounts.bats line 20:
> [[ "${lines[0]}" =~ '/tmp/bind/config.json' ]]
> ^---------------------^ SC2076: Don't quote right-hand side of =~, it'll match literally rather than as a regex.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1. cd is useless as all the paths are absolute 2. run is redundant, does not make sense to use it 3. use mkdir -p to save a line of code This also eliminates shellcheck warnings like this one: > In spec.bats line 8: > cd "$INTEGRATION_ROOT" > ^--------------------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Fixes the following warning: > In cgroups.bats line 58: > if [ "$KERNEL_MAJOR" -lt 4 ] || [ "$KERNEL_MAJOR" -eq 4 -a "$KERNEL_MINOR" -le 5 ]; then > ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Fixes the following warning:
> In update.bats line 422:
> local root_period=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_period_us")
> ^---------^ SC2155: Declare and assign separately to avoid masking return values.
>
>
> In update.bats line 423:
> local root_runtime=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_runtime_us")
> ^----------^ SC2155: Declare and assign separately to avoid masking return values.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This fixes the following warning, and implements a suggestion:
> In update.bats line 426:
> IFS='/' read -r -a dirs <<< $(echo ${CGROUP_CPU} | sed -e s@^${CGROUP_CPU_BASE_PATH}/@@)
> ^-- SC2046: Quote this to prevent word splitting.
> ^-- SC2001: See if you can use ${variable//search/replace} instead.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Fix all warnings like this one: > In checkpoint.bats line 197: > cat ./work-dir/restore.log | grep -B 5 Error || true > ^--------------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Those are pretty simple to allow shellcheck to fix these, so this commit is courtesy of > shellcheck -i SC2086 -i SC2006 -f diff *.bats > fix.diff > patch -p1 < fix.diff repeated 3 times ;) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Fix or ignore warnings like this one: > In cgroups.bats line 107: > if [ $(id -u) = "0" ]; then > ^------^ SC2046: Quote this to prevent word splitting. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Ignore warnings like this: > In checkpoint.bats line 169: > PIDS_TO_KILL=($cpt_pid) > ^------^ SC2206: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a. Since in all the cases we deal with either pids or fds, and they don't have spaces. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Ignore the shellcheck warnings like this one: > In tty.bats line 32: > update_config '(.. | select(.[]? == "sh")) += ["-c", "stat -c %u:%g $(tty) | tr : \\\\n"]' > ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that. While at it, fix some minor whitespace issues in tty.bats. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Currently all the shellcheck warnings are fixed, and we'd like it to stay thay way. So, add shellcheck call to validate target in Makefile, which is run on Travis CI. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
c17d539 to
d34f1c8
Compare
AkihiroSuda
approved these changes
Aug 17, 2020
mrunalp
approved these changes
Aug 18, 2020
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR
TODO (not in this PR):
This currently includes #2548; I'll rebase once it's merged.rebased