File: test_autoload.rb

package info (click to toggle)
ruby2.1 2.1.5-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 59,972 kB
  • sloc: ruby: 625,579; ansic: 295,220; xml: 25,445; yacc: 9,155; lisp: 2,433; tcl: 949; makefile: 535; sh: 402; perl: 62; python: 47; awk: 36; asm: 35; sed: 31
file content (70 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
assert_equal 'ok', %q{
  File.unlink('zzz.rb') if File.file?('zzz.rb')
  instance_eval do
    autoload :ZZZ, './zzz.rb'
    begin
      ZZZ
    rescue LoadError
      :ok
    end
  end
}, '[ruby-dev:43816]'

assert_equal 'ok', %q{
  open('zzz.rb', 'w') {|f| f.puts '' }
  instance_eval do
    autoload :ZZZ, './zzz.rb'
    begin
      ZZZ
    rescue NameError
      :ok
    end
  end
}, '[ruby-dev:43816]'

assert_equal 'ok', %q{
  open('zzz.rb', 'w') {|f| f.puts 'class ZZZ; def self.ok;:ok;end;end'}
  instance_eval do
    autoload :ZZZ, './zzz.rb'
    ZZZ.ok
  end
}, '[ruby-dev:43816]'

assert_equal 'ok', %q{
  open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
  autoload :ZZZ, "./zzz.rb"
  ZZZ.ok
}

assert_equal 'ok', %q{
  open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
  autoload :ZZZ, "./zzz.rb"
  require "./zzz.rb"
  ZZZ.ok
}

assert_equal 'okok', %q{
  open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
  autoload :ZZZ, "./zzz.rb"
  t1 = Thread.new {ZZZ.ok}
  t2 = Thread.new {ZZZ.ok}
  [t1.value, t2.value].join
}

assert_finish 5, %q{
  autoload :ZZZ, File.expand_path(__FILE__)
  begin
    ZZZ
  rescue NameError
  end
}, '[ruby-core:21696]'

assert_equal 'A::C', %q{
  open("zzz.rb", "w") {}
  class A
    autoload :C, "./zzz"
    class C
    end
    C
  end
}