Skip to content

Commit 9bd205f

Browse files
author
Ira Abramov
committed
Merge branch 'master' into ira/pre-commit-cleanup
* master: linting the bats linting the bats lint cleanup for shfmt test: add new lib files to `setup_libs()` test_helper: make lib loading default tests: add to `clean_files.txt` test/install: `shellcheck` test/plugin: `shellcheck` test/completion: `shellcheck` test/bash_it: `shellcheck` test/theme: `shellcheck` test/lib: `shellcheck` BATS: require `shellcheck` on test files
2 parents 3811cee + 5fd2afe commit 9bd205f

27 files changed

+646
-595
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.sh text eol=lf
22
*.bash text eol=lf
3+
*.bats text eol=lf
34

45
# Docs allow trailing whitespaces
56
*.md whitespace=-blank-at-eol

.pre-commit-config.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ repos:
1919
hooks:
2020
- id: git-check # Configure in .gitattributes
2121
- id: shellcheck
22-
exclude: ".bats$"
2322
- id: shfmt
2423
exclude: ".bats$"
2524
- repo: https://github.com/Lucas-C/pre-commit-hooks
@@ -38,10 +37,9 @@ repos:
3837
types: [file]
3938
- id: dot-bash
4039
name: Check .bash files against bash-it requirements
41-
exclude: "test/test_helper.bash"
4240
entry: ./hooks/dot-bash.sh
4341
language: system
44-
files: "\\.bash$"
42+
files: "\\.ba[ts][sh]$"
4543
types: [file]
4644
- id: clean-files-txt
4745
name: Check that clean_files.txt is sorted alphabetically.

clean_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ docs/
2121
hooks/
2222
lib/
2323
scripts/
24+
test/
2425

2526
# root files
2627
#

hooks/dot-bash.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ for file in "$@"; do
1212
# Confirm expected schellcheck header
1313
#
1414
LINE1="$(head -n 1 "${file}")"
15-
if [[ "${LINE1}" != "# shellcheck shell=bash" ]]; then
15+
SCSH="${file##*.}"
16+
if [[ "${LINE1}" != "# shellcheck shell=${SCSH}" ]]; then
1617
echo "Bash include file \`${file}\` has bad/missing shellcheck header"
1718
exit_code=1
1819
fi

plugins/available/browser.plugin.bash

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ function wmate() {
3333
if [ -t 0 ]; then
3434
if [ -n "$1" ]; then
3535
wget -qO- "$1" | /usr/bin/mate
36-
3736
TIDY=$(
3837
/usr/bin/osascript << EOT
3938
tell application "TextMate"

test/bash_it/bash_it.bats

Lines changed: 111 additions & 147 deletions
Large diffs are not rendered by default.

test/completion/aliases.completion.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ function local_setup_file() {
2626
alias rm='rm -v'
2727
run load "${BASH_IT?}/completion/available/aliases.completion.bash"
2828

29-
refute_output
29+
assert_output ""
3030
}

test/completion/bash-it.completion.bats

100755100644
Lines changed: 82 additions & 78 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/usr/bin/env bash
1+
# shellcheck shell=bash
22

33
alias test_alias="a"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/usr/bin/env bash
1+
# shellcheck shell=bash
22

33
alias test_alias="b"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/usr/bin/env bash
1+
# shellcheck shell=bash
22

33
alias test_alias="c"

test/install/install.bats

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
44

55
function local_setup() {
6-
export HOME="$BATS_TEST_TMPDIR"
6+
export HOME="${BATS_TEST_TMPDIR?}"
77
}
88

99
function local_setup_file() {
@@ -20,7 +20,7 @@ function local_setup_file() {
2020
}
2121

2222
@test "install: verify that the install script exists" {
23-
assert_file_exist "$BASH_IT/install.sh"
23+
assert_file_exist "${BASH_IT?}/install.sh"
2424
}
2525

2626
@test "install: run the install script silently" {
@@ -30,26 +30,27 @@ function local_setup_file() {
3030

3131
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
3232

33-
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
34-
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
35-
assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash"
36-
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
37-
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
33+
assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash"
34+
assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash"
35+
assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash"
36+
assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash"
37+
assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash"
3838
}
3939

4040
@test "install: verify that a backup file is created" {
41-
cd "$BASH_IT"
41+
local md5_orig md5_bak
42+
cd "${BASH_IT?}"
4243

4344
touch "$HOME/$BASH_IT_CONFIG_FILE"
4445
echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE"
45-
local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
46+
md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
4647

4748
./install.sh --silent
4849

4950
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
5051
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
5152

52-
local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
53+
md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
5354

5455
assert_equal "$md5_orig" "$md5_bak"
5556
}

test/install/uninstall.bats

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
44

55
function local_setup() {
6-
export HOME="$BATS_TEST_TMPDIR"
6+
export HOME="${BATS_TEST_TMPDIR?}"
77
}
88

99
function local_setup_file() {
@@ -20,15 +20,16 @@ function local_setup_file() {
2020
}
2121

2222
@test "uninstall: verify that the uninstall script exists" {
23-
assert_file_exist "$BASH_IT/uninstall.sh"
23+
assert_file_exist "${BASH_IT?}/uninstall.sh"
2424
}
2525

2626
@test "uninstall: run the uninstall script with an existing backup file" {
27-
cd "$BASH_IT"
27+
local md5_bak md5_conf
28+
cd "${BASH_IT?}"
2829

2930
echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak"
3031
echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
31-
local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
32+
md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
3233

3334
run ./uninstall.sh
3435
assert_success
@@ -37,16 +38,17 @@ function local_setup_file() {
3738
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
3839
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
3940

40-
local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
41+
md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
4142

4243
assert_equal "$md5_bak" "$md5_conf"
4344
}
4445

4546
@test "uninstall: run the uninstall script without an existing backup file" {
46-
cd "$BASH_IT"
47+
local md5_orig md5_uninstall
48+
cd "${BASH_IT?}"
4749

4850
echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
49-
local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
51+
md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
5052

5153
run ./uninstall.sh
5254
assert_success
@@ -55,7 +57,7 @@ function local_setup_file() {
5557
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
5658
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE"
5759

58-
local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
60+
md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
5961

6062
assert_equal "$md5_orig" "$md5_uninstall"
6163
}

0 commit comments

Comments
 (0)