Skip to content

test(learn): cover the rest of the non-interactive core#887

Merged
Chemaclass merged 2 commits into
mainfrom
test/learn-coverage
Jul 25, 2026
Merged

test(learn): cover the rest of the non-interactive core#887
Chemaclass merged 2 commits into
mainfrom
test/learn-coverage

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

src/learn.sh is 1213 lines with 6 tests over 4 functions. That gap is why the
duplication cleanup pass declined to touch it — roughly 50 lines of real, repeated code
sit in there, and a refactor had nothing to catch a mistake.

💡 Changes

  • Cover print_menu, show_progress, reset_progress, create_example_file and run_lesson_test (both the pass and fail paths): 4 functions → 9, 6 tests → 14
  • Verified non-vacuous by mutation: dropping the rm in reset_progress and the chmod in create_example_file each fail their test, and restoring returns to green

🔍 What the sandbox needed

Three things worth recording, since each looked like a test bug at first:

  • stdin from /dev/null so the Press Enter to continue prompts hit EOF instead of blocking — plus || true at the call sites, because that read returns non-zero and the sandbox runs under set -e
  • BASHUNIT_ROOT_DIR set inside the child shell (run_lesson_test shells out through it): it is readonly in the caller, so a VAR=x cmd prefix assignment aborts with readonly variable
  • the colour palette stubbed empty — learn.sh renders colour but does not source colors.sh, and pulling in the real chain (strglobalsenvcolors) would couple a unit test to source order

learn.sh is 1213 lines with 6 tests over 4 functions, which is why a real
duplication cleanup there could not be attempted safely -- a refactor had
nothing to catch it.

Covers print_menu, show_progress, reset_progress, create_example_file and
run_lesson_test (pass and fail paths): 4 functions to 9, 6 tests to 14.

Three things the sandbox needed:
- stdin from /dev/null so the 'Press Enter to continue' prompts hit EOF
  instead of blocking, plus '|| true' at the call sites because that read
  returns non-zero and the sandbox runs under set -e
- BASHUNIT_ROOT_DIR set INSIDE the child (run_lesson_test shells out
  through it); it is readonly in the caller, so a prefix assignment aborts
- the colour palette stubbed empty, since learn.sh renders colour but does
  not source colors.sh; pulling the real chain in would couple a unit test
  to source order

Verified non-vacuous by mutation: dropping the rm in reset_progress and
the chmod in create_example_file each fail their test.
@Chemaclass Chemaclass added the enhancement New feature or request label Jul 25, 2026
@Chemaclass Chemaclass self-assigned this Jul 25, 2026
Under --strict the test shell runs set -e, so a non-zero return from the
sandbox aborted the test before its assertion. show_progress and
print_menu are inspected for their output, not their status, so the call
sites tolerate it -- matching what the interactive ones already do for
the read-at-EOF case.

Verified on real Bash 3.0 in Docker with --strict, and locally with
--strict --parallel.
@Chemaclass
Chemaclass merged commit 01c813b into main Jul 25, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the test/learn-coverage branch July 25, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant