[1.9-16apr] $0 is messed up

I have just upgraded to 1.9 16-apr-2004 from 1.9 7-apr-2004.

One of my testsuites is no longer working, which worked
with the previous version. It shows up that $0 is cluttered
up.

I have placed a ‘p’ statement before the place where I
read $0. It outputs

“test_engine_builtin.rb\000test_rubicon(XTestEngineBuiltin)”

The /\000.*$/ shouldn’t be there.
The code looks like

def test_rubicon
file_name = nil
p $0
start = File.dirname($0) # BOOM null is not understood.
for base in [“.”, “language”]

In the changelog there seems to have been many changes
recently to the dir handling. I wonder if that could be
the reason?

I tried to make a small piece of code which could reproduce
the problem. But the problem seems only to be provoked when I do
a test_all.

ruby a.rb
“a.rb”
cat a.rb
require ‘b’
class C
include M
end
C.new.m
cat b.rb
module M
def m
p $0
end
end

Today is devoted to make a working proof of concept, which
can provoke the problem. Though I hope someone is able to
recognize the problem before then.

···


Simon Strandgaard

I have just upgraded to 1.9 16-apr-2004 from 1.9 7-apr-2004.

One of my testsuites is no longer working, which worked
with the previous version. It shows up that $0 is cluttered
up.

Ok… I have tracked it down. The problem seems to be located in
Test::Unit.

Try this piece of code

expand -t2 tester.rb
p $0
require ‘test/unit’

class Tester < Test::Unit::TestCase
def test_filename
p $0 # BOOM
end
end

require ‘test/unit/ui/console/testrunner’
Test::Unit::UI::Console::TestRunner.run(Tester)

ruby tester.rb
“tester.rb”
Loaded suite Tester
Started
“tester.rb\000test_filename(Tester)”

Finished in 0.003582 seconds.

1 tests, 0 assertions, 0 failures, 0 errors

ruby -v
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]

···

On Sat, 17 Apr 2004 15:20:09 +0200, Simon Strandgaard wrote:


Simon Strandgaard

Try this piece of code

svg% cat b.rb
p $0
require 'test/unit'

class Tester < Test::Unit::TestCase
  def test_filename
    p $0 # BOOM
  end
end

require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(Tester)
svg%

ruby tester.rb
"tester.rb"
Loaded suite Tester
Started
"tester.rb\000test_filename(Tester)"
..
Finished in 0.003582 seconds.

svg% ruby -v b.rb
ruby 1.9.0 (2004-04-16) [i686-linux]
"b.rb"
Loaded suite Tester
Started
"b.rb"
.
Finished in 0.001155 seconds.

1 tests, 0 assertions, 0 failures, 0 errors
svg%

Guy Decoux

Found some explanation:

http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/test/unit/ui/console/testrunner.rb

see revision 1.6:

  • lib/test/unit/ui/console/testrunner.rb (test_started): show test
    name via $0.

ATT: Nobu
I think its a bad idea to use global variables for this.
Wouldn’t it be better to have a instance variable with such info.
For instance ‘@test_name’… would be lot better.

···

On Sat, 17 Apr 2004 15:46:01 +0200, Simon Strandgaard wrote:

On Sat, 17 Apr 2004 15:20:09 +0200, Simon Strandgaard wrote:

I have just upgraded to 1.9 16-apr-2004 from 1.9 7-apr-2004.

One of my testsuites is no longer working, which worked
with the previous version. It shows up that $0 is cluttered
up.

Ok… I have tracked it down. The problem seems to be located in
Test::Unit.


Simon Strandgaard

ruby -v
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]

                                 ^^^^^^^
                                 ^^^^^^^
obsd% cat b.rb
p $0
require 'test/unit'

class Tester < Test::Unit::TestCase
  def test_filename
    p $0 # BOOM
  end
end

require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(Tester)
obsd%

obsd% ruby -v b.rb
ruby 1.9.0 (2004-04-16) [sparc-openbsd3.4]
"b.rb"
Loaded suite Tester
Started
"b.rb\000test_filename(Tester)"
.
Finished in 0.050525 seconds.

1 tests, 0 assertions, 0 failures, 0 errors
obsd%

Guy Decoux

p.s. : see the time (SS10 - 40 Mhz - 1992 :-))

Try this piece of code

Ok… this is a copy/paste of you suggested code

ruby a.rb
“a.rb”
Loaded suite Tester
Started
“a.rb\000test_filename(Tester)”

Finished in 0.003492 seconds.

1 tests, 0 assertions, 0 failures, 0 errors

ruby -v
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]

[snip]

svg% ruby -v b.rb
ruby 1.9.0 (2004-04-16) [i686-linux]
“b.rb”
Loaded suite Tester
Started
“b.rb”

Same versions… different results.
I guess your ‘lib/test/unit/ui/console’ dir isn’t uptodate ?

···

On Sat, 17 Apr 2004 23:12:18 +0900, ts wrote:


Simon Strandgaard

ruby -v
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]
^^^^^^^
^^^^^^^
[snip]
obsd% ruby -v b.rb
ruby 1.9.0 (2004-04-16) [sparc-openbsd3.4]
“b.rb”
Loaded suite Tester
Started
“b.rb\000test_filename(Tester)”

Apparently there is also a problem with print,
as indicated by Decoux. Where \0 is interpreted differently
on linux, compared to sparc, freebsd.

The other problem is that Test::Unit recently has
begun showing the test-name via the $0 variable.
Which is bad. May I propose to introduce a instance
variable ‘@test_name’ for that, instead of touching
the $0 global variable.

Comments about these 2 issues?

···

On Sun, 18 Apr 2004 00:12:31 +0900, ts wrote:


Simon Strandgaard

Found some explanation:

http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/test/unit/ui/console/testrunner.rb

see revision 1.6:

  • lib/test/unit/ui/console/testrunner.rb (test_started): show test
    name via $0.

ATT: Nobu
I think its a bad idea to use global variables for this.
Wouldn’t it be better to have a instance variable with such info.
For instance ‘@test_name’… would be lot better.

I mailed Nathaniel Talbott about it:

Well, I think I understand why it was changed (although I didn’t make
the change)… if you set the $0 variable, then ps, top, etc., will
display that value when you do a process listing. I know I’ve found
that to be handy for some processes myself. So it seems the serious
issue might be the weird output you’re ending up with, as opposed to
setting $0. But Nobu’s really the one to make the final call on it, as
he put that change in.

Now it makes much more sense… However I still wish
that $0 would be untouched by Test::Unit.

···

On Sat, 17 Apr 2004 16:10:19 +0200, Simon Strandgaard wrote:


Simon Strandgaard

Same versions.. different results.
I guess your 'lib/test/unit/ui/console' dir isn't uptodate ?

svg% ls -l
total 8
drwxrwxr-x 2 ts ts 4096 Apr 17 15:05 CVS/
-rw-rw-r-- 1 ts ts 3841 Apr 17 15:05 testrunner.rb
svg%

Guy Decoux

Apparently there is also a problem with print,

Probably I'm wrong but this has nothing to do with print ...

Guy Decoux

Same versions… different results.
I guess your ‘lib/test/unit/ui/console’ dir isn’t uptodate ?

svg% ls -l
total 8
drwxrwxr-x 2 ts ts 4096 Apr 17 15:05 CVS/
-rw-rw-r-- 1 ts ts 3841 Apr 17 15:05 testrunner.rb
svg%

ls -la
total 10
drwxr-xr-x 3 neoneye neoneye 512 Apr 17 15:28 ./
drwxr-xr-x 9 neoneye neoneye 512 Apr 17 15:28 …/
drwxr-xr-x 2 neoneye neoneye 512 Apr 17 15:28 CVS/
-rw-r–r-- 1 neoneye neoneye 3841 Apr 8 12:45 testrunner.rb

Mine is form 8th April, which corresponds to the latest revision (1.6)
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/test/unit/ui/console/testrunner.rb

I don’t know why yours shows 17th april ?

···

On Sat, 17 Apr 2004 23:28:04 +0900, ts wrote:


Simon Strandgaard

I guess \0 slips through ‘p’, and is outputted/interpreted by the
system console. I think ‘p’ should do escaping to prevent such
hiding of information (on linux).

Isn’t it something which should be fixed?

···

On Sun, 18 Apr 2004 00:38:48 +0900, ts wrote:

Apparently there is also a problem with print,

Probably I’m wrong but this has nothing to do with print …


Simon Strandgaard

I guess \0 slips through 'p', and is outputted/interpreted by the
system console. I think 'p' should do escaping to prevent such
hiding of information (on linux).

$0 is a special variable and linux and *BSD have some differences ...

Guy Decoux

I guess \0 slips through ‘p’, and is outputted/interpreted by the
system console. I think ‘p’ should do escaping to prevent such
hiding of information (on linux).

$0 is a special variable and linux and *BSD have some differences …

Guy Decoux

It seems that you are right… indeed $0 is strange

ask > ./ruby -e ‘x=“x\0x”; p x’
“x\000x”
ask > ./ruby -ve ‘$0=“x\0x”; p $0’
ruby 1.6.6 (2001-12-26) [i686-linux]
“x”
ask >

guldfaxe 35 # ./ruby -ve ‘$0=“x\0x”; p $0’
ruby 1.6.6 (2001-12-26) [sparc-solaris2.8]
“x”
guldfaxe 36 #

ruby -ve ‘$0=“x\0x”; p $0’
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]
“x\000x”
ruby18 -ve ‘$0=“x\0x”; p $0’
ruby 1.8.1 (2003-12-22) [i386-freebsd5.1]
“x\000x”

···

On Sun, 18 Apr 2004 00:56:50 +0900, ts wrote:


Simon Strandgaard

[copy in case the GW is down]

In article pan.2004.04.17.15.18.10.340319@adslhome.dk,

···

Simon Strandgaard neoneye@adslhome.dk wrote:

guldfaxe 35 # ./ruby -ve ‘$0=“x\0x”; p $0’
ruby 1.6.6 (2001-12-26) [sparc-solaris2.8]
“x”
guldfaxe 36 #

ruby -ve ‘$0=“x\0x”; p $0’
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]
“x\000x”
ruby18 -ve ‘$0=“x\0x”; p $0’
ruby 1.8.1 (2003-12-22) [i386-freebsd5.1]
“x\000x”

The FreeBSD behaviour seems correct to me, I do not see anything that says
that #p should not display the “\0”.

Ollivier ROBERT -=- EEC/AMI -=- ollivier.robert@eurocontrol.int
Usenet Canal Historique FreeBSD: The Power to Serve!