Skip to content

Commit 2d09390

Browse files
committed
remove non working part from action. add simple tests for now
1 parent b45cfc4 commit 2d09390

File tree

14 files changed

+137
-23
lines changed

14 files changed

+137
-23
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
- name: Run Shellcheck
1414
uses: ludeeus/[email protected]
1515

16-
unit-test-ubuntu:
17-
name: unit-test (ubuntu)
16+
test-ubuntu:
17+
name: test (ubuntu)
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Clone Repo
@@ -23,28 +23,33 @@ jobs:
2323
id: setup-bats
2424
uses: bats-core/[email protected]
2525
- name: Run Unit Tests
26-
run: make test
26+
run: make unit-test
27+
shell: bash
28+
- name: Run Integration Tests
29+
run: make intg-test
2730
shell: bash
2831

29-
unit-test-macos:
30-
name: unit-test (macos)
32+
test-macos:
33+
name: test (macos)
3134
runs-on: macos-latest
3235
steps:
3336
- name: Clone Repo
3437
uses: actions/checkout@v4
3538
- name: Install bats-core
3639
run: brew install bats-core
3740
- name: Run Unit Tests
38-
run: make test
41+
run: make unit-test
3942
shell: bash
40-
41-
42-
intg-test:
43-
name: intg-test
44-
runs-on: ubuntu-latest
45-
steps:
46-
- name: Clone Repo
47-
uses: actions/checkout@v4
48-
- name: Run Integration Tests in Docker
49-
run: make docker-test
43+
- name: Run Integration Tests
44+
run: make intg-test
5045
shell: bash
46+
47+
# intg-test:
48+
# name: intg-test
49+
# runs-on: ubuntu-latest
50+
# steps:
51+
# - name: Clone Repo
52+
# uses: actions/checkout@v4
53+
# - name: Run Integration Tests in Docker
54+
# run: make docker-test
55+
# shell: bash

.hasrc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# make to install/test the project
1+
# required to install/test the project
22
make
33
curl
44
git
5-
# bats for testing
5+
# bats for testing shell script
66
bats
7+
# for running integration tests
8+
# their outputs will be tested
9+
sed
10+
awk
11+
jq
12+
node

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ ifeq ($(PREFIX),)
99
PREFIX := /usr/local
1010
endif
1111

12-
test : has
12+
13+
test: unit-test intg-test
14+
15+
unit-test:
1316
bats tests/unit/unit-tests.bats
1417
bats tests/unit/with-mocks.bats
1518

16-
test-intg : has
17-
bats -t tests/intg/test_all_packages.bats
19+
intg-test:
20+
bats -t tests/intg/intg-tests.bats
1821

1922
has :
2023
# ensure 'has' in repo
@@ -53,9 +56,9 @@ docker-test:
5356

5457
.PHONY: docker-test-%
5558
docker-test-%:
56-
docker build -t test-image:$* -f tests/containers/$*.Dockerfile .
59+
docker build -t test-image:$* -f tests/to-fix/containers/$*.Dockerfile .
5760
docker run --rm \
5861
-v $(PWD):/workspace \
5962
-w /workspace \
6063
test-image:$* \
61-
bash -c "make test || bats -t ./tests/test_all_packages.bats || true"
64+
bash -c "make test || bats -t ./tests/to-fix/test_all_packages.bats || true"

tests/intg/intg-tests.bats

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bats
2+
3+
## should work on mac and ubuntu
4+
## tests just the core features with minimum set of tools
5+
6+
INSTALL_DIR=
7+
BATS_TMPDIR="${BATS_TMPDIR:-/tmp}"
8+
fancyx=''
9+
checkmark=''
10+
11+
## We need to create a new directory so that .hasrc file in the root does not get read by the `has` instance under test
12+
setup() {
13+
export HAS_TMPDIR="${BATS_TMPDIR}/tmp-for-test"
14+
mkdir -p "${HAS_TMPDIR}"
15+
cp -f "${BATS_TEST_DIRNAME}"/../../has "${HAS_TMPDIR}"
16+
cd "${HAS_TMPDIR}" || return
17+
export has="${HAS_TMPDIR}/has"
18+
}
19+
20+
teardown() {
21+
if [[ -d "${HAS_TMPDIR}" ]]; then
22+
rm -rf "${HAS_TMPDIR}"
23+
fi
24+
}
25+
26+
@test "invoking 'has' without arguments prints usage" {
27+
run $has
28+
29+
[ "$status" -eq 0 ]
30+
[ "${lines[0]}" = 'Usage: has [OPTION] <command-names>...' ]
31+
[ "${lines[1]}" = 'Has checks the presence of various command line tools on the PATH and reports their installed version.' ]
32+
}
33+
34+
@test "git version output is non-empty and debug output is shown" {
35+
run $has git
36+
echo "Output: $output"
37+
[ "$status" -eq 0 ]
38+
[ "$(echo "${lines[0]}" | grep "git")" ]
39+
version="${lines[0]##* }"
40+
[ "${#version}" -ge 2 ]
41+
}
42+
43+
@test "check multiple real tools from .hasrc (make, curl, jq, node)" {
44+
run $has make curl jq node
45+
echo "Output: $output"
46+
[ "$status" -eq 0 ]
47+
for tool in make curl jq node; do
48+
line=$(echo "$output" | grep "$tool")
49+
[ -n "$line" ]
50+
version="${line##* }"
51+
[ "${#version}" -ge 1 ]
52+
done
53+
}
54+
55+
@test "loads commands from .hasrc file and excludes comments (real tools, output debug)" {
56+
printf "bash\n#comment\nmake\n" > .hasrc
57+
run $has
58+
echo "Output: $output"
59+
[ "$status" -eq 0 ]
60+
for tool in bash make; do
61+
line=$(echo "$output" | grep "$tool")
62+
[ -n "$line" ]
63+
version="${line##* }"
64+
[ "${#version}" -ge 1 ]
65+
done
66+
}
67+
68+
@test "'has' warns about tools not configured" {
69+
run $has foobar
70+
71+
[ "$status" -eq 1 ]
72+
[ "$(echo "${output}" | grep ${fancyx} | grep "foobar not understood")" ]
73+
}
74+
75+
@test "env var 'HAS_ALLOW_UNSAFE' overrides safety check" {
76+
HAS_ALLOW_UNSAFE=y run $has foobar
77+
78+
[ "$status" -eq 1 ]
79+
[ "$(echo "${output}" | grep ${fancyx} | grep "foobar")" ]
80+
}
81+
82+
@test "status code reflects number of failed commands" {
83+
HAS_ALLOW_UNSAFE=y run $has foobar git barbaz
84+
85+
[ "$status" -eq 2 ]
86+
[ "$(echo "${output}" | grep ${fancyx} | grep "foobar")" ]
87+
[ "$(echo "${output}" | grep ${fancyx} | grep "barbaz")" ]
88+
}
89+
90+
91+
@test "loads commands from .hasrc file and honors CLI args as well" {
92+
printf "bash\nmake\ngit" >> .hasrc
93+
run $has git jq
94+
95+
[ "$status" -eq 0 ]
96+
[ "$(echo "${output}" | grep ${checkmark} | grep "bash")" ]
97+
[ "$(echo "${output}" | grep ${checkmark} | grep "make")" ]
98+
[ "$(echo "${output}" | grep ${checkmark} | grep "git")" ]
99+
[ "$(echo "${output}" | grep ${checkmark} | grep "jq")" ]
100+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)