fix(learn): generate starter files that are valid bash - #1257
Merged
Conversation
A function body of only TODO comments is a syntax error, so 7 of the 10 lesson templates did not parse -- 28 such bodies. A learner who generated the file and ran the lesson got syntax error near unexpected token `}' from a file bashunit itself wrote, saying nothing about the lesson, as their first contact with the tool. Adding the no-op alone would be worse: an untouched template then completes the lesson, because run_lesson_test treats exit 0 as success and a test with no assertions is risky, which exits 0. So the runner passes --fail-on-risky too. The learner now sees "Test has no assertions (risky)", which is the actual state of their work, and a solved lesson still exits 0. Guarded by extracting every template and running bash -n over it. The first extractor was line-oriented and reported templates as broken that bash accepts, which would have made the test lie; the perl one matches the measurement taken by hand. ShellCheck cannot see inside a string literal, which is why 28 invalid bodies sat there unnoticed. Closes #1256
This was referenced Aug 14, 2026
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
Related #1256
bashunit learnwrites a starter file per lesson, and 7 of the 10 templates did not parse — a function body of only TODO comments is a bash syntax error, and there were 28 of them:A learner who generated the file, filled in one TODO and ran the lesson got
syntax error near unexpected token '}'from a file bashunit itself wrote — as their first contact with the tool.💡 Changes
:no-op in each comment-only body, so every template parsesrun_lesson_testpasses--fail-on-riskyThe second is not optional. Making the templates valid alone is worse than the bug: an untouched template then completes the lesson, because the runner treats exit 0 as success and a test with no assertions is risky, which exits 0 by default.
::--fail-on-risky--fail-on-riskyThe learner now sees
Test has no assertions (risky)— the actual state of their work.Guard
Extracts every template and runs
bash -nover it, plus a self-check that the scan can fail and an assertion that the runner keeps--fail-on-risky. Mutation-checked by removing one no-op.My first extractor was line-oriented and reported templates as broken that
bash -naccepts — it would have made the test lie. The perl one matches the measurement I had taken by hand, and the comment says why. ShellCheck cannot see inside a string literal, which is how 28 invalid bodies went unnoticed.Verified through the real write path too:
create_example_fileusesecho "$content", and the templates contain'\''escaping that arrives on disk correctly.