Skip to content

Commit

Permalink
Add @lib for code reuse #36
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Aug 24, 2021
1 parent 4b89a47 commit 98e7752
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
6 changes: 3 additions & 3 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function handleLib() {

libName = trim($2)
if (libName in Lib) {
die("Lib '" libName "' is already defined")
addError("Lib '" libName "' is already defined")
}
arrPush(LibNames, libName)
Lib[libName]
Expand All @@ -186,7 +186,7 @@ function handleUseLib( goal_name) {

function registerUseLib(goal_name) {
if (goal_name in GoalToLib)
die("You can only use one @lib in a @goal")
addError("You can only use one @lib in a @goal")

GoalToLib[goal_name] = $2
}
Expand Down Expand Up @@ -336,7 +336,7 @@ body,goal_body,goal_bodies,resolved_goals,exit_code, t0,t1,t2, goal_timed, list)
addLine(goal_body, trim(Code[""]))
exit_code = shellExec(goal_body[0]) # TODO optimize : don't exec empty prelude
if (exit_code != 0)
realExit(exit_code)
realExit(exit_code) # TODO show prelude failed

addLine(defines_line, MyDirScript)
if (DefinesFile)
Expand Down
4 changes: 4 additions & 0 deletions tests/13_errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@doc Doc in prelude
@options usupported
@shell usupported
@use_lib lib1

@goal
echo Goal without name
Expand All @@ -19,9 +20,12 @@
@goal g2
@shell sh
@define A=1
@lib lib2

@goal g3
@doc doc1
@doc doc2
@options timing
@unknown_directive arg
@use_lib lib1
@use_lib lib2
20 changes: 12 additions & 8 deletions tests/13_errors.tush
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ $ cd "$MYDIR"; ./makesure -f tests/13_errors.sh
@ tests/13_errors.sh:5: @options usupported
@ Shell 'usupported' is not supported:
@ tests/13_errors.sh:6: @shell usupported
@ Only use @use_lib in @goal:
@ tests/13_errors.sh:7: @use_lib lib1
@ Goal must have a name:
@ tests/13_errors.sh:8: @goal
@ tests/13_errors.sh:9: @goal
@ Goal 'g1' is already defined:
@ tests/13_errors.sh:14: @goal g1
@ tests/13_errors.sh:15: @goal g1
@ Multiple @reached_if not allowed for a goal:
@ tests/13_errors.sh:16: @reached_if false
@ tests/13_errors.sh:17: @reached_if false
@ Only use @shell in prelude:
@ tests/13_errors.sh:20: @shell sh
@ tests/13_errors.sh:21: @shell sh
@ Only use @define in prelude:
@ tests/13_errors.sh:21: @define A=1
@ tests/13_errors.sh:22: @define A=1
@ Multiple @doc not allowed for a goal:
@ tests/13_errors.sh:25: @doc doc2
@ tests/13_errors.sh:27: @doc doc2
@ Only use @options in prelude:
@ tests/13_errors.sh:26: @options timing
@ tests/13_errors.sh:28: @options timing
@ Unknown directive: @unknown_directive:
@ tests/13_errors.sh:27: @unknown_directive arg
@ tests/13_errors.sh:29: @unknown_directive arg
@ You can only use one @lib in a @goal:
@ tests/13_errors.sh:31: @use_lib lib2
? 1
10 changes: 5 additions & 5 deletions tests/16_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
echo "Hello $1"
}

@lib lib_name
f2 () {
echo "Hello lib_name $1"
}

@goal g1
@use_lib
f1 World

@goal g2
@use_lib lib_name
f2 World

@lib lib_name
f2 () {
echo "Hello lib_name $1"
}

0 comments on commit 98e7752

Please sign in to comment.