1 require File.dirname(__FILE__) + '/../../spec_helper'
3 # FIXME: somehow make these fixture dirs independent of the
4 # rubyspec submodule dir in spec/frozen, otherwise these specs
5 # won't behave the same with the clone of rubyspecs in spec/ruby.
6 $load_fixture_dir = (File.dirname(__FILE__) + '/../../frozen/1.8/fixtures/load')
7 $LOAD_PATH << $load_fixture_dir
8 $LOAD_PATH << (File.dirname(__FILE__) + '/../../frozen/1.8/fixtures/load/load_spec_rba.rba')
21 $load_spec_wrap2 = nil
23 $load_spec_rooby = nil
27 describe "Kernel#load" do
28 # Avoid storing .rbc and .rba in repo
30 # Kernel.compile will not work correctly from that dir so no chdir here
31 system "rm #{$load_fixture_dir}/*.rbc 2>/dev/null"
33 Kernel.compile($load_fixture_dir + '/load_spec_10.rb')
34 Dir.chdir($load_fixture_dir) do |dir|
35 system "rm load_spec_rba.rba 2>/dev/null"
36 system "ar r load_spec_rba.rba load_spec_10.rbc 2>/dev/null"
41 Dir.glob("#{$load_fixture_dir}/*.rbc") {|f| File.delete f }
42 Dir.glob("#{$load_fixture_dir}/load_dynamic.rb*") {|f| File.delete f }
46 Dir.glob("#{$load_fixture_dir}/load_dynamic.rb*") {|f| File.delete f }
49 it "loads a .rbc file directly" do
50 load('load_spec_2.rb').should == true
51 load('load_spec_2.rbc').should == true
54 it "compiles a new .rbc file if one does not exist" do
55 `rm -f #{$load_fixture_dir}/load_spec_2.rbc`
57 load('load_spec_2.rb').should == true
59 File.exist?("#{$load_fixture_dir}/load_spec_2.rbc").should == true
62 it "generates a .<name>.compiled.rbc but no .rb file if using a file with no extension" do
63 `rm -f #{$load_fixture_dir}/load_spec.rbc`
65 load('load_spec').should == true
66 File.exist?("#{$load_fixture_dir}/.load_spec.compiled.rbc").should == true
69 it "generates a .<name>.compiled.rbc file if using a file with some arbitrary extension" do
70 `rm -f #{$load_fixture_dir}/load_spec.rooby.rbc`
72 load('load_spec.rooby').should == true
73 File.exist?("#{$load_fixture_dir}/.load_spec.rooby.compiled.rbc").should == true
76 it "loads the .rbc if the .rb does not exist" do
78 load('load_spec_9.rb').should == true
80 Dir.chdir($load_fixture_dir) do |dir|
81 `mv load_spec_9.rb ls9.old`
84 load('load_spec_9.rb').should == true
87 Dir.chdir($load_fixture_dir) do |dir|
88 `mv ls9.old load_spec_9.rb`
93 it "loads the .rbc file unless the .rb file is newer by modification time" do
94 File.open("#{$load_fixture_dir}/load_spec_dynamic.rb", "w+") do |f|
95 f.puts "$load_spec_dynamic = 1"
97 Kernel.compile "#{$load_fixture_dir}/load_spec_dynamic.rb"
98 system "mv #{$load_fixture_dir}/load_spec_dynamic.rbc #{$load_fixture_dir}/lsd.old"
100 File.open("#{$load_fixture_dir}/load_spec_dynamic.rb", "w+") do |f|
101 f.puts "$load_spec_dynamic = 2"
104 load("load_spec_dynamic.rb").should == true
105 $load_spec_dynamic.should == 2
107 system "mv #{$load_fixture_dir}/lsd.old #{$load_fixture_dir}/load_spec_dynamic.rbc"
109 system "touch -t 200701011800 #{$load_fixture_dir}/load_spec_dynamic.rb"
110 system "touch -t 200801011800 #{$load_fixture_dir}/load_spec_dynamic.rbc"
112 load("load_spec_dynamic.rb").should == true
113 $load_spec_dynamic.should == 1
115 system "touch -t 200701011800 #{$load_fixture_dir}/load_spec_dynamic.rbc"
116 system "touch -t 200801011800 #{$load_fixture_dir}/load_spec_dynamic.rb"
118 load("load_spec_dynamic.rb").should == true
119 $load_spec_dynamic.should == 2
122 system "touch -t 200801011800 #{$load_fixture_dir}/load_spec_dynamic.rbc"
123 system "touch -t 200801011801 #{$load_fixture_dir}/load_spec_dynamic.rb"
125 load("load_spec_dynamic.rb").should == true
126 $load_spec_dynamic.should == 2
129 it "recompiles the file each time if the second parameter is a Hash with non-false :recompile" do
130 File.open("#{$load_fixture_dir}/load_spec_dynamic.rb", "w+") do |f|
131 f.puts "$load_spec_dynamic = 1"
133 Kernel.compile "#{$load_fixture_dir}/load_spec_dynamic.rb"
134 system "mv #{$load_fixture_dir}/load_spec_dynamic.rbc #{$load_fixture_dir}/lsd.old"
136 File.open("#{$load_fixture_dir}/load_spec_dynamic.rb", "w+") do |f|
137 f.puts "$load_spec_dynamic = 2"
140 load("load_spec_dynamic.rb").should == true
141 $load_spec_dynamic.should == 2
143 system "mv #{$load_fixture_dir}/lsd.old #{$load_fixture_dir}/load_spec_dynamic.rbc"
145 system "touch -t 200701011800 #{$load_fixture_dir}/load_spec_dynamic.rb"
146 system "touch -t 200801011800 #{$load_fixture_dir}/load_spec_dynamic.rbc"
148 load("load_spec_dynamic.rb", :recompile => true).should == true
149 $load_spec_dynamic.should == 2
152 it "raises an error if the source file does not exist and :recompile is present" do
153 File.open("#{$load_fixture_dir}/load_spec_dynamic.rb", "w+") do |f|
154 f.puts "$load_spec_dynamic = 1"
156 Kernel.compile "#{$load_fixture_dir}/load_spec_dynamic.rb"
157 system "rm #{$load_fixture_dir}/load_spec_dynamic.rb"
159 lambda { load "load_spec_dynamic.rb", :recompile => true }.should raise_error
162 it "loads a .rbc from a .rba in $LOAD_PATH" do
163 load('load_spec_10.rbc').should == true
164 $load_spec_10.nil?.should == false
167 it "loads a .rbc from a .rba in $LOAD_PATH if only given .rb name" do
169 load('load_spec_10.rb').should == true
170 $load_spec_10.nil?.should == false