landro / TesTcl

when you don't have the balls to test your F5 BIG-IP iRules directly in production
https://testcl.com
BSD 3-Clause "New" or "Revised" License
98 stars 30 forks source link

Unexpected unknown command invocation 'class configure' #46

Closed carlpett closed 8 years ago

carlpett commented 8 years ago

Hi! I'm trying to follow the examples for classes from the documentation, but I can't get it to work. I'm getting syntax errors:

Unexpected unknown command invocation 'class configure blacklist {
    "blacklisted" "192.168.6.66"
  }'

Maybe you should add an "on" statement similar to the one below to your "it" block?

    it "your description" {
      ...
      on class configure blacklist {
    "blacklisted" "192.168.6.66"
  } return "your return value"
      ...
    }

I'm using jtcl 2.8.0 and testcl 1.0.8 on Java 1.8.0_60, and start jtcl like this: /opt/jdk/bin/java -DTCLLIBPATH=/jtcl/TesTcl -cp /jtcl/jtcl-irule.jar:/jtcl/jtcl-2.8.0.jar tcl.lang.Shell.

Some incompatibility with my versions, or error in the invocation?

carlpett commented 8 years ago

@jamespic: From the commit log, it looks like you contributed this functionality - thanks for the effort! Do you have any insight in what could cause this? I tried running the test/test_class.tcl file included in the release, and that does seem to work. However, it seems to be bypassing a lot of the "normal" import structure and instead including parts explicitly with source src/classes.tcl and so on. I'm guessing that is not what I as an end user should do?

jamespic commented 8 years ago

@carlpett It's been a while since I worked with the codebase, and my Tcl isn't that strong (I basically learned just enough to solve our problem, on the project where I used this), but my recollection is that we used explicit source src/classes.tcl in our code.

I could readily believe that that's not the Tcl way, so feel free to refactor it to be more idiomatic.

carlpett commented 8 years ago

@jamespic Thanks for the quick reply! I'm basically in the same boat, no tcl knowledge outside the quite simple stuff in irules. I'll try and see if I can get my rules and tests working by adding source then. @landro: If this is how it is meant to be done, I could try to update the examples?

landro commented 8 years ago

@carlpett the way users should write tests, is by following the pattern found in the examples folder. The stuff found in tests is for testing the TesTcl itself (consider them unit-tests).

TesTcl heavily relies on the "unknown" command, which kicks in whenever an unknown/undefined proc is called, in this case the class command. I'll quickly check @jamespic's code to see if I can sort out what's going on. Stay tuned.

nickm4062 commented 8 years ago

👍

landro commented 8 years ago

@carlpett Could you please test the classes_fix branch and see if it works for you? I added an example that show how end users should use this functionality, see examples directory

carlpett commented 8 years ago

@landro It works! Thanks a lot, great work!

landro commented 8 years ago

fixed in 99ab81f78a45774fa6df4bd17d30a9051f7e3c16