I like that–in fact, I’d probably use it. What happens if there are
multiple TEST{} blocks (especially in required files)? Do they all get
executed?
I would suggest yes. Perhaps -t and -tr (e.g., -t only runs the last; -tr
runs all). What was brought up on #ruby-lang is whether the TEST {} blocks
would be exclusive, overriding normal behaviour. This may be desirable.
Exclusive, meaning regular code (ie, code outside of TEST{}) would not
run? I don’t know if I like that. If that’s what is needed, then it
sounds like what is really needed is better separation of real and test
code.
I can see the value of TEST{}. But if you need something that only gets
run during testing, and excludes the real application code… I don’t
know if such a language construct belongs in Ruby. Seems too specific
to me.
On a slightly related, albeit more general, note: what if there were a
mechanism whereby the invoked script could handle options that were
passed to the Ruby interpreter, and which the interpreter didn’t
understand? That is to say, instead of making -t and -tr actual flags
in the interpreter, what if it were possible to make them accessible to
(for instance) a module that the script ‘requires’? Then the script
could set a $TEST flag, define the behavior of the TEST method, and have
all TEST{} blocks be executed when the script is run, as long as -t was
passed to the interpreter.
Perhaps it’s just too late and I need to go to bed.
Not quite sure what you mean by "exclusive". Do you mean it would ignore
anything not in some TEST{} block? Then it would be useless for putting
unit-tests in the same file as classes/modules under test. Again, in my
experience, that would make TEST{} useless.
Joseph Beckenbach
lead XP tester, Eidogen Inc.
···
On Thu, 11 Dec 2003 12:38:37 +0900, Jamis Buck wrote:
I would suggest yes. Perhaps -t and -tr (e.g., -t only runs the last; -tr
runs all). What was brought up on #ruby-lang is whether the TEST {} blocks
would be exclusive, overriding normal behaviour. This may be desirable.
This behavior of test/unit could be modified if TEST { } existed. The
main idea TEST { } was as a replacement for if $0 == FILE when used
for testing (like in some files in the Ruby standard library).
It could be used for running unit tests, but I’ve found it easier to
place them in their own files and run the tests separately.
You can put a “comment” down the bottom (or top if you wish):
vim: filetype=ruby
or
vim: ft=ruby
Gavin
···
On Friday, December 12, 2003, 5:37:17 AM, Mike wrote:
This scheme works well for me, the only thing I need to remember is
that when I start a new program without a suffix then gvim doesn’t
syntax highlight.