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 24, 2023
1 parent 77b4f92 commit 3e00dfa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/parameterized_goals.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ Should work as expected. `@doc` should just copy to instantiated goals.
- [ ] handle + test w/ `@private`
- [ ] test w/ `@lib`
- [ ] test w/ `@doc`
- [ ] handle + test w/ `@reached_if`
- [x] handle + test w/ `@reached_if`
- [ ] test w/ `@glob` (should be covered by `@params` at pos 3 check)
- [ ] README.md
12 changes: 8 additions & 4 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,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
function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInstantiated,argsCnt,gi,gii,argsCode) { # -> goalNameInstantiated
# indent(IDepth++); print "instantiating " goal " { " renderArgs(args) "} ..."

goalNameInstantiated = instantiateGoalName(goal, args)
Expand All @@ -638,13 +638,17 @@ function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInst
copyKey(goal,goalNameInstantiated,GoalsByName)
copyKey(goal,goalNameInstantiated,DependenciesCnt)
copyKey(goal,goalNameInstantiated,CodePre)
for (i in args) {
CodePre[goalNameInstantiated] = addL(CodePre[goalNameInstantiated], i "=" quoteArg(args[i]))
}
copyKey(goal,goalNameInstantiated,Code)
copyKey(goal,goalNameInstantiated,Doc)
copyKey(goal,goalNameInstantiated,ReachedIf)
copyKey(goal,goalNameInstantiated,GoalToLib)

for (i in args)
argsCode = addL(argsCode, i "=" quoteArg(args[i]))

CodePre[goalNameInstantiated] = addL(CodePre[goalNameInstantiated], argsCode)
if (goalNameInstantiated in ReachedIf)
ReachedIf[goalNameInstantiated] = argsCode "\n" ReachedIf[goalNameInstantiated]
}

for (i=0; i < DependenciesCnt[goal]; i++) {
Expand Down
7 changes: 7 additions & 0 deletions tests/27_parameterized_goals.tush
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,10 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/27_parameterized_goals_10_errors.sh -l
@ tests/27_parameterized_goals_10_errors.sh:9: @depends_on e @args 'arg1' # err args for non-PG
? 1

$ cd "$MYDIR"; ./$MAKESURE -f tests/27_parameterized_goals_11_reached_if.sh a
| goal 'b@hi' ...
| W is hi
| goal 'b@hello' [already satisfied].
| goal 'b@salut' ...
| W is salut
| goal 'a' [empty].
10 changes: 10 additions & 0 deletions tests/27_parameterized_goals_11_reached_if.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

@goal a
@depends_on b @args 'hi'
@depends_on b @args 'hello'
@depends_on b @args 'salut'


@goal b @params W
@reached_if [[ "$W" == 'hello' ]]
echo "W is $W"

0 comments on commit 3e00dfa

Please sign in to comment.