question

dclaar avatar image
dclaar Suspended asked dclaar Suspended posted

Valid variable names in iTest?

In SVT, the rules for variables were that of TCL. Is that true in iTest? For example, in SVT, you could set _foo {bah}, and then reference

^{e:$foo}. What about iTest?

iTestFanfareSVT to iTest Migration
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

PaulD avatar image
PaulD answered PaulD posted

iTest still supports Tcl integration if you prefer to use that.  In iTest, the equivalent to ^{e:$foo} is now [tclexpr {$foo}].  And the equivalent of ^{t:set foo bar} is [tcl {set foo bar}].

 

However iTest now has its own data model and procedural context independent of Tcl.  This make a lot of new things possible while also simplifying the syntax for a lot of common cases.  The syntax for accessing the iTest commands and data model is identical to Tcl.  (But it is important to understand that iTest's data model and commands are not Tcl.)

 

In most string properties in iTest, you can use field substitution like you can in FanfareSVT,  but now you use Tcl's syntax for these substitutions rather than the proprietary syntax used in FanfareSVT.  So where you used to say, for example,

 

Session:  s1

Action:  command

Command:   show interface $portNumber

 

where in FanfareSVT, you would have used

 

Command:  show interface ^{e:$portNumber}

 

And if you want to fetch a parameter, for example, in iTest, you now say,

 

Command:  show interface [param port_number]

 

where in FanfareSVT you would have said

 

Command:  show interface ^{p:port_number}

 

One of the ways in which this improves things is that the syntax in FanfareSVT becomes complex or ambiguous where you get into nested substitutions.  And combining that with expression logic made it almost impossible to decode in FanfareSVT.  With iTest, it becomes simpler.  For example, you might want to perform some more complex logic in the substitution like:

 

Command:  show interface [expr [param $port_param_name] + $i * 2]

 

 

6 comments
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dclaar avatar image dclaar commented ·

None of these answer the real question, which I was obviously unclear about. What are the naming rules? Are any of these valid?

$_foo

$456

$_this-is#the!one 

The first one is valid in TCL, the rest I just made up... :smileywink:

 

0 Likes 0 ·
PaulD avatar image PaulD commented ·
Sorry.  The naming rules for iTest variables are more restrictive than for Tcl.  We use an underlying XML model for data, and therefore variables need to respect XML's naming rules for elements and attributes.  You can see these rules documented at here
0 Likes 0 ·
dclaar avatar image dclaar PaulD commented ·

O, be some other name! What's in a name? that which we call a rose

By any other name would smell as sweet;

So _foo would, were it not underscore started.

0 Likes 0 ·
KumarS avatar image KumarS dclaar commented ·
An XML node can start with "_" so "_foo" is allowed.
0 Likes 0 ·
dclaar avatar image dclaar PaulD commented ·

Hmm. According to http://www.w3schools.com/XML/xml_elements.asp:

 

  • Names can contain letters, numbers, and other characters
  • Names must not start with a number or punctuation character
  • Names must not start with the letters xml (or XML, or Xml, etc)
  • Names cannot contain spaces
  •  

    So, _foo would be ruled out by the second rule.

0 Likes 0 ·
PaulD avatar image PaulD dclaar commented ·
That reference I sent used the word "punctuation" rather loosely.  The formal spec is here.  You'll see that you're allowed to start with an underscore.  Sorry for the confusion.
0 Likes 0 ·
KumarS avatar image
KumarS answered KumarS posted

iTest has its own concept of variables and uses tcl syntax to set them. So you can still set a variable by doing:

 

set foo 1

 

But to access these, you do not have to do ^{e:$foo}. You simply type $foo where you want to use the variable.

 

Note that you can still use a tcl interpreter to store your variable by using "scriptEval" action. Then there are two ways to get the variable to and from tcl intepreter to iTest: using scriptGet and scriptSet actions. See iTest help for more details on these. You can also use command called [tcl ...] to execute any tcl command and get its results as a field substitution. 

 

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.