Fix VELOCITY-944
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
index ada01e6..e77f2df 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
@@ -1499,6 +1499,7 @@ public boolean render(Context context, Writer writer,
 
         try
         {
+            ica.setCurrentResource(nodeTree.getTemplate());
             try
             {
                 nodeTree.init(ica, this);
@@ -1554,6 +1555,7 @@ public boolean render(Context context, Writer writer,
         finally
         {
             ica.popCurrentTemplateName();
+            ica.setCurrentResource(null);
             if (isScopeControlEnabled(evaluateScopeName))
             {
                 Object obj = ica.get(evaluateScopeName);
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java
index 63dc92b..d4dbcbf 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java
@@ -36,7 +36,7 @@
  *
  * <ul>
  * <li>flat - all allowable VMs are in the global namespace</li>
- * <li>local - inline VMs are added to it's own template namespace</li>
+ * <li>local - inline VMs are added to their own template namespace</li>
  * </ul>
  *
  * Thanks to <a href="mailto:JFernandez@viquity.com">Jose Alberto Fernandez</a>
@@ -190,7 +190,7 @@ public VelocimacroProxy get(final String vmName, final Template renderingTemplat
         if( usingNamespaces() && template != null )
         {
             MacroEntry me = (MacroEntry)template.getMacros().get(vmName);
-            if( template.getMacros().size() > 0 && me != null )
+            if(!template.getMacros().isEmpty() && me != null )
             {
                 return me.getProxy();
             }
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/BaseTestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/BaseTestCase.java
index 1d43a83..9f5b67f 100644
--- a/velocity-engine-core/src/test/java/org/apache/velocity/test/BaseTestCase.java
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/BaseTestCase.java
@@ -113,10 +113,10 @@ protected StringResourceRepository getStringRepository()
         return repo;
     }
 
-    protected void addTemplate(String name, String template)
+    protected void addTemplate(String name, String vtl)
     {
-        info("Template '"+name+"':  "+template);
-        getStringRepository().putStringResource(name, template);
+        info("Template '"+name+"':  "+vtl);
+        getStringRepository().putStringResource(name, vtl);
     }
 
     protected void removeTemplate(String name)
@@ -202,18 +202,18 @@ protected void assertContextValue(String key, Object expected)
     /**
      * Ensure that a template renders as expected.
      */
-    protected void assertEvalEquals(String expected, String template)
+    protected void assertEvalEquals(String expected, String vtl)
     {
-        assertEvalEquals(expected, template, engine);
+        assertEvalEquals(expected, vtl, engine);
     }
 
     /**
      * Ensure that a template renders as expected against the provided engine.
      */
-    protected void assertEvalEquals(String expected, String template, VelocityEngine ve)
+    protected void assertEvalEquals(String expected, String vtl, VelocityEngine ve)
     {
         info("Expectation: "+expected);
-        assertEquals(expected, evaluate(template, ve));
+        assertEquals(expected, evaluate(vtl, ve));
     }
 
     /**
@@ -314,25 +314,25 @@ protected Exception assertEvalExceptionAt(String evil, int line, int col)
     /**
      * Evaluate the specified String as a template and return the result as a String.
      */
-    protected String evaluate(String template)
+    protected String evaluate(String vtl)
     {
-        return evaluate(template, engine);
+        return evaluate(vtl, engine);
     }
 
     /**
      * Evaluate the specified String as a template against the provided engine and return the result as a String.
      */
-    protected String evaluate(String template, VelocityEngine ve)
+    protected String evaluate(String vtl, VelocityEngine ve)
     {
         StringWriter writer = new StringWriter();
         try
         {
-            info("Template: "+template);
+            info("Template: "+vtl);
 
             // use template as its own name, since our templates are short
             // unless it's not that short, then shorten it...
-            String name = (template.length() <= 15) ? template : template.substring(0,15);
-            ve.evaluate(context, writer, name, template);
+            String name = (vtl.length() <= 15) ? vtl : vtl.substring(0,15);
+            ve.evaluate(context, writer, name, vtl);
 
             String result = writer.toString();
             info("Result: "+result);
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity944TestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity944TestCase.java
new file mode 100644
index 0000000..b3169c9
--- /dev/null
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity944TestCase.java
@@ -0,0 +1,50 @@
+package org.apache.velocity.test.issues;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
+import org.apache.velocity.runtime.resource.util.StringResourceRepository;
+import org.apache.velocity.test.BaseTestCase;
+
+public class Velocity944TestCase extends BaseTestCase {
+    public Velocity944TestCase(String name) {
+        super(name);
+    }
+
+    @Override
+    protected void setUpEngine(VelocityEngine engine) {
+        engine.setProperty("velocimacro.inline.local_scope", "true");
+    }
+
+    @Override
+    protected void setUpContext(VelocityContext context) {
+        context.put("someObj", new SomeClass());
+    }
+
+    public void testVelocity944StringLiteral() throws Exception {
+        assertEvalEquals(
+                "<span>foo</span> some text <span>bar</span>",
+                "#macro( m $v )<span>$v</span>#end#m( 'foo' ) some text #set($str=\"#m( 'bar' )\")$str"
+        );
+    }
+
+    public void testVelocity944ReferenceArgument() throws Exception {
+        assertEvalEquals(
+                "<span>foo</span> some text <span>bar</span>",
+                "#macro( m $v )<span>$v</span>#end#m( 'foo' ) some text ${someObj.someMethod(\"#m( 'bar' )\")}"
+        );
+    }
+
+    public void testVelocity944LoadedTemplate() throws Exception {
+        addTemplate("velocity944", "#macro( m $v )<span>$v</span>#end#m( 'foo' ) some text ${someObj.someMethod(\"#m( 'bar' )\")}");
+        assertTmplEquals("<span>foo</span> some text <span>bar</span>", "velocity944");
+    }
+
+    public static class SomeClass
+    {
+        public String someMethod(final String value)
+        {
+            return value;
+        }
+    }
+}