Skip to content

Commit 97876e7

Browse files
committed
Fix specs for Kernel#require
1 parent ed496d4 commit 97876e7

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

spec/ruby/core/kernel/shared/require.rb

+30
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@
296296
$LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR]
297297
@object.require("load_fixture").should be_false
298298
end
299+
300+
it "stores the missing path in a LoadError object" do
301+
path = "abcd1234"
302+
303+
-> {
304+
@object.send(@method, path)
305+
}.should raise_error(LoadError) { |e|
306+
e.path.should == path
307+
}
308+
end
299309
end
300310

301311
describe "(file extensions)" do
@@ -815,4 +825,24 @@
815825
e.path.should == path
816826
}
817827
end
828+
829+
platform_is :linux, :darwin do
830+
it "does not store the missing path in a LoadError object when c-extension file exists but loading fails and passed absolute path without extension" do
831+
# the error message is specific to what dlerror() returns
832+
path = File.join CODE_LOADING_DIR, "a", "load_fixture"
833+
-> { @object.send(@method, path) }.should raise_error(LoadError) { |e|
834+
e.path.should == nil
835+
}
836+
end
837+
end
838+
839+
platform_is :darwin do
840+
it "does not store the missing path in a LoadError object when c-extension file exists but loading fails and passed absolute path with extension" do
841+
# the error message is specific to what dlerror() returns
842+
path = File.join CODE_LOADING_DIR, "a", "load_fixture.bundle"
843+
-> { @object.send(@method, path) }.should raise_error(LoadError) { |e|
844+
e.path.should == nil
845+
}
846+
end
847+
end
818848
end

spec/tags/core/kernel/require_tags.txt

-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,3 @@ slow:Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread, ru
66
slow:Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required
77
slow:Kernel#require complex, enumerator, rational, thread, ruby2_keywords, fiber are already required
88
slow:Kernel#require complex, enumerator, fiber, rational, thread, ruby2_keywords are already required
9-
fails:Kernel#require complex, enumerator, fiber, rational, thread, ruby2_keywords are already required
10-
fails:Kernel#require (path resolution) loads c-extension file when passed absolute path without extension when no .rb is present
11-
fails:Kernel#require (path resolution) loads .bundle file when passed absolute path with .so
12-
fails:Kernel.require (path resolution) loads c-extension file when passed absolute path without extension when no .rb is present
13-
fails:Kernel.require (path resolution) loads .bundle file when passed absolute path with .so

src/main/java/org/truffleruby/core/exception/CoreExceptions.java

+10
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,16 @@ public RubyException loadError(String message, String path, Node currentNode) {
975975
return loadError;
976976
}
977977

978+
@TruffleBoundary
979+
public RubyException loadError(String message, Node currentNode) {
980+
RubyString messageString = StringOperations.createUTF8String(context, language, message);
981+
RubyClass exceptionClass = context.getCoreLibrary().loadErrorClass;
982+
RubyException loadError = ExceptionOperations
983+
.createRubyException(context, exceptionClass, messageString, currentNode, null);
984+
985+
return loadError;
986+
}
987+
978988
@TruffleBoundary
979989
public RubyException loadErrorCannotLoad(String name, Node currentNode) {
980990
return loadError(StringUtils.format("cannot load such file -- %s", name), name, currentNode);

src/main/java/org/truffleruby/language/loader/RequireNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private void handleCExtensionException(String feature, Exception e) {
308308
message = linkError;
309309
}
310310

311-
throw new RaiseException(getContext(), getContext().getCoreExceptions().runtimeError(message, this));
311+
throw new RaiseException(getContext(), getContext().getCoreExceptions().loadError(message, this));
312312
}
313313

314314
final Throwable linkerException = searchForException("LLVMLinkerException", e);

0 commit comments

Comments
 (0)