From cd878c2cb551572f614b4feebeb0de01a3b1daf9 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Sun, 31 May 2020 19:50:36 -0600 Subject: [PATCH 01/15] added bats --- .gitmodules | 9 +++++++++ bashtop | 4 ++++ test/bats | 8 ++++++++ test/libs/bats | 1 + test/libs/bats-assert | 1 + test/libs/bats-support | 1 + 6 files changed, 24 insertions(+) create mode 100644 .gitmodules create mode 100644 test/bats create mode 160000 test/libs/bats create mode 160000 test/libs/bats-assert create mode 160000 test/libs/bats-support diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..dedb624 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "test/libs/bats"] + path = test/libs/bats + url = https://github.com/sstephenson/bats +[submodule "test/libs/bats-assert"] + path = test/libs/bats-assert + url = https://github.com/ztombol/bats-assert +[submodule "test/libs/bats-support"] + path = test/libs/bats-support + url = https://github.com/ztombol/bats-support diff --git a/bashtop b/bashtop index ee4c6fe..2f07e3c 100755 --- a/bashtop +++ b/bashtop @@ -4822,6 +4822,10 @@ else exec 2>/dev/null fi + +#* if we have been sourced by another shell, quit. Allows sourcing only function definition. +[[ "${#BASH_SOURCE[@]}" -gt 1 ]] && { return 0; } + #* Call init function init_ diff --git a/test/bats b/test/bats new file mode 100644 index 0000000..fbb4b89 --- /dev/null +++ b/test/bats @@ -0,0 +1,8 @@ +#!/usr/bin/env bats + +source bashtop + +@test "im a toy" { + result=$(echo hello) + [ "$result" = "hello" ] +} diff --git a/test/libs/bats b/test/libs/bats new file mode 160000 index 0000000..0360811 --- /dev/null +++ b/test/libs/bats @@ -0,0 +1 @@ +Subproject commit 03608115df2071fff4eaaff1605768c275e5f81f diff --git a/test/libs/bats-assert b/test/libs/bats-assert new file mode 160000 index 0000000..9f88b42 --- /dev/null +++ b/test/libs/bats-assert @@ -0,0 +1 @@ +Subproject commit 9f88b4207da750093baabc4e3f41bf68f0dd3630 diff --git a/test/libs/bats-support b/test/libs/bats-support new file mode 160000 index 0000000..004e707 --- /dev/null +++ b/test/libs/bats-support @@ -0,0 +1 @@ +Subproject commit 004e707638eedd62e0481e8cdc9223ad471f12ee From 8f4a00f7271a1a10de2380b571cc68329802cfa2 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Sun, 31 May 2020 22:31:09 -0600 Subject: [PATCH 02/15] adding tests and travis yml --- .travis.yml | 10 ++++++++++ test.sh | 3 +++ test/basic_test.bats | 17 +++++++++++++++++ test/bats | 8 -------- test/test_helper.bash | 1 + 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 .travis.yml create mode 100755 test.sh create mode 100644 test/basic_test.bats delete mode 100644 test/bats create mode 100644 test/test_helper.bash diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..07618fa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +udo: false +language: bash +addons: + apt: + sources: + - sourceline: 'ppa:duggan/bats' + packages: + - bats + - bc +script: bats ./test/*.bats \ No newline at end of file diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..6343258 --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./test/libs/bats/bin/bats test/*.bats \ No newline at end of file diff --git a/test/basic_test.bats b/test/basic_test.bats new file mode 100644 index 0000000..e6b95a4 --- /dev/null +++ b/test/basic_test.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +load 'libs/bats-support/load' +load 'libs/bats-assert/load' + +load test_helper + +@test "sourcing works, by checking if $system is set" { + run echo $system + refute_output "" +} + +@test "#get_themes populates themes" { + get_themes + assert_success + assert [ ${#themes[@]} -gt 0 ] +} \ No newline at end of file diff --git a/test/bats b/test/bats deleted file mode 100644 index fbb4b89..0000000 --- a/test/bats +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bats - -source bashtop - -@test "im a toy" { - result=$(echo hello) - [ "$result" = "hello" ] -} diff --git a/test/test_helper.bash b/test/test_helper.bash new file mode 100644 index 0000000..f0d1c88 --- /dev/null +++ b/test/test_helper.bash @@ -0,0 +1 @@ +source bashtop \ No newline at end of file From 0929c24f8ff9e009d44e468a8385cf5fb0a45ea8 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 10:44:17 -0600 Subject: [PATCH 03/15] use test script --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 07618fa..3dd6bcd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ addons: packages: - bats - bc -script: bats ./test/*.bats \ No newline at end of file +script: ./test.sh \ No newline at end of file From eadc5435e6994c9e925c0f344e8c2d6d65e5704e Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 10:48:36 -0600 Subject: [PATCH 04/15] triggering travis build --- test/basic_test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basic_test.bats b/test/basic_test.bats index e6b95a4..c00e185 100644 --- a/test/basic_test.bats +++ b/test/basic_test.bats @@ -5,7 +5,7 @@ load 'libs/bats-assert/load' load test_helper -@test "sourcing works, by checking if $system is set" { +@test "Sourcing works, by checking if $system is set" { run echo $system refute_output "" } From a537c1ea74a685422bf15a169b84d8d3b515da30 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 10:54:28 -0600 Subject: [PATCH 05/15] pull bash from apt --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3dd6bcd..55eade3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ -udo: false +sudo: false language: bash addons: apt: sources: - - sourceline: 'ppa:duggan/bats' + - sourceline: 'ppa:duggan/bats' packages: - - bats - - bc + - bash + - bats + - bc script: ./test.sh \ No newline at end of file From fed9ca8624f83c6cbe05141b0286965930de20f9 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 10:56:56 -0600 Subject: [PATCH 06/15] pull docker bash instead --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 55eade3..05a00d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,14 @@ sudo: false language: bash +env: + - BASH=5.0.3 addons: apt: sources: - sourceline: 'ppa:duggan/bats' packages: - - bash - bats - bc +before_script: + - docker pull bash:$BASH script: ./test.sh \ No newline at end of file From c84c770047fb81eebb667a4f3f0bc032b82a8735 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:04:51 -0600 Subject: [PATCH 07/15] move to newer ubuntu container base --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 05a00d4..deb4a91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ sudo: false language: bash +dist: bionic env: - BASH=5.0.3 addons: @@ -9,6 +10,4 @@ addons: packages: - bats - bc -before_script: - - docker pull bash:$BASH script: ./test.sh \ No newline at end of file From 0e2243f7bb4afc7eb33c4e75f07897502359825b Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:05:04 -0600 Subject: [PATCH 08/15] rm --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index deb4a91..1b2d8cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ sudo: false language: bash dist: bionic -env: - - BASH=5.0.3 addons: apt: sources: From e58e56446d8f9ded68da6f31253a126de47cdb75 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:20:15 -0600 Subject: [PATCH 09/15] moving to python container --- .travis.yml | 7 ++++++- requirements.txt | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/.travis.yml b/.travis.yml index 1b2d8cd..bf35fb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ sudo: false -language: bash +language: python +python: + - "3.6" dist: bionic addons: apt: @@ -8,4 +10,7 @@ addons: packages: - bats - bc +# command to install dependencies +install: + - pip install -r requirements.txt script: ./test.sh \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a87aaef --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +psutil==5.7.0 \ No newline at end of file From 4f19d627d67f04c709905e24e9590c559cd1af4d Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:28:25 -0600 Subject: [PATCH 10/15] test test failure for travis --- test/basic_test.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/basic_test.bats b/test/basic_test.bats index c00e185..9a263b9 100644 --- a/test/basic_test.bats +++ b/test/basic_test.bats @@ -5,9 +5,9 @@ load 'libs/bats-assert/load' load test_helper -@test "Sourcing works, by checking if $system is set" { +@test "Sourcing works, by checking if \$system is set" { run echo $system - refute_output "" + refute_output "MacOS" } @test "#get_themes populates themes" { From 93d5ad4e6b1869e5cb34b0aacd2539fcda4b692f Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:30:53 -0600 Subject: [PATCH 11/15] but do it correctly --- test/basic_test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basic_test.bats b/test/basic_test.bats index 9a263b9..5ea4006 100644 --- a/test/basic_test.bats +++ b/test/basic_test.bats @@ -7,7 +7,7 @@ load test_helper @test "Sourcing works, by checking if \$system is set" { run echo $system - refute_output "MacOS" + assert_output "" } @test "#get_themes populates themes" { From 9c2a25f248a240742b354760531d9942c7a7398f Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:33:05 -0600 Subject: [PATCH 12/15] back to good state --- test/basic_test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basic_test.bats b/test/basic_test.bats index 5ea4006..2b157d9 100644 --- a/test/basic_test.bats +++ b/test/basic_test.bats @@ -7,7 +7,7 @@ load test_helper @test "Sourcing works, by checking if \$system is set" { run echo $system - assert_output "" + refute_output "" } @test "#get_themes populates themes" { From 3a35afdb4f1b49d1e635c5275c18c1ebbb7b35a3 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:37:44 -0600 Subject: [PATCH 13/15] dont install bats, use one from submodules --- .travis.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index bf35fb2..3912c12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,6 @@ language: python python: - "3.6" dist: bionic -addons: - apt: - sources: - - sourceline: 'ppa:duggan/bats' - packages: - - bats - - bc -# command to install dependencies install: - pip install -r requirements.txt script: ./test.sh \ No newline at end of file From b658b8cf232c1c04830bcd6a3dd6a40486da8fb2 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:40:43 -0600 Subject: [PATCH 14/15] dont use deprecated sudo flag, specify os --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3912c12..e762dde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ -sudo: false +# travis does not offer python container for OSX or Windows, not sure if we can get automated testing? +os: linux language: python python: - "3.6" From a7acb014689ae9007dfb2e046c47cfa0232d2205 Mon Sep 17 00:00:00 2001 From: Maciek Swiech Date: Mon, 1 Jun 2020 11:45:11 -0600 Subject: [PATCH 15/15] newline at EOF --- .travis.yml | 2 +- requirements.txt | 2 +- test.sh | 2 +- test/basic_test.bats | 2 +- test/test_helper.bash | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e762dde..b589ccf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ python: dist: bionic install: - pip install -r requirements.txt -script: ./test.sh \ No newline at end of file +script: ./test.sh diff --git a/requirements.txt b/requirements.txt index a87aaef..24156d6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -psutil==5.7.0 \ No newline at end of file +psutil==5.7.0 diff --git a/test.sh b/test.sh index 6343258..958110a 100755 --- a/test.sh +++ b/test.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -./test/libs/bats/bin/bats test/*.bats \ No newline at end of file +./test/libs/bats/bin/bats test/*.bats diff --git a/test/basic_test.bats b/test/basic_test.bats index 2b157d9..e159b6f 100644 --- a/test/basic_test.bats +++ b/test/basic_test.bats @@ -14,4 +14,4 @@ load test_helper get_themes assert_success assert [ ${#themes[@]} -gt 0 ] -} \ No newline at end of file +} diff --git a/test/test_helper.bash b/test/test_helper.bash index f0d1c88..d173159 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1 +1 @@ -source bashtop \ No newline at end of file +source bashtop