From d6645611439e2a41dc01a5462f05a28145791cf6 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 7 Jan 2023 16:10:23 +0900 Subject: [PATCH] test.sh: Prefer toolbox in same directory over globally installed one Because test.sh uses the environment's PATH, it ends up using whatever toolbox is installed in the environment, instead of the toolbox that it was shipped with. This commit modifies the test script so that it overrides the path, making tests use the toolbox they were distributed with. This also removes unnecessary PATH modifications from the test specs. --- test.sh | 29 +++++++++++++++++++++++++++++ test/array_spec.sh | 4 +--- test/include | 1 - test/ipc_spec.sh | 4 +--- test/is_spec.sh | 4 +--- test/json_spec.sh | 4 +--- test/log_spec.sh | 4 +--- test/mutex_spec.sh | 2 -- test/opt_spec.sh | 2 -- test/queue_spec.sh | 4 +--- test/sem_spec.sh | 2 -- test/uipc_spec.sh | 4 +--- test/wmutex_spec.sh | 2 -- 13 files changed, 36 insertions(+), 30 deletions(-) delete mode 120000 test/include diff --git a/test.sh b/test.sh index 5c2f4c1..9895b63 100755 --- a/test.sh +++ b/test.sh @@ -85,7 +85,36 @@ main() { return 0 } +whereami() { + local scriptpath + + if ! scriptpath=$(realpath "${BASH_SOURCE[0]}"); then + return 1 + fi + + echo "${scriptpath%/*}" + return 0 +} + +use_this_toolbox() { + local here + + if ! here=$(whereami); then + return 1 + fi + + if ! export PATH="$here:$PATH"; then + return 1 + fi + + return 0 +} + { + if ! use_this_toolbox; then + exit 1 + fi + if ! . toolbox.sh; then exit 1 fi diff --git a/test/array_spec.sh b/test/array_spec.sh index d6f8210..30ec14e 100644 --- a/test/array_spec.sh +++ b/test/array_spec.sh @@ -1,7 +1,7 @@ #!/bin/bash # array_spec.sh - Test cases for the toolbox array module -# Copyright (C) 2021 Matthias Kruk +# Copyright (C) 2021-2023 Matthias Kruk # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -export PATH="$PWD/..:$PATH" - if ! . toolbox.sh; then exit 1 fi diff --git a/test/include b/test/include deleted file mode 120000 index f5030fe..0000000 --- a/test/include +++ /dev/null @@ -1 +0,0 @@ -../include \ No newline at end of file diff --git a/test/ipc_spec.sh b/test/ipc_spec.sh index c45aa63..2a699d6 100644 --- a/test/ipc_spec.sh +++ b/test/ipc_spec.sh @@ -1,7 +1,7 @@ #!/bin/bash # ipc_spec.sh - Test cases for the toolbox ipc module -# Copyright (C) 2021 Matthias Kruk +# Copyright (C) 2021-2023 Matthias Kruk # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -export PATH="$PWD/..:$PATH" - . toolbox.sh include "ipc" diff --git a/test/is_spec.sh b/test/is_spec.sh index e23df5a..86ce770 100644 --- a/test/is_spec.sh +++ b/test/is_spec.sh @@ -1,7 +1,7 @@ #!/bin/bash # is_spec.sh - Test cases for the toolbox is module -# Copyright (C) 2021 Matthias Kruk +# Copyright (C) 2021-2023 Matthias Kruk # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -export PATH="$PWD/..:$PATH" - . toolbox.sh include "is" diff --git a/test/json_spec.sh b/test/json_spec.sh index 3a64876..bbe5e0d 100644 --- a/test/json_spec.sh +++ b/test/json_spec.sh @@ -1,7 +1,7 @@ #!/bin/bash # json_spec.sh - Test cases for the toolbox json module -# Copyright (C) 2021 Matthias Kruk +# Copyright (C) 2021-2023 Matthias Kruk # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -export PATH="$PWD/..:$PATH" - if ! . toolbox.sh; then exit 1 fi diff --git a/test/log_spec.sh b/test/log_spec.sh index 13868c6..757a5c6 100644 --- a/test/log_spec.sh +++ b/test/log_spec.sh @@ -1,7 +1,7 @@ #!/bin/bash # log_spec.sh - Test cases for the toolbox log module -# Copyright (C) 2021 Matthias Kruk +# Copyright (C) 2021-2023 Matthias Kruk # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -export PATH="$PWD/..:$PATH" - . toolbox.sh include "log" diff --git a/test/mutex_spec.sh b/test/mutex_spec.sh index ef96d12..0e44291 100644 --- a/test/mutex_spec.sh +++ b/test/mutex_spec.sh @@ -1,7 +1,5 @@ #!/bin/bash -export PATH="$PWD/..:$PATH" - . toolbox.sh include "mutex" diff --git a/test/opt_spec.sh b/test/opt_spec.sh index 81a8ab5..50d8d66 100644 --- a/test/opt_spec.sh +++ b/test/opt_spec.sh @@ -1,7 +1,5 @@ #!/bin/bash -export PATH="$PWD/..:$PATH" - . toolbox.sh include "opt" diff --git a/test/queue_spec.sh b/test/queue_spec.sh index a921348..6aaab60 100644 --- a/test/queue_spec.sh +++ b/test/queue_spec.sh @@ -1,7 +1,7 @@ #!/bin/bash # queue_spec.sh - Test cases for the toolbox queue module -# Copyright (C) 2021 Matthias Kruk +# Copyright (C) 2021-2023 Matthias Kruk # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -export PATH="$PWD/..:$PATH" - if ! . toolbox.sh; then exit 1 fi diff --git a/test/sem_spec.sh b/test/sem_spec.sh index 72d1055..f4e0a22 100644 --- a/test/sem_spec.sh +++ b/test/sem_spec.sh @@ -1,7 +1,5 @@ #!/bin/bash -export PATH="$PWD/..:$PATH" - . toolbox.sh include "sem" diff --git a/test/uipc_spec.sh b/test/uipc_spec.sh index 9d25806..9f0e22d 100644 --- a/test/uipc_spec.sh +++ b/test/uipc_spec.sh @@ -1,7 +1,7 @@ #!/bin/bash # uipc_spec.sh - Test cases for the toolbox uipc module -# Copyright (C) 2022 Matthias Kruk +# Copyright (C) 2022-2023 Matthias Kruk # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -export PATH="$PWD/..:$PATH" - . toolbox.sh include "uipc" diff --git a/test/wmutex_spec.sh b/test/wmutex_spec.sh index ad1c5bf..61adfec 100644 --- a/test/wmutex_spec.sh +++ b/test/wmutex_spec.sh @@ -1,7 +1,5 @@ #!/bin/bash -export PATH="$PWD/..:$PATH" - . toolbox.sh include "wmutex" -- 2.47.3