This functions checks if variable isVarDefined - __isVarDefined(varName) It would return true or false
what about property? should we have another parameter to allow checking is property defined?
(In reply to orimarko from comment #1) > what about property? should we have another parameter to allow checking is > property defined? Don't know if it's really useful , in this case functions should be named: __isSet(boolean isVar, String varOrProp) isVar : true or false Thoughts ?
I think that in general having flags to change function behaviour can be confusing, if they are boolean, what do they mean (when reading the code) and if they are strings or something, how do we find out what we should use? I presume most of the time you don't care if it's a var or property? I think that simply, __isDefined(varOrPropName) is best, unless more complex knowledge is required. If vars and props can have the same name and you care about only the one being defined, how about: __isVarDefined(name) __isPropDefined(name) or if they cannot have the same name, maybe: __isDefined(varOrPropName) - true or false if var or prop is defined and __isVar(name) and __isProp(name) if you then care about the difference once you've done but this wouldn't work very well if both are defined and you are trying to find out which is defined, but that doesn't seem to be the use case here anyway.
(In reply to Graham Russell from comment #3) > I think that in general having flags to change function behaviour can be > confusing, if they are boolean, what do they mean (when reading the code) > and if they are strings or something, how do we find out what we should use? > Function Helper Dialog can describe this. We could use a mode instead of boolean. > I presume most of the time you don't care if it's a var or property? Not sure. User may have named by error a property and a variable the same. > > I think that simply, __isDefined(varOrPropName) is best, unless more complex > knowledge is required. > > If vars and props can have the same name and you care about only the one > being defined, how about: > __isVarDefined(name) > __isPropDefined(name) Yes, my idea was just to avoid having too many functions. > > or if they cannot have the same name, maybe: > __isDefined(varOrPropName) - true or false if var or prop is defined > and This name is already taken by jmeter-plugins functions. > __isVar(name) and __isProp(name) if you then care about the difference once > you've done but this wouldn't work very well if both are defined and you are > trying to find out which is defined, but that doesn't seem to be the use > case here anyway. But intuitively, I would say that this function tells me if name is a property or a variable, not if it's defined. So I would end up to the following: - Option 1 : isVarDefined / isPropDefined - Option 2 : isSet(MODE, name), where mode is Property, Variable Except for the additional function I feel Option 1 is better
I accept your suggestion and think isPropDefined is a good addition, I wanted to point out that __V function code will be almost equal to isVarDefined except return true/false instead of the value. Can __V function be added is defined 2nd parameter, and if it's true return true/false instead of the value (default false as now)?
(In reply to orimarko from comment #5) > I accept your suggestion and think isPropDefined is a good addition, > I wanted to point out that __V function code will > be almost equal to isVarDefined except return true/false instead of the > value. > > Can __V function be added is defined 2nd parameter, and if it's true return > true/false instead of the value (default false as now)? I prefer a more meaningful name in fact. So let's go for a new function.
Created attachment 35537 [details] Add patch with 2 functions, tests and xdocs
Author: pmouawad Date: Sun Nov 19 11:04:53 2017 New Revision: 1815725 URL: http://svn.apache.org/viewvc?rev=1815725&view=rev Log: Bug 61760 - Add "__isPropDefined" and "__isVarDefined" functions to know if property or variable exist Contributed by Orimarko Bugzilla Id: 61760 Added: jmeter/trunk/src/functions/org/apache/jmeter/functions/IsPropDefined.java (with props) jmeter/trunk/src/functions/org/apache/jmeter/functions/IsVarDefined.java (with props) jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsPropDefined.java (with props) jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsVarDefined.java (with props) Modified: jmeter/trunk/xdocs/changes.xml jmeter/trunk/xdocs/usermanual/functions.xml
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/4588