From adb6b7341ba334626792e73a4518ef9bc917dbbf Mon Sep 17 00:00:00 2001 From: tmakar Date: Tue, 2 May 2023 20:46:39 +0200 Subject: [PATCH 1/8] test: add shell test case for parent array spec bug (#4061) --- .../example_codegen_econf_empty_array_spec.sh | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/shell/external/example_codegen_econf_empty_array_spec.sh diff --git a/tests/shell/external/example_codegen_econf_empty_array_spec.sh b/tests/shell/external/example_codegen_econf_empty_array_spec.sh new file mode 100644 index 00000000000..e9b96d14593 --- /dev/null +++ b/tests/shell/external/example_codegen_econf_empty_array_spec.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +@INCLUDE_COMMON@ + +echo +echo ELEKTRA CHECK EXTERNAL CODEGEN ECONF EMPTY ARRAY SPEC +echo + +if command -v realpath; then + if command -v pkg-config; then + if ! pkg-config elektra; then + echo "Elektra not installed, will skip" + exit 0 + fi + else + echo "pkg-config not installed, will skip" + exit 0 + fi +else + echo "realpath is not installed, will skip" + exit 0 +fi + +check_version + +EXTERNAL_FOLDER="@CMAKE_SOURCE_DIR@/examples/codegen/econf" + +check_if_parent_exists() { + if grep -e "spec:\/sw\/example\/econf/\#0\/current\/format\/#$"; then + echo "array parent was found" + return 0 + else + echo "did not find array parent spec:/sw/example/econf/#0/current/format/#" + return 1 + fi +} + +do_tests() { + KEY="/sw/example/econf/#0/current" + UKEY="user:$KEY" + SPECKEY="spec:$KEY" + + "$KDB" umount "$SPECKEY" + "$KDB" umount "$KEY" + "$KDB" rm -r "$UKEY" + "$KDB" rm -r "$SPECKEY" + + "$KDB" mount `pwd`/spec.ini "$SPECKEY" ni + "$KDB" import "$SPECKEY" ni < "$EXTERNAL_FOLDER/spec.ini" + "$KDB" spec-mount "$KEY" + + "$KDB" ls "spec:/sw/example/econf/#0" | check_if_parent_exists + + "$KDB" meta-set "$KEY/format" array "#2" + "$KDB" ls "spec:/sw/example/econf/#0" | check_if_parent_exists +} + +echo "Testing build with cmake" + +cd "$EXTERNAL_FOLDER" || exit +mkdir build +cd build || exit + +# manually set Elektra_DIR and KDB to support non-standard install locations +cmake ../cmake -DElektra_DIR:PATH="$(realpath $(dirname "$0")/../../cmake/Elektra)" -DKDB:PATH="$KDB" +succeed_if "could not run cmake" + +cmake --build . +succeed_if "could not build cmake project" + +do_tests + +cd .. +rm -r build + +echo "Testing build with pkgconfig" + +cd "$EXTERNAL_FOLDER/pkgconfig" || exit +# set KDB to support non-standard install locations +KDB="$KDB" make +succeed_if "could not build pkgconfig project" + +do_tests + +make clean + +end_script gen \ No newline at end of file From 72891cf4c62a8bd8dd9fc03696b5420bd8ae3c14 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 2 May 2023 18:53:55 +0000 Subject: [PATCH 2/8] Restyled by shfmt --- .../external/example_codegen_econf_empty_array_spec.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/shell/external/example_codegen_econf_empty_array_spec.sh b/tests/shell/external/example_codegen_econf_empty_array_spec.sh index e9b96d14593..da79c3b1aa0 100644 --- a/tests/shell/external/example_codegen_econf_empty_array_spec.sh +++ b/tests/shell/external/example_codegen_econf_empty_array_spec.sh @@ -30,7 +30,7 @@ check_if_parent_exists() { echo "array parent was found" return 0 else - echo "did not find array parent spec:/sw/example/econf/#0/current/format/#" + echo "did not find array parent spec:/sw/example/econf/#0/current/format/#" return 1 fi } @@ -45,7 +45,7 @@ do_tests() { "$KDB" rm -r "$UKEY" "$KDB" rm -r "$SPECKEY" - "$KDB" mount `pwd`/spec.ini "$SPECKEY" ni + "$KDB" mount $(pwd)/spec.ini "$SPECKEY" ni "$KDB" import "$SPECKEY" ni < "$EXTERNAL_FOLDER/spec.ini" "$KDB" spec-mount "$KEY" @@ -84,4 +84,4 @@ do_tests make clean -end_script gen \ No newline at end of file +end_script gen From 21f8b7234050245b35cec90060c31867c10b44e7 Mon Sep 17 00:00:00 2001 From: tmakar Date: Tue, 2 May 2023 21:18:12 +0200 Subject: [PATCH 3/8] fix: remove return values (#4061) --- tests/shell/external/example_codegen_econf_empty_array_spec.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/shell/external/example_codegen_econf_empty_array_spec.sh b/tests/shell/external/example_codegen_econf_empty_array_spec.sh index da79c3b1aa0..051f1f807ab 100644 --- a/tests/shell/external/example_codegen_econf_empty_array_spec.sh +++ b/tests/shell/external/example_codegen_econf_empty_array_spec.sh @@ -28,10 +28,8 @@ EXTERNAL_FOLDER="@CMAKE_SOURCE_DIR@/examples/codegen/econf" check_if_parent_exists() { if grep -e "spec:\/sw\/example\/econf/\#0\/current\/format\/#$"; then echo "array parent was found" - return 0 else echo "did not find array parent spec:/sw/example/econf/#0/current/format/#" - return 1 fi } From 79e04869380d1e470c088ca74d1e6faa01fdb02f Mon Sep 17 00:00:00 2001 From: tmakar Date: Tue, 2 May 2023 22:38:07 +0200 Subject: [PATCH 4/8] fix: clean up after econf empty array spec test (#4061) --- .../external/example_codegen_econf_empty_array_spec.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/shell/external/example_codegen_econf_empty_array_spec.sh b/tests/shell/external/example_codegen_econf_empty_array_spec.sh index 051f1f807ab..0927ee8f0ad 100644 --- a/tests/shell/external/example_codegen_econf_empty_array_spec.sh +++ b/tests/shell/external/example_codegen_econf_empty_array_spec.sh @@ -51,6 +51,12 @@ do_tests() { "$KDB" meta-set "$KEY/format" array "#2" "$KDB" ls "spec:/sw/example/econf/#0" | check_if_parent_exists + + "$KDB" rm -r "$UKEY" + "$KDB" rm -r "$SPECKEY" + "$KDB" umount "$SPECKEY" + "$KDB" umount "$UKEY" + "$KDB" umount "$KEY" } echo "Testing build with cmake" From 9abe1f674315cc19089e14f56107c52db7bf0973 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 2 May 2023 20:38:20 +0000 Subject: [PATCH 5/8] Restyled by shfmt --- .../external/example_codegen_econf_empty_array_spec.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/shell/external/example_codegen_econf_empty_array_spec.sh b/tests/shell/external/example_codegen_econf_empty_array_spec.sh index 0927ee8f0ad..bfb2e67dd52 100644 --- a/tests/shell/external/example_codegen_econf_empty_array_spec.sh +++ b/tests/shell/external/example_codegen_econf_empty_array_spec.sh @@ -53,10 +53,10 @@ do_tests() { "$KDB" ls "spec:/sw/example/econf/#0" | check_if_parent_exists "$KDB" rm -r "$UKEY" - "$KDB" rm -r "$SPECKEY" - "$KDB" umount "$SPECKEY" - "$KDB" umount "$UKEY" - "$KDB" umount "$KEY" + "$KDB" rm -r "$SPECKEY" + "$KDB" umount "$SPECKEY" + "$KDB" umount "$UKEY" + "$KDB" umount "$KEY" } echo "Testing build with cmake" From 4dce253adc7a97902f8dde37eaa3d33c750edeaa Mon Sep 17 00:00:00 2001 From: tmakar Date: Tue, 2 May 2023 23:50:52 +0200 Subject: [PATCH 6/8] doc: add release note --- doc/news/_preparation_next_release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/news/_preparation_next_release.md b/doc/news/_preparation_next_release.md index b92717655fa..d5056ff3119 100755 --- a/doc/news/_preparation_next_release.md +++ b/doc/news/_preparation_next_release.md @@ -477,7 +477,7 @@ This section keeps you up-to-date with the multi-language support provided by El ## Tests -- <> +- Add shell test to verify correct behavior for https://github.com/ElektraInitiative/libelektra/issues/4061 _(Tomislav Makar @tmakar)_ - <> - <> - <> From e5f7edf6acbae07997b3ea0eb3bd50a9383b826d Mon Sep 17 00:00:00 2001 From: tmakar Date: Wed, 3 May 2023 08:55:38 +0200 Subject: [PATCH 7/8] fix: wrap environment variable call --- .../shell/external/example_codegen_econf_empty_array_spec.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/shell/external/example_codegen_econf_empty_array_spec.sh b/tests/shell/external/example_codegen_econf_empty_array_spec.sh index bfb2e67dd52..556a163d09c 100644 --- a/tests/shell/external/example_codegen_econf_empty_array_spec.sh +++ b/tests/shell/external/example_codegen_econf_empty_array_spec.sh @@ -43,7 +43,7 @@ do_tests() { "$KDB" rm -r "$UKEY" "$KDB" rm -r "$SPECKEY" - "$KDB" mount $(pwd)/spec.ini "$SPECKEY" ni + "$KDB" mount "$(pwd)/spec.ini" "$SPECKEY" ni "$KDB" import "$SPECKEY" ni < "$EXTERNAL_FOLDER/spec.ini" "$KDB" spec-mount "$KEY" @@ -66,7 +66,7 @@ mkdir build cd build || exit # manually set Elektra_DIR and KDB to support non-standard install locations -cmake ../cmake -DElektra_DIR:PATH="$(realpath $(dirname "$0")/../../cmake/Elektra)" -DKDB:PATH="$KDB" +cmake ../cmake -DElektra_DIR:PATH="$(realpath "$(dirname "$0")"/../../cmake/Elektra)" -DKDB:PATH="$KDB" succeed_if "could not run cmake" cmake --build . From c741bdc23f821c8cc9ba6fb3e89c78d3672323e6 Mon Sep 17 00:00:00 2001 From: tmakar Date: Tue, 9 May 2023 11:31:42 +0200 Subject: [PATCH 8/8] fix: return on error after print --- tests/shell/external/example_codegen_econf_empty_array_spec.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/shell/external/example_codegen_econf_empty_array_spec.sh b/tests/shell/external/example_codegen_econf_empty_array_spec.sh index 556a163d09c..c8c9424a2f1 100644 --- a/tests/shell/external/example_codegen_econf_empty_array_spec.sh +++ b/tests/shell/external/example_codegen_econf_empty_array_spec.sh @@ -30,6 +30,7 @@ check_if_parent_exists() { echo "array parent was found" else echo "did not find array parent spec:/sw/example/econf/#0/current/format/#" + exit 1 fi }