Skip to content

fix(learn): generate starter files that are valid bash - #1257

Merged
Chemaclass merged 2 commits into
mainfrom
fix/1256-learn-templates
Aug 14, 2026
Merged

fix(learn): generate starter files that are valid bash#1257
Chemaclass merged 2 commits into
mainfrom
fix/1256-learn-templates

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1256

bashunit learn writes 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:

function tear_down() {
  # TODO: Clean up test files
}

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

  • A : no-op in each comment-only body, so every template parses
  • run_lesson_test passes --fail-on-risky

The 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.

template run result
comments only (before) plain syntax error
valid with : plain exit 0 — lesson completed, no work done
valid with : --fail-on-risky exit 1
solved --fail-on-risky exit 0

The learner now sees Test has no assertions (risky) — the actual state of their work.

Guard

Extracts every template and runs bash -n over 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 -n accepts — 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_file uses echo "$content", and the templates contain '\'' escaping that arrives on disk correctly.

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
@Chemaclass Chemaclass added the bug Something isn't working label Aug 14, 2026
@Chemaclass Chemaclass self-assigned this Aug 14, 2026
@Chemaclass
Chemaclass merged commit 7d21449 into main Aug 14, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the fix/1256-learn-templates branch August 14, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant