Skip to content

Commit 89141f1

Browse files
authored
Merge pull request #14082 from fzakaria/fzakaria/shellcheck-multiple
shellcheck: multiple file fixes
2 parents e3d62f3 + 1619409 commit 89141f1

File tree

9 files changed

+165
-161
lines changed

9 files changed

+165
-161
lines changed

maintainers/flake-module.nix

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,6 @@
107107
excludes = [
108108
# We haven't linted these files yet
109109
''^tests/functional/dump-db\.sh$''
110-
''^tests/functional/dyn-drv/eval-outputOf\.sh$''
111-
''^tests/functional/dyn-drv/old-daemon-error-hack\.sh$''
112-
''^tests/functional/dyn-drv/recursive-mod-json\.sh$''
113-
''^tests/functional/eval-store\.sh$''
114-
''^tests/functional/export-graph\.sh$''
115-
''^tests/functional/export\.sh$''
116-
''^tests/functional/extra-sandbox-profile\.sh$''
117-
''^tests/functional/fetchClosure\.sh$''
118-
''^tests/functional/fetchGit\.sh$''
119-
''^tests/functional/fetchGitRefs\.sh$''
120110
''^tests/functional/fetchGitSubmodules\.sh$''
121111
''^tests/functional/fetchGitVerification\.sh$''
122112
''^tests/functional/fetchMercurial\.sh$''

tests/functional/dyn-drv/old-daemon-error-hack.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck shell=bash
12
# Purposely bypassing our usual common for this subgroup
23
source ../common.sh
34

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck shell=bash
12
source common.sh
23

34
# FIXME
@@ -10,18 +11,18 @@ restartDaemon
1011

1112
clearStore
1213

13-
rm -f $TEST_ROOT/result
14+
rm -f "$TEST_ROOT"/result
1415

15-
EXTRA_PATH=$(dirname $(type -p nix)):$(dirname $(type -p jq))
16+
EXTRA_PATH=$(dirname "$(type -p nix)"):$(dirname "$(type -p jq)")
1617
export EXTRA_PATH
1718

1819
# Will produce a drv
1920
metaDrv=$(nix-instantiate ./recursive-mod-json.nix)
2021

2122
# computed "dynamic" derivation
22-
drv=$(nix-store -r $metaDrv)
23+
drv=$(nix-store -r "$metaDrv")
2324

2425
# build that dyn drv
25-
res=$(nix-store -r $drv)
26+
res=$(nix-store -r "$drv")
2627

27-
grep 'I am alive!' $res/hello
28+
grep 'I am alive!' "$res"/hello

tests/functional/eval-store.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ TODO_NixOS
66

77
# Using `--eval-store` with the daemon will eventually copy everything
88
# to the build store, invalidating most of the tests here
9+
# shellcheck disable=SC1111
910
needLocalStore "“--eval-store” doesn't achieve much with the daemon"
1011

1112
eval_store=$TEST_ROOT/eval-store
@@ -15,43 +16,43 @@ rm -rf "$eval_store"
1516

1617
nix build -f dependencies.nix --eval-store "$eval_store" -o "$TEST_ROOT/result"
1718
[[ -e $TEST_ROOT/result/foobar ]]
18-
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
19+
if [[ -z "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
1920
# Resolved CA derivations are written to store for building
2021
#
2122
# TODO when we something more systematic
2223
# (https://github.com/NixOS/nix/issues/5025) that distinguishes
2324
# between scratch storage for building and the final destination
2425
# store, we'll be able to make this unconditional again -- resolved
2526
# derivations should only appear in the scratch store.
26-
(! ls $NIX_STORE_DIR/*.drv)
27+
(! ls "$NIX_STORE_DIR"/*.drv)
2728
fi
28-
ls $eval_store/nix/store/*.drv
29+
ls "$eval_store"/nix/store/*.drv
2930

3031
clearStore
3132
rm -rf "$eval_store"
3233

3334
nix-instantiate dependencies.nix --eval-store "$eval_store"
34-
(! ls $NIX_STORE_DIR/*.drv)
35-
ls $eval_store/nix/store/*.drv
35+
(! ls "$NIX_STORE_DIR"/*.drv)
36+
ls "$eval_store"/nix/store/*.drv
3637

3738
clearStore
3839
rm -rf "$eval_store"
3940

4041
nix-build dependencies.nix --eval-store "$eval_store" -o "$TEST_ROOT/result"
4142
[[ -e $TEST_ROOT/result/foobar ]]
42-
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
43+
if [[ -z "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
4344
# See above
44-
(! ls $NIX_STORE_DIR/*.drv)
45+
(! ls "$NIX_STORE_DIR"/*.drv)
4546
fi
46-
ls $eval_store/nix/store/*.drv
47+
ls "$eval_store"/nix/store/*.drv
4748

4849
clearStore
4950
rm -rf "$eval_store"
5051

5152
# Confirm that import-from-derivation builds on the build store
5253
[[ $(nix eval --eval-store "$eval_store?require-sigs=false" --impure --raw --file ./ifd.nix) = hi ]]
53-
ls $NIX_STORE_DIR/*dependencies-top/foobar
54-
(! ls $eval_store/nix/store/*dependencies-top/foobar)
54+
ls "$NIX_STORE_DIR"/*dependencies-top/foobar
55+
(! ls "$eval_store"/nix/store/*dependencies-top/foobar)
5556

5657
# Can't write .drv by default
5758
(! nix-instantiate dependencies.nix --eval-store "dummy://")

tests/functional/export-graph.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@ clearStore
88
clearProfiles
99

1010
checkRef() {
11-
nix-store -q --references $TEST_ROOT/result | grepQuiet "$1"'$' || fail "missing reference $1"
11+
nix-store -q --references "$TEST_ROOT"/result | grepQuiet "$1"'$' || fail "missing reference $1"
1212
}
1313

1414
# Test the export of the runtime dependency graph.
1515

16-
outPath=$(nix-build ./export-graph.nix -A 'foo."bar.runtimeGraph"' -o $TEST_ROOT/result)
16+
outPath=$(nix-build ./export-graph.nix -A 'foo."bar.runtimeGraph"' -o "$TEST_ROOT"/result)
1717

18-
test $(nix-store -q --references $TEST_ROOT/result | wc -l) = 3 || fail "bad nr of references"
18+
test "$(nix-store -q --references "$TEST_ROOT"/result | wc -l)" = 3 || fail "bad nr of references"
1919

2020
checkRef input-2
21-
for i in $(cat $outPath); do checkRef $i; done
21+
# shellcheck disable=SC2013
22+
for i in $(cat "$outPath"); do checkRef "$i"; done
2223

2324
# Test the export of the build-time dependency graph.
2425

2526
nix-store --gc # should force rebuild of input-1
2627

27-
outPath=$(nix-build ./export-graph.nix -A 'foo."bar.buildGraph"' -o $TEST_ROOT/result)
28+
outPath=$(nix-build ./export-graph.nix -A 'foo."bar.buildGraph"' -o "$TEST_ROOT"/result)
2829

2930
checkRef input-1
3031
checkRef input-1.drv
3132
checkRef input-2
3233
checkRef input-2.drv
3334

34-
for i in $(cat $outPath); do checkRef $i; done
35+
# shellcheck disable=SC2013
36+
for i in $(cat "$outPath"); do checkRef "$i"; done

tests/functional/export.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,35 @@ clearStore
88

99
outPath=$(nix-build dependencies.nix --no-out-link)
1010

11-
nix-store --export $outPath > $TEST_ROOT/exp
11+
nix-store --export "$outPath" > "$TEST_ROOT"/exp
1212

13-
nix-store --export $(nix-store -qR $outPath) > $TEST_ROOT/exp_all
13+
# shellcheck disable=SC2046
14+
nix-store --export $(nix-store -qR "$outPath") > "$TEST_ROOT"/exp_all
1415

15-
if nix-store --export $outPath >/dev/full ; then
16+
if nix-store --export "$outPath" >/dev/full ; then
1617
echo "exporting to a bad file descriptor should fail"
1718
exit 1
1819
fi
1920

2021

2122
clearStore
2223

23-
if nix-store --import < $TEST_ROOT/exp; then
24+
if nix-store --import < "$TEST_ROOT"/exp; then
2425
echo "importing a non-closure should fail"
2526
exit 1
2627
fi
2728

2829

2930
clearStore
3031

31-
nix-store --import < $TEST_ROOT/exp_all
32+
nix-store --import < "$TEST_ROOT"/exp_all
3233

33-
nix-store --export $(nix-store -qR $outPath) > $TEST_ROOT/exp_all2
34+
# shellcheck disable=SC2046
35+
nix-store --export $(nix-store -qR "$outPath") > "$TEST_ROOT"/exp_all2
3436

3537

3638
clearStore
3739

3840
# Regression test: the derivers in exp_all2 are empty, which shouldn't
3941
# cause a failure.
40-
nix-store --import < $TEST_ROOT/exp_all2
42+
nix-store --import < "$TEST_ROOT"/exp_all2

tests/functional/fetchClosure.sh

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ requireDaemonNewerThan "2.16.0pre20230524"
1717

1818
# Initialize binary cache.
1919
nonCaPath=$(nix build --json --file ./dependencies.nix --no-link | jq -r .[].outputs.out)
20-
caPath=$(nix store make-content-addressed --json $nonCaPath | jq -r '.rewrites | map(.) | .[]')
21-
nix copy --to file://$cacheDir $nonCaPath
20+
caPath=$(nix store make-content-addressed --json "$nonCaPath" | jq -r '.rewrites | map(.) | .[]')
21+
nix copy --to file://"$cacheDir" "$nonCaPath"
2222

2323
# Test basic fetchClosure rewriting from non-CA to CA.
2424
clearStore
2525

26-
[ ! -e $nonCaPath ]
27-
[ ! -e $caPath ]
26+
[ ! -e "$nonCaPath" ]
27+
[ ! -e "$caPath" ]
2828

2929
[[ $(nix eval -v --raw --expr "
3030
builtins.fetchClosure {
3131
fromStore = \"file://$cacheDir\";
3232
fromPath = $nonCaPath;
3333
toPath = $caPath;
3434
}
35-
") = $caPath ]]
35+
") = "$caPath" ]]
3636

37-
[ ! -e $nonCaPath ]
38-
[ -e $caPath ]
37+
[ ! -e "$nonCaPath" ]
38+
[ -e "$caPath" ]
3939

4040
clearStore
4141

@@ -55,7 +55,7 @@ if [[ "$NIX_REMOTE" != "daemon" ]]; then
5555
# TODO: Should the closure be rejected, despite single user mode?
5656
# [ ! -e $nonCaPath ]
5757

58-
[ ! -e $caPath ]
58+
[ ! -e "$caPath" ]
5959

6060
# We can use non-CA paths when we ask explicitly.
6161
[[ $(nix eval --raw --no-require-sigs --expr "
@@ -64,15 +64,15 @@ if [[ "$NIX_REMOTE" != "daemon" ]]; then
6464
fromPath = $nonCaPath;
6565
inputAddressed = true;
6666
}
67-
") = $nonCaPath ]]
67+
") = "$nonCaPath" ]]
6868

69-
[ -e $nonCaPath ]
70-
[ ! -e $caPath ]
69+
[ -e "$nonCaPath" ]
70+
[ ! -e "$caPath" ]
7171

7272

7373
fi
7474

75-
[ ! -e $caPath ]
75+
[ ! -e "$caPath" ]
7676

7777
# 'toPath' set to empty string should fail but print the expected path.
7878
expectStderr 1 nix eval -v --json --expr "
@@ -84,39 +84,41 @@ expectStderr 1 nix eval -v --json --expr "
8484
" | grep "error: rewriting.*$nonCaPath.*yielded.*$caPath"
8585

8686
# If fromPath is CA, then toPath isn't needed.
87-
nix copy --to file://$cacheDir $caPath
87+
nix copy --to file://"$cacheDir" "$caPath"
8888

8989
clearStore
9090

91-
[ ! -e $caPath ]
91+
[ ! -e "$caPath" ]
9292

9393
[[ $(nix eval -v --raw --expr "
9494
builtins.fetchClosure {
9595
fromStore = \"file://$cacheDir\";
9696
fromPath = $caPath;
9797
}
98-
") = $caPath ]]
98+
") = "$caPath" ]]
9999

100-
[ -e $caPath ]
100+
[ -e "$caPath" ]
101101

102102
# Check that URL query parameters aren't allowed.
103103
clearStore
104104
narCache=$TEST_ROOT/nar-cache
105-
rm -rf $narCache
105+
rm -rf "$narCache"
106106
(! nix eval -v --raw --expr "
107107
builtins.fetchClosure {
108108
fromStore = \"file://$cacheDir?local-nar-cache=$narCache\";
109109
fromPath = $caPath;
110110
}
111111
")
112-
(! [ -e $narCache ])
112+
# shellcheck disable=SC2235
113+
(! [ -e "$narCache" ])
113114

114115
# If toPath is specified but wrong, we check it (only) when the path is missing.
115116
clearStore
116117

117-
badPath=$(echo $caPath | sed -e 's!/store/................................-!/store/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-!')
118+
# shellcheck disable=SC2001
119+
badPath=$(echo "$caPath" | sed -e 's!/store/................................-!/store/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-!')
118120

119-
[ ! -e $badPath ]
121+
[ ! -e "$badPath" ]
120122

121123
expectStderr 1 nix eval -v --raw --expr "
122124
builtins.fetchClosure {
@@ -126,19 +128,19 @@ expectStderr 1 nix eval -v --raw --expr "
126128
}
127129
" | grep "error: rewriting.*$nonCaPath.*yielded.*$caPath.*while.*$badPath.*was expected"
128130

129-
[ ! -e $badPath ]
131+
[ ! -e "$badPath" ]
130132

131133
# We only check it when missing, as a performance optimization similar to what we do for fixed output derivations. So if it's already there, we don't check it.
132134
# It would be nice for this to fail, but checking it would be too(?) slow.
133-
[ -e $caPath ]
135+
[ -e "$caPath" ]
134136

135137
[[ $(nix eval -v --raw --expr "
136138
builtins.fetchClosure {
137139
fromStore = \"file://$cacheDir\";
138140
fromPath = $badPath;
139141
toPath = $caPath;
140142
}
141-
") = $caPath ]]
143+
") = "$caPath" ]]
142144

143145

144146
# However, if the output address is unexpected, we can report it

0 commit comments

Comments
 (0)