diff --git a/backend/src/main/scala/com/griddynamics/genesis/template/dsl/groovy/transformations/MacroASTTransformation.scala b/backend/src/main/scala/com/griddynamics/genesis/template/dsl/groovy/transformations/MacroASTTransformation.scala index 64170bac7..beec21f02 100644 --- a/backend/src/main/scala/com/griddynamics/genesis/template/dsl/groovy/transformations/MacroASTTransformation.scala +++ b/backend/src/main/scala/com/griddynamics/genesis/template/dsl/groovy/transformations/MacroASTTransformation.scala @@ -138,6 +138,7 @@ class MacroExpandVisitor(val macrodefs: Map[String, Macro], replacements: mutabl case closure: ClosureExpression => copyClosureExpression(closure) case arguments: ArgumentListExpression => new ArgumentListExpression(arguments.getExpressions.map(copy)) case mapEntry: MapEntryExpression => new MapEntryExpression(copy(mapEntry.getKeyExpression), copy(mapEntry.getValueExpression)) + case prop: PropertyExpression => new PropertyExpression(copy(prop.getObjectExpression), copy(prop.getProperty)) } private def copyClosureExpression(closure: ClosureExpression): ClosureExpression = { diff --git a/backend/src/test/resources/groovy/Macros.genesis b/backend/src/test/resources/groovy/Macros.genesis index 788ea97d6..40cdddacf 100644 --- a/backend/src/test/resources/groovy/Macros.genesis +++ b/backend/src/test/resources/groovy/Macros.genesis @@ -22,11 +22,18 @@ template { defmacro "map": { $key, $mapValue -> withMap { - text = "Test" + text = $vars.myvar map = { [ $key: $mapValue ] } } } + defmacro "defvar": { $name -> + $name = { + description = "Variable from template" + isOptional = false + } + } + defmacro "bad_require": { $message -> require { $message { 1 == 2 } @@ -47,6 +54,9 @@ template { } workflow("maps") { + variables { + macro:defvar(myvar) + } steps { macro:map("operation", "subst") } diff --git a/backend/src/test/scala/com/griddynamics/genesis/service/impl/MacrosTest.scala b/backend/src/test/scala/com/griddynamics/genesis/service/impl/MacrosTest.scala index 617ec646f..8ef877679 100644 --- a/backend/src/test/scala/com/griddynamics/genesis/service/impl/MacrosTest.scala +++ b/backend/src/test/scala/com/griddynamics/genesis/service/impl/MacrosTest.scala @@ -14,7 +14,7 @@ import com.griddynamics.genesis.cache.NullCacheManager import com.griddynamics.genesis.template.VersionedTemplate import com.griddynamics.genesis.api import com.griddynamics.genesis.plugin.{StepBuilderFactory, StepBuilder} -import com.griddynamics.genesis.service.TemplateDefinition +import com.griddynamics.genesis.service.{VariableDescription, TemplateDefinition} import com.griddynamics.genesis.api.Failure import com.griddynamics.genesis.workflow.Step import scala.beans.BeanProperty @@ -65,9 +65,15 @@ class MacrosTest extends AssertionsForJUnit with MockitoSugar with DSLTestUniver def testMacroWithMap() { val template: Option[TemplateDefinition] = templateService.findTemplate(0, "Macros", "0.1", 0) val result = template.get.getWorkflow("maps").get - val steps = result.embody(Map()) - val values: Map[String, String] = steps.regular(0).newStep.actualStep.asInstanceOf[StepWithMap].values + val steps = result.embody(Map("myvar" -> "1024")) + val variables: Seq[VariableDescription] = result.variableDescriptions + assert(variables.size == 1) + assert(variables.exists(_.name == "myvar")) + val step: StepWithMap = steps.regular(0).newStep.actualStep.asInstanceOf[StepWithMap] + val values: Map[String, String] = step.values + val text = step.name expectResult(Map("operation" -> "subst"))(values) + expectResult("1024")(text) } }