Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shellcheck to project and fix warnings #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ script:
./tests/tests.sh
```

# Running shellcheck

To lint the shell scripts, you need to install `shellcheck`. This tool will check the scripts for issues and ensure they follow best practices.

- On Debian-like systems: `apt-get install shellcheck`
- On Fedora-like systems: `dnf install shellcheck`

After installation, you can run `shellcheck` by executing the following command:

```sh
shellcheck wcurl ./tests/*
```

# Authors

Samuel Henrique <[[email protected]](mailto:[email protected])>
Expand Down
21 changes: 13 additions & 8 deletions tests/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#
# SPDX-License-Identifier: curl

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

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

Expand All @@ -82,24 +84,26 @@ testEncodingWhitespace()
testDoubleDash()
{
params='example.com --curl-options=abc'
ret=$(${WCURL_CMD} -- ${params})
ret=$(${WCURL_CMD} -- "${params}")
assertTrue "Verify whether 'wcurl' accepts '--' without erroring" "$?"
assertContains "Verify whether 'wcurl' considers everywhing after '--' a url" "${ret}" '--curl-options=abc'
}

testCurlOptions()
{
params='example.com --curl-options=--foo --curl-options --bar'
ret=$(${WCURL_CMD} ${params})
ret=$(${WCURL_CMD} "${params}")
assertTrue "Verify 'wcurl' accepts '--curl-options' with and without trailing '='" "$?"
assertContains "Verify 'wcurl' correctly passes through --curl-options=<option>" "${ret}" '--foo'
assertContains "Verify 'wcurl' correctly passes through --curl-options <option>" "${ret}" '--bar'
}

testNextAmount()
{
urls='example.com/1 example.com/2 example.com3'
ret=$(${WCURL_CMD} ${urls})
url_1='example.com/1'
url_2='example.com/2'
url_3='example.com3'
ret=$(${WCURL_CMD} ${url_1} ${url_2} ${url_3})
next_count=$(printf '%s' "${ret}" | grep -c -- --next)
assertEquals "Verify whether 'wcurl' includes '--next' for every url besides the first" "${next_count}" "2"
}
Expand Down Expand Up @@ -152,7 +156,7 @@ testUrlDecodingDisabled()
testUrlDecodingWhitespacesQueryString()
{
url='example.com/filename%20with%20spaces?query=string'
ret=$(${WCURL_CMD} ${url} 2>&1)
ret=$(${WCURL_CMD} "${url}" 2>&1)
assertContains "Verify whether 'wcurl' successfully decodes percent-encoded whitespaces in URLs with query strings" "${ret}" 'filename with spaces'
}

Expand Down Expand Up @@ -201,4 +205,5 @@ testUrlDecodingNonLatinLanguages()
## - Options are the same for all URLs (except --next)
## - URLs beginning with '-' (with and without using '--')

# shellcheck disable=SC1091
. shunit2
Loading