Skip to content

Commit

Permalink
chore: Add simple unit tests to check basic functions with make test
Browse files Browse the repository at this point in the history
Tests are executed with `bats`.
Currently it checks the "version" and "help" function (this notably verifies that libraries are correctly sourced and called from the main script).

Closes #234
  • Loading branch information
Antiz96 committed Sep 23, 2024
1 parent a1a5c07 commit 825dd6d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ _pkgname=Arch-Update

PREFIX ?= /usr/local

.PHONY: all install uninstall
.PHONY: all install test uninstall

all:

Expand Down Expand Up @@ -95,5 +95,5 @@ uninstall:
rm -rf "${DESTDIR}${PREFIX}/share/doc/${pkgname}/"

test:
# Run the help function of the main script as a simple test
"src/script/${pkgname}.sh" --help
# Run some simple unit tests on basic functions
bats test/case/basic_functions.bats
6 changes: 6 additions & 0 deletions README-fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ Pour installer `arch-update`, allez dans le répertoire extrait/cloné et exécu
sudo make install
```

Si vous voulez exécuter des tests unitaires simples, vous pouvez exécuter la commande suivante (requiert l'installation de [bats](https://archlinux.org/packages/extra/any/bats/) :

```bash
make test
```

Pour désinstaller `arch-update`, allez dans le répertoire extrait/cloné et exécutez la commande suivante :

```bash
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ To install `arch-update`, go into the extracted/cloned directory and run the fol
sudo make install
```

If you want to run simple unit tests, you can run the following command (requires [bats](https://archlinux.org/packages/extra/any/bats/) to be installed):

```bash
make test
```

To uninstall `arch-update`, go into the extracted/cloned directory and run the following command:

```bash
Expand Down
4 changes: 3 additions & 1 deletion src/arch-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ version="2.3.3"
option="${1}"

# Define the directory containing libraries
if [ -d "${XDG_DATA_HOME}/${name}/lib" ]; then
if [ -n "${TEST_LIBDIR}" ]; then # Used in bats test cases for `make test`
libdir="${TEST_LIBDIR}"
elif [ -d "${XDG_DATA_HOME}/${name}/lib" ]; then
libdir="${XDG_DATA_HOME}/${name}/lib"
elif [ -d "${HOME}/.local/share/${name}/lib" ]; then
libdir="${HOME}/.local/share/${name}/lib"
Expand Down
9 changes: 9 additions & 0 deletions test/case/basic_functions.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export TEST_LIBDIR="${PWD}/src/lib"

@test "version" {
src/arch-update.sh --version
}

@test "help" {
src/arch-update.sh --help
}

0 comments on commit 825dd6d

Please sign in to comment.