jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: Allow spaces in ${...} expressions around function calls.
Date Sat, 07 Mar 2020 13:46:52 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new 89ed2ef  Allow spaces in ${...} expressions around function calls.
89ed2ef is described below

commit 89ed2ef64bea7a082171ea8dcc1c9cb1a2e302bf
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Thu Mar 5 21:35:20 2020 +0100

    Allow spaces in ${...} expressions around function calls.
    
    With this change it is possible to write
    
     ${ __P(something, 1) }
    
    where such an expression would previously have resulted in an error.
    
    Bugzilla Id: 64198
---
 .../apache/jmeter/engine/util/FunctionParser.java  | 14 ++++-
 .../jmeter/engine/util/FunctionParserSpec.groovy   | 62 ++++++++++++++++++++++
 xdocs/changes.xml                                  |  1 +
 3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java b/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java
index 5c19d4e..8f5a16c 100644
--- a/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java
+++ b/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java
@@ -125,10 +125,10 @@ class FunctionParser {
                     buffer.append(current[0]);
                 } else if (current[0] == '(' && previous != ' ') {
                     String funcName = buffer.toString();
-                    function = CompoundVariable.getNamedFunction(funcName);
+                    function = CompoundVariable.getNamedFunction(funcName.trim());
                     if (function instanceof Function) {
                         ((Function) function).setParameters(parseParams(reader));
-                        if (reader.read(current) == 0 || current[0] != '}') {
+                        if (firstNonSpace(reader, '#') != '}') {
                             reader.reset();// set to start of string
                             char []cb = new char[100];
                             int nbRead = reader.read(cb);
@@ -162,6 +162,16 @@ class FunctionParser {
         return buffer.toString();
     }
 
+    private char firstNonSpace(StringReader reader, char defaultResult) throws IOException
{
+        char[] current = new char[1];
+        while (reader.read(current) == 1) {
+            if (!Character.isSpaceChar(current[0])) {
+                return current[0];
+            }
+        }
+        return defaultResult;
+    }
+
     /**
      * Compile a String into a list of parameters, each made into a
      * CompoundVariable.
diff --git a/src/core/src/test/groovy/org/apache/jmeter/engine/util/FunctionParserSpec.groovy
b/src/core/src/test/groovy/org/apache/jmeter/engine/util/FunctionParserSpec.groovy
new file mode 100644
index 0000000..5913437
--- /dev/null
+++ b/src/core/src/test/groovy/org/apache/jmeter/engine/util/FunctionParserSpec.groovy
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.engine.util
+
+import org.apache.jmeter.functions.Function
+import org.apache.jmeter.samplers.SampleResult
+import org.apache.jmeter.samplers.Sampler
+
+import spock.lang.Specification
+import spock.lang.Unroll
+
+@Unroll
+class FunctionParserSpec extends Specification {
+    def "function '#value' gets compiled"() {
+        given:
+            CompoundVariable.functions.put('__func', Func.class)
+            def parser = new FunctionParser()
+        when:
+            def result = parser.compileString(value)
+        then:
+            "$result" == "$expected"
+        where:
+            value           | expected
+            '${__func()}'   | [new Func()]
+            '${ __func()}'  | [new Func()]
+            '${__func() }'  | [new Func()]
+            '${ __func() }' | [new Func()]
+    }
+
+    public static class Func implements Function {
+        void setParameters(Collection params) {
+            // do nothing
+        }
+        String getReferenceKey() {
+            return "__func"
+        }
+        List<String> getArgumentDesc() {
+            return Collections.emptyList()
+        }
+        String execute(SampleResult result, Sampler sampler) {
+            return "done"
+        }
+        String toString() {
+            return "__func()"
+        }
+    }
+}
\ No newline at end of file
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 7ce5f34..4e1ac7d 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -123,6 +123,7 @@ to view the last release notes of version 5.2.1.
   <li><bug>63458</bug><pr>551</pr>Add new template "Functional
Testing Test Plan [01]". Contributed by Sebastian Boga (sebastian.boga at endava.com)</li>
   <li><bug>64119</bug>Use first renderer from <code>view.results.tree.renderers_order</code>
property as default in View Results Tree</li>
   <li><bug>64148</bug>Use gray icons for disabled elements in the tree,
display subtree as gray</li>
+  <li><bug>64198</bug>Allow spaces in <code>${...}</code> expressions
around functions.</li>
 </ul>
 
 <ch_section>Non-functional changes</ch_section>


Mime
View raw message