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

chore: Add simple unit tests to check basic functions with make test #236

Merged
merged 3 commits into from
Sep 23, 2024
Merged
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
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 [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/)):

```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
}