Skip to content

tests: shunit2: add test for _jshn_append via JSON script - #30

Merged
openwrt-bot merged 1 commit into
openwrt:masterfrom
ynezz:ynezz/jshn-append-test
Nov 17, 2025
Merged

tests: shunit2: add test for _jshn_append via JSON script#30
openwrt-bot merged 1 commit into
openwrt:masterfrom
ynezz:ynezz/jshn-append-test

Conversation

@ynezz

@ynezz ynezz commented Nov 13, 2025

Copy link
Copy Markdown
Member

tests: shunit2: add test for _jshn_append via JSON script

Add another test which verifies _jshn_append leading space fix in commit
82cb5fd ("libubox: Drop extraneous space when appending values to
variable") by appending keys to JSON objects, making sure there is no
leading space on the first key when adding second key.

  test_jshn_append_via_json_script
  ASSERT:expected:<first> but was:< first>
  ASSERT:expected:<first second> but was:< first second>

Tests: #16

tests: shunit2: add bash shebang to fix export -n error in dash

The test script was missing a shebang, causing it to be executed with
/bin/sh (often dash on Debian/Ubuntu systems). When the test sources
jshn.sh, which uses 'export -n', dash fails with:

  libubox/tests/shunit2/tests.sh: 125: export: Illegal option -n

Fix it by adding bash shebang.


https://github.com/ynezz/openwrt-libubox/actions/runs/19331703870/job/55296135170#step:9:34

Test results with 82cb5fd fix reverted
Run make test CTEST_OUTPUT_ON_FAILURE=1
Running tests...
Test project /home/runner/work/openwrt-libubox/openwrt-libubox
    Start 1: cram
1/2 Test #1: cram .............................   Passed   45.61 sec
    Start 2: shunit2
2/2 Test #2: shunit2 ..........................***Failed    0.20 sec
#
# Performing tests
#
test_bad_json
test_expr_eq
test_expr_has
test_expr_regex_single
test_expr_regex_multi
test_expr_not
test_expr_and
test_expr_or
test_expr_isdir
test_cmd_case
test_cmd_if
test_cmd_cb
test_cmd_return
test_jshn_append_no_leading_space
ASSERT:expected:<foo> but was:< foo>
ASSERT:expected:<first second> but was:< first second>
test_jshn_append_via_json_script
ASSERT:expected:<first> but was:< first>
ASSERT:expected:<first second> but was:< first second>

#
# Test report
#
tests passed:     1  20%
tests failed:     4  80%
tests skipped:    0   0%
tests total:      5 100%

Errors while running CTest

50% tests passed, 1 tests failed out of 2

Total Test time (real) =  45.81 sec

The following tests FAILED:
	  2 - shunit2 (Failed)
make: *** [Makefile:71: test] Error 8

@l-jonas

l-jonas commented Nov 13, 2025

Copy link
Copy Markdown

This adds tests for the manually merged #16. Now, one can easily see why that other PR is useful. Now I see a reason for merging that other PR and this one too.

Add another test which verifies _jshn_append leading space fix in commit
82cb5fd ("libubox: Drop extraneous space when appending values to
variable") by appending keys to JSON objects, making sure there is no
leading space on the first key when adding second key.

  test_jshn_append_via_json_script
  ASSERT:expected:<first> but was:< first>
  ASSERT:expected:<first second> but was:< first second>

Tests: openwrt#16
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Link: openwrt#30
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
@Noltari
Noltari force-pushed the ynezz/jshn-append-test branch from 29f067f to a3ff29e Compare November 17, 2025 18:31
@openwrt-bot
openwrt-bot merged commit a3ff29e into openwrt:master Nov 17, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants