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 23, 2023
1 parent 86a6f34 commit beef41d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
24 changes: 12 additions & 12 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,11 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) {

checkBeforeRun()

dbgA("GoalParamsCnt",GoalParamsCnt)
dbgA("GoalParams",GoalParams)
dbgA("DependencyArgsCnt",DependencyArgsCnt)
dbgA("DependencyArgs",DependencyArgs)
dbgA("DependencyArgsType",DependencyArgsType)
# dbgA("GoalParamsCnt",GoalParamsCnt)
# dbgA("GoalParams",GoalParams)
# dbgA("DependencyArgsCnt",DependencyArgsCnt)
# dbgA("DependencyArgs",DependencyArgs)
# dbgA("DependencyArgsType",DependencyArgsType)

# First do topological sort disregarding @reached_if to catch loops.
# We need to do it before instantiate, because instantiation is recursive and will hang in presence of loop.
Expand Down Expand Up @@ -505,6 +505,7 @@ function realExit(code) {
exit code
}
function addError(err, n) { if (!n) n=NR; Error=addL(Error, err ":\n" ARGV[1] ":" n ": " Lines[n]) }
function addErrorDedup(err, n) { if ((err,n) in AddedErrors) return; AddedErrors[err,n]; addError(err,n) }
function die(msg, out) {
out = "cat 1>&2" # trick to write from awk to stderr
print msg | out
Expand Down Expand Up @@ -627,7 +628,7 @@ function renderArgs(args, s,k) { s = ""; for (k in args) s = s k "=>" args[k]
# args: { F => "file1" }
#
function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInstantiated,argsCnt,gi,gii) { # -> goalNameInstantiated
indent(IDepth++); print "instantiating " goal " { " renderArgs(args) "} ..."
# indent(IDepth++); print "instantiating " goal " { " renderArgs(args) "} ..."

goalNameInstantiated = instantiateGoalName(goal, args)

Expand All @@ -650,24 +651,23 @@ function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInst
dep = Dependencies[gi = goal SUBSEP i]
argsCnt = +DependencyArgsCnt[gi]

# we should not report wrong args count for unknown deps
# we do not report wrong args count for unknown deps
if (dep in GoalsByName && argsCnt != GoalParamsCnt[dep])
addError("wrong args count for '" dep "'", DependenciesLineNo[gi])
# dbgA("DependencyArgsCnt",DependencyArgsCnt)
addErrorDedup("wrong args count for '" dep "'", DependenciesLineNo[gi])

indent(IDepth); print ">dep=" dep ", argsCnt[" gi "]=" argsCnt
# indent(IDepth); print ">dep=" dep ", argsCnt[" gi "]=" argsCnt

for (j=0; j < argsCnt; j++) {
depArg = DependencyArgs [gi,j]
depArgType = DependencyArgsType[gi,j]

indent(IDepth); print ">>@ " depArg " " depArgType
# indent(IDepth); print ">>@ " depArg " " depArgType

newArgs[GoalParams[dep,j]] = \
depArgType == "str" ? \
depArg : \
depArgType == "var" ? \
(depArg in args ? args[depArg] : addError("wrong arg '" depArg "'", DependenciesLineNo[gi])) : \
(depArg in args ? args[depArg] : addErrorDedup("wrong arg '" depArg "'", DependenciesLineNo[gi])) : \
die("wrong depArgType: " depArgType)
}

Expand Down
26 changes: 26 additions & 0 deletions tests/27_parameterized_goals.tush
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,29 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/27_parameterized_goals_9.sh 'greet2@John@'\'
| goal $'greet@\'quoted\'' ...
| hello 'quoted'
| goal $'greet2@John@\'quoted\'' [empty].

$ cd "$MYDIR"; ./$MAKESURE -f tests/27_parameterized_goals_10_errors.sh -l
@ Goal 'a' has unknown dependency 'unknown1':
@ tests/27_parameterized_goals_10_errors.sh:10: @depends_on unknown1 # err unknown dep
@ Goal 'a' has unknown dependency 'unknown2':
@ tests/27_parameterized_goals_10_errors.sh:11: @depends_on unknown2 @args 'arg2' # err unknown dep
@ wrong args count for 'b':
@ tests/27_parameterized_goals_10_errors.sh:5: @depends_on b # err missing args
@ wrong args count for 'e':
@ tests/27_parameterized_goals_10_errors.sh:19: @depends_on e @args WRONG3 WRONG4 # multiple errors
@ wrong arg 'WRONG3':
@ tests/27_parameterized_goals_10_errors.sh:19: @depends_on e @args WRONG3 WRONG4 # multiple errors
@ wrong arg 'WRONG4':
@ tests/27_parameterized_goals_10_errors.sh:19: @depends_on e @args WRONG3 WRONG4 # multiple errors
@ wrong arg 'WRONG2':
@ tests/27_parameterized_goals_10_errors.sh:15: @depends_on c @args WRONG2 # err unknown arg
@ wrong args count for 'b':
@ tests/27_parameterized_goals_10_errors.sh:6: @depends_on b @args # err missing args
@ wrong args count for 'b':
@ tests/27_parameterized_goals_10_errors.sh:7: @depends_on b @args 'hello' 'hi' # err more args than params
@ wrong arg 'WRONG1':
@ tests/27_parameterized_goals_10_errors.sh:8: @depends_on b @args WRONG1 # err unknown arg
@ wrong args count for 'e':
@ tests/27_parameterized_goals_10_errors.sh:9: @depends_on e @args 'arg1' # err args for non-PG
? 1

0 comments on commit beef41d

Please sign in to comment.