~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to sample/test.rb

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
$failed = 0
7
7
 
8
8
def test_check(what)
9
 
  printf "%s\n", what
 
9
  STDERR.print "\nsample/test.rb:#{what} "
10
10
  $what = what
11
11
  $testnum = 0
12
12
end
14
14
def test_ok(cond,n=1)
15
15
  $testnum+=1
16
16
  $ntest+=1
 
17
  where = (st = caller(n)) ? st[0] : "caller error! (n=#{n}, trace=#{caller(0).join(', ')}"
17
18
  if cond
18
 
    printf "ok %d\n", $testnum
 
19
    STDERR.print "."
 
20
    printf "ok %d (%s)\n", $testnum, where
19
21
  else
20
 
    where = (st = caller(n)) ? st[0] : "caller error! (n=#{n}, trace=#{caller(0).join(', ')}"
 
22
    STDERR.print "F"
21
23
    printf "not ok %s %d -- %s\n", $what, $testnum, where
22
24
    $failed+=1 
23
25
  end
 
26
  STDOUT.flush
 
27
  STDERR.flush
24
28
end
25
29
 
26
30
# make sure conditional operators work
750
754
 
751
755
test_check "hash"
752
756
$x = {1=>2, 2=>4, 3=>6}
753
 
$y = {1, 2, 2, 4, 3, 6}
754
757
 
755
758
test_ok($x[1] == 2)
756
759
 
757
760
test_ok(begin   
758
 
     for k,v in $y
 
761
     for k,v in $x
759
762
       raise if k*2 != v
760
763
     end
761
764
     true
769
772
test_ok($x.values_at(2,3) == [4,6])
770
773
test_ok($x == {1=>2, 2=>4, 3=>6})
771
774
 
772
 
$z = $y.keys.sort.join(":")
 
775
$z = $x.keys.sort.join(":")
773
776
test_ok($z == "1:2:3")
774
777
 
775
 
$z = $y.values.sort.join(":")
 
778
$z = $x.values.sort.join(":")
776
779
test_ok($z == "2:4:6")
777
 
test_ok($x == $y)
 
780
test_ok($x == $x)
778
781
 
779
 
$y.shift
780
 
test_ok($y.length == 2)
 
782
$x.shift
 
783
test_ok($x.length == 2)
781
784
 
782
785
$z = [1,2]
783
 
$y[$z] = 256
784
 
test_ok($y[$z] == 256)
 
786
$x[$z] = 256
 
787
test_ok($x[$z] == 256)
785
788
 
786
789
$x = Hash.new(0)
787
790
$x[1] = 1
1868
1871
File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"`
1869
1872
 
1870
1873
$bad = false
1871
 
if (dir = File.dirname(File.dirname($0))) == '.'
 
1874
if (dir = File.dirname(File.dirname(__FILE__))) == '.'
1872
1875
  dir = ""
1873
1876
else
1874
1877
  dir << "/"
1875
1878
end
1876
1879
 
1877
1880
def valid_syntax?(code, fname)
1878
 
  eval("BEGIN {return true}\n#{code}", nil, fname, 0)
 
1881
  p fname
 
1882
  code = code.sub(/\A(?:\s*\#.*$)*(\n)?/n) {
 
1883
    "#$&#{"\n" if $1 && !$2}BEGIN{return true}\n"
 
1884
  }
 
1885
  eval(code, nil, fname, 0)
1879
1886
rescue Exception
1880
 
  puts $!.message
 
1887
  STDERR.puts $!.message
1881
1888
  false
1882
1889
end
1883
1890
 
1884
1891
for script in Dir["#{dir}{lib,sample,ext}/**/*.rb"]
1885
1892
  unless valid_syntax? IO::read(script), script
 
1893
    STDERR.puts script
1886
1894
    $bad = true
1887
1895
  end
1888
1896
end
2211
2219
GC.start
2212
2220
test_ok true   # reach here or dumps core
2213
2221
 
 
2222
ObjectSpace.each_object{|o|
 
2223
  o.class.name
 
2224
}
 
2225
test_ok true   # reach here or dumps core
 
2226
 
2214
2227
if $failed > 0
2215
2228
  printf "not ok/test: %d failed %d\n", $ntest, $failed
2216
2229
else