Skip to content

Commit

Permalink
Add @lib for code reuse #36 : handle unknown lib
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Sep 3, 2021
1 parent 67bcaef commit 82b00cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ BEGIN {
split("",GlobGoals) # list
split("",LibNames) # list
split("",Lib) # name -> code
split("",UseLibLineNo)# name -> line no.
split("",GoalToLib)# goal name -> lib name
Mode = "prelude" # prelude|goal|goal_glob|lib
srand()
Expand Down Expand Up @@ -189,6 +190,7 @@ function registerUseLib(goal_name) {
addError("You can only use one @lib in a @goal")

GoalToLib[goal_name] = $2
UseLibLineNo[goal_name] = NR
}

function handleGoal( priv) {
Expand Down Expand Up @@ -381,8 +383,11 @@ body,goal_body,goal_bodies,resolved_goals,exit_code, t0,t1,t2, goal_timed, list)
addLine(goal_body, "exit 0")

addLine(goal_body, defines_line[0])
if (goal_name in GoalToLib)
addLine(goal_body, Lib[GoalToLib[goal_name]]) # TODO handle unknown lib
if (goal_name in GoalToLib) {
if (!(GoalToLib[goal_name] in Lib))
die("Goal '" goal_name "' uses unknown lib '" GoalToLib[goal_name] "'", UseLibLineNo[goal_name])
addLine(goal_body, Lib[GoalToLib[goal_name]])
}

if ("tracing" in Options)
addLine(goal_body, "set -x")
Expand Down
4 changes: 4 additions & 0 deletions tests/16_lib.tush
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ $ cd "$MYDIR"; ./makesure -f tests/16_lib.sh g2
| goal 'g2' ...
| Hello lib_name World

$ cd "$MYDIR"; ./makesure -f tests/16_lib_unknown.sh g3
@ Goal 'g3' uses unknown lib 'unknown':
@ tests/16_lib_unknown.sh:3: @use_lib unknown
? 1

7 changes: 7 additions & 0 deletions tests/16_lib_unknown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@goal g3
@use_lib unknown

#@goal g4
#@use_lib

0 comments on commit 82b00cb

Please sign in to comment.