[1.9-16apr] $0 is messed up

S

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.

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.

server> ruby a.rb
"a.rb"
server> cat a.rb
require 'b'
class C
include M
end
C.new.m
server> cat b.rb
module M
def m
p $0
end
end
server>


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.
 
S

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

server> 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)
server> 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
server> ruby -v
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]
server>
 
S

Simon Strandgaard

T

ts

S> 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%

server> ruby tester.rb
S> "tester.rb"
S> Loaded suite Tester
S> Started
S> "tester.rb\000test_filename(Tester)"
S> ..
S> 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"
 
S

Simon Strandgaard

S> Try this piece of code

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

server> 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
server> ruby -v
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]
server>

[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 ?
 
T

ts

S> Same versions.. different results.
S> 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
 
S

Simon Strandgaard

S> Same versions.. different results.
S> 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%

server> 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
server>

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 ?
 
T

ts

server> ruby -v
S> 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)"
 
S

Simon Strandgaard

server> ruby -v
S> 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?
 
T

ts

S> Apparently there is also a problem with print,

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


Guy Decoux
 
S

Simon Strandgaard

S> Apparently there is also a problem with print,

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

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?
 
T

ts

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

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

Guy Decoux
 
S

Simon Strandgaard

S> I guess \0 slips through 'p', and is outputted/interpreted by the
S> system console. I think 'p' should do escaping to prevent such
S> 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 #


server> ruby -ve '$0="x\0x"; p $0'
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]
"x\000x"
server> ruby18 -ve '$0="x\0x"; p $0'
ruby 1.8.1 (2003-12-22) [i386-freebsd5.1]
"x\000x"
server>
 
S

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

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

Ollivier Robert

[copy in case the GW is down]

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


server> ruby -ve '$0="x\0x"; p $0'
ruby 1.9.0 (2004-04-16) [i386-freebsd5.1]
"x\000x"
server> ruby18 -ve '$0="x\0x"; p $0'
ruby 1.8.1 (2003-12-22) [i386-freebsd5.1]
"x\000x"
server>

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ASP.NET File Download messed up 0
$0 is truncated 8
[CHALLENGE] better alias_method 23
Faster Prime class then Ruby 1.9 0
[ANN] slave-1.2.1 1
[ANN] pervasives-1.1.0 1
override.rb 13
ANN main-4.4.0 0

Members online

Forum statistics

Threads
474,145
Messages
2,570,824
Members
47,371
Latest member
Brkaa

Latest Threads

Top