Skip to content

Commit ea192a3

Browse files
arthurbdinizsamueloph
authored andcommitted
Add lint to project and fix warnings
Signed-off-by: Arthur Diniz <[email protected]>
1 parent 78ac479 commit ea192a3

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ script:
113113
./tests/tests.sh
114114
```
115115

116+
# Lint
117+
118+
To lint the shell scripts, you need to install `shellcheck` and `checkbashisms`. Those tools will check the scripts for issues and ensure they follow best practices.
119+
120+
- On Debian-like systems: `apt install shellcheck devscripts`
121+
- On Fedora-like systems: `dnf install shellcheck devscripts`
122+
123+
After installation, you can run `shellcheck` and `checkbashisms` by executing the following commands:
124+
125+
```sh
126+
shellcheck wcurl ./tests/*
127+
128+
checkbashisms wcurl ./tests/*
129+
```
130+
116131
# Authors
117132

118133
Samuel Henrique &lt;[[email protected]](mailto:[email protected])&gt;

tests/tests.sh

+13-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#
2727
# SPDX-License-Identifier: curl
2828

29-
readonly ROOTDIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
29+
ROOTDIR=$(CDPATH=$(cd -- "$(dirname -- "$0")/.." && pwd))
30+
readonly ROOTDIR
3031
export PATH="${ROOTDIR}:${PATH}"
3132

3233
readonly WCURL_CMD="wcurl --dry-run "
@@ -67,8 +68,9 @@ testParallelIfMoreThanOneUrl()
6768
{
6869
# TODO: This test is wrong for curl 7.65 or older, since --parallel was only introduced in 7.66.
6970
# We should check curl's version and skip this test instead.
70-
urls='example.com/1 example.com/2'
71-
ret=$(${WCURL_CMD} ${urls})
71+
url_1='example.com/1'
72+
url_2='example.com/2'
73+
ret=$(${WCURL_CMD} ${url_1} ${url_2})
7274
assertContains "Verify whether 'wcurl' uses '--parallel' if more than one url is provided" "${ret}" '--parallel'
7375
}
7476

@@ -82,24 +84,26 @@ testEncodingWhitespace()
8284
testDoubleDash()
8385
{
8486
params='example.com --curl-options=abc'
85-
ret=$(${WCURL_CMD} -- ${params})
87+
ret=$(${WCURL_CMD} -- "${params}")
8688
assertTrue "Verify whether 'wcurl' accepts '--' without erroring" "$?"
8789
assertContains "Verify whether 'wcurl' considers everywhing after '--' a url" "${ret}" '--curl-options=abc'
8890
}
8991

9092
testCurlOptions()
9193
{
9294
params='example.com --curl-options=--foo --curl-options --bar'
93-
ret=$(${WCURL_CMD} ${params})
95+
ret=$(${WCURL_CMD} "${params}")
9496
assertTrue "Verify 'wcurl' accepts '--curl-options' with and without trailing '='" "$?"
9597
assertContains "Verify 'wcurl' correctly passes through --curl-options=<option>" "${ret}" '--foo'
9698
assertContains "Verify 'wcurl' correctly passes through --curl-options <option>" "${ret}" '--bar'
9799
}
98100

99101
testNextAmount()
100102
{
101-
urls='example.com/1 example.com/2 example.com3'
102-
ret=$(${WCURL_CMD} ${urls})
103+
url_1='example.com/1'
104+
url_2='example.com/2'
105+
url_3='example.com3'
106+
ret=$(${WCURL_CMD} ${url_1} ${url_2} ${url_3})
103107
next_count=$(printf '%s' "${ret}" | grep -c -- --next)
104108
assertEquals "Verify whether 'wcurl' includes '--next' for every url besides the first" "${next_count}" "2"
105109
}
@@ -168,7 +172,7 @@ testUrlDecodingDisabled()
168172
testUrlDecodingWhitespacesQueryString()
169173
{
170174
url='example.com/filename%20with%20spaces?query=string'
171-
ret=$(${WCURL_CMD} ${url} 2>&1)
175+
ret=$(${WCURL_CMD} "${url}" 2>&1)
172176
assertContains "Verify whether 'wcurl' successfully decodes percent-encoded whitespaces in URLs with query strings" "${ret}" 'filename with spaces'
173177
}
174178

@@ -217,4 +221,5 @@ testUrlDecodingNonLatinLanguages()
217221
## - Options are the same for all URLs (except --next)
218222
## - URLs beginning with '-' (with and without using '--')
219223

224+
# shellcheck disable=SC1091
220225
. shunit2

0 commit comments

Comments
 (0)