Skip to content

Commit

Permalink
Parameterized goals #115
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Jan 25, 2023
1 parent acdaa43 commit 61a2b9e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
18 changes: 11 additions & 7 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function registerUseLib(goalName) {

function handleGoal( i,goalName) {
started("goal")
if (registerGoal(isPriv(), goalName=$2))
if (registerGoal(parsePriv(), goalName=$2))
if ("@params" == $3) {
if (3 == NF) addError("missing parameters")
for (i=4; i <= NF; i++)
Expand Down Expand Up @@ -255,14 +255,18 @@ function calcGlob(goalName, pattern, script, file) {
quicksort(GlobFiles,0,arrLen(GlobFiles)-1)
}

function isPriv() { if ("@private" != $NF) return 0; NF--; return 1 }
function parsePriv() { if ("@private" != $NF) return 0; NF--; return 1 }

function handleGoalGlob( goalName,globAllGoal,globSingle,priv,i,pattern) {
function handleGoalGlob( goalName,globAllGoal,globSingle,priv,i,pattern,nfMax) {
started("goal_glob")
priv = isPriv()
goalName = $2; pattern = $4
if ("@glob" == goalName) {
goalName = ""; pattern = $3
priv = parsePriv()
if ("@glob" == goalName = $2) {
goalName = ""; pattern = $(nfMax=3)
} else
pattern = $(nfMax=4)
if (NF > nfMax) {
addError("nothing allowed after glob pattern")
return
}
calcGlob(goalName, pattern)
globAllGoal = goalName ? goalName : pattern
Expand Down
16 changes: 16 additions & 0 deletions tests/12_errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,19 @@ echo 'more code in prelude'
@depends_on unknown1

@lib lib2

@goal @private
echo 'private goal without name'

@goal g15 should not have anything after goal name
@goal g16 # but comment is OK

@goal g17 @glob '*.txt' should not have anything after glob pattern
@goal g18 @glob '*.txt' # but comment is OK

@goal @glob '*.txt' should not have anything after glob pattern
@goal @glob '*.txt' should_not_have_anything_after_glob_pattern
@goal @glob '*.txt' # but comment is OK

@goal @glob # absent glob pattern
@goal g19 @glob # absent glob pattern
10 changes: 10 additions & 0 deletions tests/12_errors.tush
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/12_errors.sh
@ tests/12_errors.sh:38: @use_lib lib2
@ Lib 'lib2' is already defined:
@ tests/12_errors.sh:46: @lib lib2
@ Goal must have a name:
@ tests/12_errors.sh:48: @goal @private
@ nothing allowed after goal name:
@ tests/12_errors.sh:51: @goal g15 should not have anything after goal name
@ nothing allowed after glob pattern:
@ tests/12_errors.sh:54: @goal g17 @glob '*.txt' should not have anything after glob pattern
@ nothing allowed after glob pattern:
@ tests/12_errors.sh:57: @goal @glob '*.txt' should not have anything after glob pattern
@ nothing allowed after glob pattern:
@ tests/12_errors.sh:58: @goal @glob '*.txt' should_not_have_anything_after_glob_pattern
@ Goal 'g1' has unknown dependency 'unknown':
@ tests/12_errors.sh:18: @depends_on unknown
@ Goal 'g2' uses unknown lib 'unknown':
Expand Down

0 comments on commit 61a2b9e

Please sign in to comment.