test(learn): cover the rest of the non-interactive core#887
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Background
src/learn.shis 1213 lines with 6 tests over 4 functions. That gap is why theduplication 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
print_menu,show_progress,reset_progress,create_example_fileandrun_lesson_test(both the pass and fail paths): 4 functions → 9, 6 tests → 14rminreset_progressand thechmodincreate_example_fileeach 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:
/dev/nullso thePress Enter to continueprompts hit EOF instead of blocking — plus|| trueat the call sites, because thatreadreturns non-zero and the sandbox runs underset -eBASHUNIT_ROOT_DIRset inside the child shell (run_lesson_testshells out through it): it is readonly in the caller, so aVAR=x cmdprefix assignment aborts withreadonly variablelearn.shrenders colour but does not sourcecolors.sh, and pulling in the real chain (str→globals→env→colors) would couple a unit test to source order