Skip to content

Commit

Permalink
[Truffle] Allow loading relative ../ paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jul 11, 2015
1 parent 93e44e7 commit ce46667
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
14 changes: 0 additions & 14 deletions spec/truffle/tags/core/kernel/require_tags.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
fails:Kernel#require (path resolution) calls #to_path on non-String objects
fails:Kernel#require (path resolution) loads a ../ relative path from the current working directory with empty $LOAD_PATH
fails:Kernel#require (path resolution) loads a ../ relative path from the current working directory with non-empty $LOAD_PATH
fails:Kernel#require (path resolution) loads a non-canonical path from the current working directory with non-empty $LOAD_PATH
fails:Kernel#require (path resolution) does not require file twice after $LOAD_PATH change
fails:Kernel#require (path resolution) does not resolve a ../ relative path against $LOAD_PATH entries
fails:Kernel#require (path resolution) loads a path with duplicate path separators
fails:Kernel#require (path resolution) with an unreadable file raises a LoadError
fails:Kernel#require (file extensions) loads a .rb extensioned file when passed a non-extensioned path
fails:Kernel#require (file extensions) loads a .rb extensioned file when a C-extension file of the same name is loaded
Expand All @@ -17,8 +12,6 @@ fails:Kernel#require ($LOAD_FEATURES) does not load a ./ relative path that is a
fails:Kernel#require ($LOAD_FEATURES) does not load a ../ relative path that is already stored
fails:Kernel#require ($LOAD_FEATURES) does not load a non-canonical path that is already stored
fails:Kernel#require ($LOAD_FEATURES) does not load twice the same file with and without extension
fails:Kernel#require ($LOAD_FEATURES) stores ../ relative paths as absolute paths
fails:Kernel#require ($LOAD_FEATURES) collapses duplicate path separators
fails:Kernel#require ($LOAD_FEATURES) adds the suffix of the resolved filename
fails:Kernel#require ($LOAD_FEATURES) does not load a non-canonical path for a file already loaded
fails:Kernel#require ($LOAD_FEATURES) does not load a ./ relative path for a file already loaded
Expand All @@ -30,12 +23,7 @@ fails:Kernel#require ($LOAD_FEATURES) when a non-extensioned file is in $LOADED_
fails:Kernel#require (shell expansion) performs tilde expansion on a .rb file before storing paths in $LOADED_FEATURES
fails:Kernel#require (shell expansion) performs tilde expansion on a non-extensioned file before storing paths in $LOADED_FEATURES
fails:Kernel.require (path resolution) calls #to_path on non-String objects
fails:Kernel.require (path resolution) loads a ../ relative path from the current working directory with empty $LOAD_PATH
fails:Kernel.require (path resolution) loads a ../ relative path from the current working directory with non-empty $LOAD_PATH
fails:Kernel.require (path resolution) loads a non-canonical path from the current working directory with non-empty $LOAD_PATH
fails:Kernel.require (path resolution) does not require file twice after $LOAD_PATH change
fails:Kernel.require (path resolution) does not resolve a ../ relative path against $LOAD_PATH entries
fails:Kernel.require (path resolution) loads a path with duplicate path separators
fails:Kernel.require (path resolution) with an unreadable file raises a LoadError
fails:Kernel.require (file extensions) loads a .rb extensioned file when passed a non-extensioned path
fails:Kernel.require (file extensions) loads a .rb extensioned file when a C-extension file of the same name is loaded
Expand All @@ -48,8 +36,6 @@ fails:Kernel.require ($LOAD_FEATURES) does not load a ./ relative path that is a
fails:Kernel.require ($LOAD_FEATURES) does not load a ../ relative path that is already stored
fails:Kernel.require ($LOAD_FEATURES) does not load a non-canonical path that is already stored
fails:Kernel.require ($LOAD_FEATURES) does not load twice the same file with and without extension
fails:Kernel.require ($LOAD_FEATURES) stores ../ relative paths as absolute paths
fails:Kernel.require ($LOAD_FEATURES) collapses duplicate path separators
fails:Kernel.require ($LOAD_FEATURES) adds the suffix of the resolved filename
fails:Kernel.require ($LOAD_FEATURES) does not load a non-canonical path for a file already loaded
fails:Kernel.require ($LOAD_FEATURES) does not load a ./ relative path for a file already loaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public boolean require(String feature, Node currentNode) throws IOException {

if (feature.startsWith("./")) {
final String cwd = context.getRuntime().getCurrentDirectory();
feature = cwd + "/" + feature;
feature = cwd + "/" + feature.substring(2);
} else if (feature.startsWith("../")) {
final String cwd = context.getRuntime().getCurrentDirectory();
feature = cwd.substring(0, cwd.lastIndexOf('/')) + "/" + feature.substring(3);
}

try {
Expand Down

0 comments on commit ce46667

Please sign in to comment.