Skip to content

Commit

Permalink
Merge pull request #7210 from PurityLake/fix-argf-inplace-2-3
Browse files Browse the repository at this point in the history
Fix 2 failing tests for ARGF `test_inplace2` and `test_inplace3`
  • Loading branch information
enebo committed May 12, 2022
2 parents e9fa2d9 + 2ef7bdb commit 4c08d1b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyArgsFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public static IRubyObject inplace_mode(ThreadContext context, IRubyObject recv)
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);

if (data.inPlace == null) return context.nil;
if (data.inPlace.isNil()) return context.runtime.newString("");
if (data.inPlace.isNil()) return context.nil;

return data.inPlace.dup();
}
Expand All @@ -296,7 +296,9 @@ public static IRubyObject inplace_mode_set(ThreadContext context, IRubyObject re
private static IRubyObject setInplaceMode(ThreadContext context, IRubyObject recv, IRubyObject test) {
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);

if (!test.isTrue()) {
if (test.isNil()) {
data.inPlace = context.nil;
} else if (!test.isTrue()) {
data.inPlace = context.fals;
} else {
test = TypeConverter.convertToType(test, context.runtime.getString(), "to_str", false);
Expand Down
27 changes: 25 additions & 2 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public static void createGlobals(Ruby runtime) {
runtime.defineVariable(new BacktraceGlobalVariable(runtime, "$@"), THREAD);

initSTDIO(runtime, globals);

runtime.defineVariable(new LoadedFeatures(runtime, "$\""), GLOBAL);
runtime.defineVariable(new LoadedFeatures(runtime, "$LOADED_FEATURES"), GLOBAL);

Expand Down Expand Up @@ -246,7 +246,7 @@ public static void createGlobals(Ruby runtime) {
globals.defineReadonly("$-p",
new ValueAccessor(runtime.newBoolean(runtime.getInstanceConfig().isAssumePrinting())),
GLOBAL);
globals.defineReadonly("$-a",
globals.defineReadonly("$-a",
new ValueAccessor(runtime.newBoolean(runtime.getInstanceConfig().isSplit())),
GLOBAL);
globals.defineReadonly("$-l",
Expand All @@ -256,6 +256,13 @@ public static void createGlobals(Ruby runtime) {
// ARGF, $< object
RubyArgsFile.initArgsFile(runtime);

String inplace = runtime.config.getInPlaceBackupExtension();
if (inplace != null) {
runtime.defineVariable(new ArgfGlobalVariable(runtime, "$-i", runtime.newString(inplace)), GLOBAL);
} else {
runtime.defineVariable(new ArgfGlobalVariable(runtime, "$-i", runtime.getNil()), GLOBAL);
}

globals.alias("$-0", "$/");

// Define aliases originally in the "English.rb" stdlib
Expand Down Expand Up @@ -953,6 +960,22 @@ public IRubyObject set(IRubyObject value) {
}
}

public static class ArgfGlobalVariable extends GlobalVariable {
public ArgfGlobalVariable(Ruby runtime, String name, IRubyObject value) {
super(runtime, name, value);
set(value);
}

@Override
public IRubyObject set(IRubyObject value) {
RubyArgsFile.inplace_mode_set(runtime.getCurrentContext(), runtime.getArgsFile(), value);
if (value.isNil() || !value.isTrue()) {
runtime.getInstanceConfig().setInPlaceBackupExtension(null);
}
return super.set(value);
}
}

public static class DeprecatedStringGlobalVariable extends StringGlobalVariable {
public DeprecatedStringGlobalVariable(Ruby runtime, String name, IRubyObject value) {
super(runtime, name, value);
Expand Down
10 changes: 1 addition & 9 deletions test/mri/excludes/TestArgf.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
exclude :test_argf, "needs investigation"
exclude :test_bytes, "needs investigation - deprecated not matched"
exclude :test_chars, "needs investigation - deprecated not matched"
exclude :test_close_replace, "needs investigation"
exclude :test_codepoints, "needs investigation"
exclude :test_each_line_limit_0, "needs investigation"
exclude :test_encoding, "needs investigation"
exclude :test_eof, "needs investigation"
exclude :test_filename2, "needs investigation"
exclude :test_inplace2, "needs investigation"
exclude :test_inplace3, "needs investigation"
exclude :test_inplace_bug_17117, "needs investigation"
exclude :test_inplace_dup, "needs investigation"
exclude :test_inplace_ascii_incompatible_path, "needs investigation"
exclude :test_inplace_no_backup, "needs investigation"
exclude :test_inplace_nonascii, "encoding issue from Ruby -> Java string"
Expand All @@ -19,10 +14,7 @@
exclude :test_inplace_stdin2, "needs investigation"
exclude :test_lineno, "needs investigation"
exclude :test_lineno2, "needs investigation"
exclude :test_lines, "needs investigation"
exclude :test_readlines_limit_0, "HANGS"
exclude :test_skip, "needs investigation"
exclude :test_skip_in_each_char, "needs investigation"
exclude :test_skip_in_each_codepoint, "needs investigation"
exclude :test_to_io, "needs investigation"
exclude :test_unreadable, "needs investigation"
exclude :test_to_io, "needs investigation"
3 changes: 0 additions & 3 deletions test/mri/excludes/TestArray.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
exclude :test_aset_error, "works except JRuby raises RangeError (instead of IndexError) on int overflow"
exclude :test_collect, "breaks in full interp and JIT due to differences in lambda args processing (#6165)"
exclude :test_combination_with_callcc, "no callcc"
exclude :test_count, "needs investigation"
exclude :test_flatten_with_callcc, "no callcc"
exclude :test_permutation, "super flaky on travis" if ENV['TRAVIS'].eql?('true')
exclude :test_permutation_with_callcc, "no callcc"
exclude :test_product_with_callcc, "no callcc"
exclude :test_reject_with_callcc, "no callcc"
exclude :test_repeated_combination_with_callcc, "no callcc"
exclude :test_repeated_permutation_with_callcc, "no callcc"
exclude :test_rindex2, "needs investigation"
exclude :test_sample_random, "gen2 conc modifies ary"
exclude :test_sort_with_callcc, "no callcc"

0 comments on commit 4c08d1b

Please sign in to comment.