[GULF] Find the test dir

Don't know how much gulf this can take, but I sure would like as small
a version as I can get.

  paths = File.expand_path(File.dirname(__FILE__)).split('/')
  paths.size.downto(1) do |i|
    f = (paths.slice(0..i)+['test']).join('/')
    $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f)
  end
  raise unless $TESTDIR

T.

I believe you mean golf? :wink:

Here are a couple options (probably not the shortest though):

paths = File.expand_path(File.dirname(__FILE__)).split('/')
while paths.length > 1
  f = (paths+['test/FIXTURE']).join('/')
  $TESTDIR = f if File.directory?(f)
  paths.pop
end
raise unless $TESTDIR

path = File.expand_path(File.dirname(__FILE__))
until path == '/'
  f = File.join(path,'test/FIXTURE')
  $TESTDIR = f if File.directory?(f)
  path = File.dirname(path)
end
raise unless $TESTDIR

Ryan

···

On 10/22/05, Trans <transfire@gmail.com> wrote:

Don't know how much gulf this can take, but I sure would like as small
a version as I can get.

  paths = File.expand_path(File.dirname(__FILE__)).split('/')
  paths.size.downto(1) do |i|
    f = (paths.slice(0..i)+['test']).join('/')
    $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f)
  end
  raise unless $TESTDIR

Hi --

···

On Sun, 23 Oct 2005, Trans wrote:

Don't know how much gulf this can take, but I sure would like as small
a version as I can get.

paths = File.expand_path(File.dirname(__FILE__)).split('/')
paths.size.downto(1) do |i|
   f = (paths.slice(0..i)+['test']).join('/')
   $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f)
end
raise unless $TESTDIR

require'file/find'
raise unless$TESTDIR=Find.find(File.dirname(__FILE__)){|f|
break File.join(f,"FIXTURE")if test(?d,f)&&/\btest$/.match(f)}

David

--
David A. Black
dblack@wobblini.net

Trans wrote:

Don't know how much gulf this can take, but I sure would like as small
a version as I can get.

  paths = File.expand_path(File.dirname(__FILE__)).split('/')
  paths.size.downto(1) do |i|
    f = (paths.slice(0..i)+['test']).join('/')
    $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f)
  end
  raise unless $TESTDIR

The best balance between size and readability is probably the
following:

  find_test_dir

Of course, the method "find_test_dir" must be implemented somewhere,
but you won't have to read it very often, and you can just use the six
lines you've written above.

However, I would use the 'pathname' library to clarify some of the
code.

Cheers,
Gavin

Oops I mean "GOLF" with an O not a U. GOLF. G...O...L...F.

(smtms i wsh nglsh ws mr lk hbrw)

T.

Gavin Sinclair wrote:

> paths = File.expand_path(File.dirname(__FILE__)).split('/')
> paths.size.downto(1) do |i|
> f = (paths.slice(0..i)+['test']).join('/')
> $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f)
> end
> raise unless $TESTDIR

[...]

However, I would use the 'pathname' library to clarify some of the
code.

To wit (untested):

  require 'pathname'

  def find_test_dir
    dir = Pathname.new(__FILE__)
    loop do
      dir = dir.dirname
      test_dir = dir + "test"
      return test_dir if test_dir.directory?
      raise "Test directory not found" if dir.mountpoint?
    end
  end
  
  # ...
  
  fixture = find_test_dir() + "FIXTURE"

Cheers,
Gavin

David A. Black wrote:

require'file/find'
raise unless$TESTDIR=Find.find(File.dirname(__FILE__)){|f|
break File.join(f,"FIXTURE")if test(?d,f)&&/\btest$/.match(f)}

Shorter than I thought possible! And I did not know about file/find.

Thanks,
T.

Gavin Sinclair wrote:

The best balance between size and readability is probably the
following:

  find_test_dir

Of course, the method "find_test_dir" must be implemented somewhere,
but you won't have to read it very often, and you can just use the six
lines you've written above.

That' a good point. But my trouble here is that the tests themsselves
can get run out of either of two locations: as attached to the bottom
of the file they test, which is in lib/ or standalone in test/ dir
(same code I just extract it). So there's no convenient place to store
this and still be able to require it without the same trouble, AFAIK.

However, I would use the 'pathname' library to clarify some of the
code.

Yes, in this case it would be good, but I recently discovered Pathname
is terribly slow, so I stopped using it.

Thanks,
T.

?nm y t'nD

?nm y t'nd)wrbh kl rm sw hslgn hsw i smtms(

···

On 10/22/05, Trans <transfire@gmail.com> wrote:

Oops I mean "GOLF" with an O not a U. GOLF. G...O...L...F.

(smtms i wsh nglsh ws mr lk hbrw)

T.

--
thanks,
-pate
-------------------------

pat eyler wrote:

?nm y t'nD

?nm y t'nd)wrbh kl rm sw hslgn hsw i smtms(

LOL :slight_smile:

pat eyler <pat.eyler@gmail.com> writes:

                                                  ?nm y t'nD

?nm y t'nd)wrbh kl rm sw hslgn hsw i smtms(

.hght, drrfn b nc gnnm ht wh gnzm ylpmS

···

-pate

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

$ echo -e "[...snip...]" | ./2hebrew.rb
lc yw s rtlsnrt wrbhgp t hslgn n
?s knht y t'nD
$ cat 2hebrew.rb
#!/usr/bin/env ruby

ARGF.each do | line | puts line.chomp.gsub(/[aeiou]/i, '').reverse end

cheers,

Brian

···

On 23/10/05, Christian Neukirchen <chneukirchen@gmail.com> wrote:

pat eyler <pat.eyler@gmail.com> writes:

> ?nm y t'nD
>
> ?nm y t'nd)wrbh kl rm sw hslgn hsw i smtms(

.hght, drrfn b nc gnnm ht wh gnzm ylpmS

> -pate
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/