[#4076] Ruby/DL — Jamis Buck <jamis_buck@...>

I recently used Ruby/DL to create bindings to the SQLite3 embedded

40 messages 2005/01/03
[#4096] Re: Ruby/DL — Paul Brannan <pbrannan@...> 2005/01/04

On Tue, Jan 04, 2005 at 02:53:49AM +0900, Jamis Buck wrote:

[#4099] Re: Ruby/DL — ts <decoux@...> 2005/01/04

>>>>> "P" == Paul Brannan <pbrannan@atdesk.com> writes:

[#4119] Re: Ruby/DL — Paul Brannan <pbrannan@...> 2005/01/05

On Wed, Jan 05, 2005 at 03:05:48AM +0900, ts wrote:

[#4120] Re: Ruby/DL — ts <decoux@...> 2005/01/05

>>>>> "P" == Paul Brannan <pbrannan@atdesk.com> writes:

[#4125] Re: Ruby/DL — Paul Brannan <pbrannan@...> 2005/01/05

On Thu, Jan 06, 2005 at 01:10:34AM +0900, ts wrote:

[#4116] Test::Unit::Collector::Dir won't work with code that modifies $LOAD_PATH — Eric Hodel <drbrain@...7.net>

Any test code that depends upon modifications of $: fails when used

10 messages 2005/01/05

[#4146] The face of Unicode support in the future — Charles O Nutter <headius@...>

Hello Rubyists!

47 messages 2005/01/06
[#4152] Re: The face of Unicode support in the future — Yukihiro Matsumoto <matz@...> 2005/01/07

Hi,

[#4167] Re: The face of Unicode support in the future — Christian Neukirchen <chneukirchen@...> 2005/01/09

Yukihiro Matsumoto <matz@ruby-lang.org> writes:

[#4175] Re: The face of Unicode support in the future — Yukihiro Matsumoto <matz@...> 2005/01/10

Hi,

[#4186] Re: The face of Unicode support in the future — Paul Brannan <pbrannan@...> 2005/01/11

On Mon, Jan 10, 2005 at 11:53:48PM +0900, Yukihiro Matsumoto wrote:

[#4192] Re: The face of Unicode support in the future — Yukihiro Matsumoto <matz@...> 2005/01/12

Hi,

[#4269] Re: The face of Unicode support in the future — Wes Nakamura <wknaka@...>

19 messages 2005/01/18
[#4270] Re: The face of Unicode support in the future — Yukihiro Matsumoto <matz@...> 2005/01/18

Hi,

[#4275] Re: The face of Unicode support in the future — Wes Nakamura <wknaka@...> 2005/01/19

[#4323] test/unit doesn't rescue a Exception — Tanaka Akira <akr@...17n.org>

test/unit doesn't rescue a Exception in a test method, as follows.

14 messages 2005/01/27
[#8773] Re: test/unit doesn't rescue a Exception — Tanaka Akira <akr@...> 2006/09/02

In article <87is5jb46q.fsf@serein.a02.aist.go.jp>,

[#8776] Re: test/unit doesn't rescue a Exception — "Nathaniel Talbott" <ntalbott@...> 2006/09/03

On 9/1/06, Tanaka Akira <akr@fsij.org> wrote:

[#8777] Re: test/unit doesn't rescue a Exception — Eric Hodel <drbrain@...7.net> 2006/09/03

On Sep 2, 2006, at 6:34 PM, Nathaniel Talbott wrote:

Re: Test::Unit::Collector::Dir won't work with code that modifies $LOAD_PATH

From: Nathaniel Talbott <ntalbott@...>
Date: 2005-01-30 01:41:44 UTC
List: ruby-core #4331
On Thu, 27 Jan 2005 17:17:14 -0500, Nathaniel Talbott
<ntalbott@gmail.com> wrote:

> As for fixing the dir collector so that it respects the $LOAD_PATH,
> I'm not happy with the robustness of the solutions I've found so far.
> The best solution would be to find a way to not modify $LOAD_PATH at
> all, but I'm not sure if that's possible. Otherwise I'm stuck trying
> to undo only the changes made for requiring a test file, but I don't
> think there's a completely fool-proof way of doing that, and I'm
> afraid of introducing weird corner-cases that look like they ought to
> work but don't. Ideas?

Attached is a new version of the patch that seems to resolve this
issue completely, but it's so simple I'm thinking there has to be a
gotcha. Basically, it doesn't modify $LOAD_PATH at all, but rather
does a File.expand_path on the filename to get the absolute path and
then depends on the fact that require will load an absolute pathname
without regard to the $LOAD_PATH. In my simplistic tests this works
fine, but I'm concerned I might be missing something.

Feedback is (as always) welcome, and if no one comes up with any
problems, I plan to commit it Monday.

Thanks,


-- 
Nathaniel

<:((><
Terralien, Inc.

Attachments (1)

patch.txt (6.21 KB, text/x-diff)
Index: ChangeLog
===================================================================
RCS file: /var/cvs/src/ruby/ChangeLog,v
retrieving revision 1.2673.2.812
diff -u -r1.2673.2.812 ChangeLog
--- ChangeLog	29 Jan 2005 05:14:08 -0000	1.2673.2.812
+++ ChangeLog	30 Jan 2005 01:32:13 -0000
@@ -1,3 +1,16 @@
+Sun Jan 30 10:27:00 2005  Nathaniel Talbott  <ntalbott@ruby-lang.org>
+  * lib/test/unit/collector.rb (collect_file): no longer modifies the
+    $LOAD_PATH - instead expands the file path to determine the
+    absolute path and requires that.
+
+  * lib/test/unit/autorunner.rb (AutoRunner.run): fixed so that
+    'ruby -rtest/unit -rtest1 -rtest2 -e0' will use the objectspace
+    collector again. Also tried to simplify the calling convention.
+    
+  * test/runner.rb: adjusted for new AutoRunner semantics.
+  
+  * lib/test/unit.rb: ditto.
+
 Sat Jan 29 09:42:12 2005  Sam Roberts  <sroberts@uniserve.com>
 
 	* lib/resolv.rb (Resolv::DNS::Resource::IN::SRV): Added RFC2782 SRV
Index: lib/test/unit.rb
===================================================================
RCS file: /var/cvs/src/ruby/lib/test/unit.rb,v
retrieving revision 1.7.2.5
diff -u -r1.7.2.5 unit.rb
--- lib/test/unit.rb	19 Dec 2004 02:01:58 -0000	1.7.2.5
+++ lib/test/unit.rb	30 Jan 2005 01:32:14 -0000
@@ -240,35 +240,35 @@
   #  class TS_MyTests
   #    def self.suite
   #      suite = Test::Unit::TestSuite.new
-#      suite << TC_MyFirstTests.suite
-#      suite << TC_MoreTestsByMe.suite
-#      suite << TS_AnotherSetOfTests.suite
-#      return suite
-#    end
-#  end
-#  Test::Unit::UI::Console::TestRunner.run(TS_MyTests)
-#
-# Now, this is a bit cumbersome, so Test::Unit does a little bit more
-# for you, by wrapping these up automatically when you require
-# 'test/unit'. What does this mean? It means you could write the above
-# test case like this instead:
-#
-#  require 'test/unit'
-#  require 'tc_myfirsttests'
-#  require 'tc_moretestsbyme'
-#  require 'ts_anothersetoftests'
-#
-# Test::Unit is smart enough to find all the test cases existing in
-# the ObjectSpace and wrap them up into a suite for you. It then runs
-# the dynamic suite using the console TestRunner.
-#
-#
-# == Questions?
-#
-# I'd really like to get feedback from all levels of Ruby
-# practitioners about typos, grammatical errors, unclear statements,
-# missing points, etc., in this document (or any other).
-#
+  #      suite << TC_MyFirstTests.suite
+  #      suite << TC_MoreTestsByMe.suite
+  #      suite << TS_AnotherSetOfTests.suite
+  #      return suite
+  #    end
+  #  end
+  #  Test::Unit::UI::Console::TestRunner.run(TS_MyTests)
+  #
+  # Now, this is a bit cumbersome, so Test::Unit does a little bit more
+  # for you, by wrapping these up automatically when you require
+  # 'test/unit'. What does this mean? It means you could write the above
+  # test case like this instead:
+  #
+  #  require 'test/unit'
+  #  require 'tc_myfirsttests'
+  #  require 'tc_moretestsbyme'
+  #  require 'ts_anothersetoftests'
+  #
+  # Test::Unit is smart enough to find all the test cases existing in
+  # the ObjectSpace and wrap them up into a suite for you. It then runs
+  # the dynamic suite using the console TestRunner.
+  #
+  #
+  # == Questions?
+  #
+  # I'd really like to get feedback from all levels of Ruby
+  # practitioners about typos, grammatical errors, unclear statements,
+  # missing points, etc., in this document (or any other).
+  #
   module Unit
     def self.run=(flag)
       @run = flag
@@ -282,6 +282,6 @@
 
 at_exit do
   unless $! || Test::Unit.run?
-    exit Test::Unit::AutoRunner.run($0 != "-e" && $0)
+    exit Test::Unit::AutoRunner.run
   end
 end
Index: lib/test/unit/autorunner.rb
===================================================================
RCS file: /var/cvs/src/ruby/lib/test/unit/autorunner.rb,v
retrieving revision 1.8.2.2
diff -u -r1.8.2.2 autorunner.rb
--- lib/test/unit/autorunner.rb	19 Dec 2004 02:01:58 -0000	1.8.2.2
+++ lib/test/unit/autorunner.rb	30 Jan 2005 01:32:14 -0000
@@ -5,14 +5,20 @@
 module Test
   module Unit
     class AutoRunner
-      def self.run(current_file=nil, default_dir=nil, argv=ARGV, &block)
-        if(!current_file || current_file == $0)
-          r = new(!current_file, &block)
-          if !r.process_args(argv) && default_dir
-            r.to_run << default_dir
-          end
-          r.run
+      def self.run(force_standalone=false, default_dir=nil, argv=ARGV, &block)
+        r = new(force_standalone || standalone?, &block)
+        if((!r.process_args(argv)) && default_dir)
+          r.to_run << default_dir
         end
+        r.run
+      end
+      
+      def self.standalone?
+        return false unless("-e" == $0)
+        ObjectSpace.each_object(Class) do |klass|
+          return false if(klass < TestCase)
+        end
+        true
       end
 
       RUNNERS = {
Index: lib/test/unit/collector/dir.rb
===================================================================
RCS file: /var/cvs/src/ruby/lib/test/unit/collector/dir.rb,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 dir.rb
--- lib/test/unit/collector/dir.rb	19 Dec 2004 02:01:59 -0000	1.4.2.1
+++ lib/test/unit/collector/dir.rb	30 Jan 2005 01:32:14 -0000
@@ -75,17 +75,13 @@
         end
 
         def collect_file(name, suites, already_gathered)
-          loadpath = $:.dup
-          dir = File.dirname(File.expand_path(name))
-          $:.unshift(dir) unless $:.first == dir
+          absolute_name = File.expand_path(name)
           if(@req)
-            @req.require(name)
+            @req.require(absolute_name)
           else
-            require(name)
+            require(absolute_name)
           end
           find_test_cases(already_gathered).each{|t| add_suite(suites, t.suite)}
-        ensure
-          $:.replace(loadpath)
         end
       end
     end
Index: test/runner.rb
===================================================================
RCS file: /var/cvs/src/ruby/test/runner.rb,v
retrieving revision 1.11
diff -u -r1.11 runner.rb
--- test/runner.rb	2 Dec 2003 12:31:44 -0000	1.11
+++ test/runner.rb	30 Jan 2005 01:32:14 -0000
@@ -4,4 +4,4 @@
 Version = rcsid[2].scan(/\d+/).collect!(&method(:Integer)).freeze
 Release = rcsid[3].freeze
 
-exit Test::Unit::AutoRunner.run(false, File.dirname($0))
+exit Test::Unit::AutoRunner.run(true, File.dirname($0))

In This Thread