Skip to content

bashunit learn generates starter files that are not valid bash #1256

Closed

Description

@Chemaclass

Problem

bashunit learn writes a starter file for each lesson, and 7 of the 10 templates do not parse. A function body of only comments is a syntax error in bash, and the templates are full of them — 28 comment-only bodies across the lessons:

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

So a learner who runs the lesson to generate the file, fills in one TODO and runs again gets:

challenge_test.sh: line 72: syntax error near unexpected token `}'
✗ Error: Source

That says nothing about the lesson, and the invalid file came from bashunit itself. It is the first thing a newcomer to the tool sees.

The fix needs two halves

Adding a : no-op to each body makes the file parse — and on its own that is worse, because an untouched template then passes the lesson:

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

bashunit::learn::run_lesson_test runs "$BASHUNIT_ROOT_DIR/bashunit" "$test_file" --simple and treats exit 0 as success. A test with no assertions is risky, and risky exits 0 by default.

So: make the templates parse, and run the lesson's verification with --fail-on-risky. The learner then sees "risky: no assertions" — which is the actual state of their work — instead of a bash syntax error, and cannot complete a lesson without writing an assertion.

Verified

All 16 assertions the lessons teach exist in src/assert/, so the taught API itself is accurate; this is about the generated files.

Activity

  1. self-assigned this
    on Aug 14, 2026
  2. Chemaclass commented on Aug 14, 2026

    @Chemaclass
    MemberAuthor

    Done in #1257 (merged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions