Issue #13269 has been updated by Shyouhei Urabe.

Status changed from Open to Assigned
Assignee set to Nobuyoshi Nakada

----------------------------------------
Bug #13269: test/readline/test_readline.rb and mingw
https://bugs.ruby-lang.org/issues/13269#change-63543

* Author: Greg L
* Status: Assigned
* Priority: Normal
* Assignee: Nobuyoshi Nakada
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-03-02 trunk 57755) [x64-mingw32]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
When running test-all on a mingw build, [`test_readline.rb`](https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb) generates failures and errors.  Several of the errors are due to the `with_temp_stdio` method in `test_readline.rb`.  It also leaves several undeleted files in the temp dir.

Current link is: [TestReadline#with_temp_stdio](https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L580-L586)

The current code is:

```ruby
def with_temp_stdio
  Tempfile.create("test_readline_stdin") {|stdin|
    Tempfile.create("test_readline_stdout") {|stdout|
      yield stdin, stdout
    }
  }
end
```

Replacing it with the following solved the problems.

```ruby
  def with_temp_stdio
    stdin =  Tempfile.new("test_readline_stdin")
    stdout = Tempfile.new("test_readline_stdout")
    yield stdin, stdout
    if stdout
      stdout.closed? ? stdout.unlink : stdout.close!
    end
    if stdin
      stdin.closed?  ? stdin.unlink  : stdin.close!
    end
  end
```

I can only test on Windows, but I assume the changed code would work on other os's.  If someone could test it, I'd submit a PR.  Maybe the code in `Tempfile::Remover` is really where the change should occur, but I haven't looked at that.

After this update, I only had one failure and three errors.  Text below.

Odd thing for two errors it that they report `NoMethodError: undefined method assert_separately`, but the highlighted line is `return if assert_under_utf8`. I didn't do an exhaustive search, but I can't find a reference to that function.  But, I'm pulling the test files out of ruby and running separately...

```
Failure: test_input_metachar(TestReadline)
D:/r_test/Readline/test_readline.rb:420:in `test_input_metachar'
     417:       wo = w.dup
     418:       wo.write("\C-re\ef\n")
     419:     end
  => 420:     assert_equal("hello", line, bug6601)
     421:   ensure
     422:     wo.close
     423:     Readline.delete_text
[ruby-core:45682]
<"hello">(UTF-8) expected but was
<"hfello">(IBM437)

diff:
? hfello

? Encoding: UTF-8
?           IBM437
====================================================================================================================================================
Error: test_input_metachar_multibyte(TestReadline):
  NoMethodError: undefined method `assert_separately' for #<TestReadline:0x00000003bcfef0>
  Did you mean?  assert_empty
D:/r_test/Readline/test_readline.rb:618:in `assert_under_utf8'
D:/r_test/Readline/test_readline.rb:429:in `test_input_metachar_multibyte'
     426:
     427:   def test_input_metachar_multibyte
     428:     unless Encoding.find("locale") == Encoding::UTF_8
  => 429:       return if assert_under_utf8
     430:       skip 'this test needs UTF-8 locale'
     431:     end
     432:     bug6602 = '[ruby-core:45683]'
====================================================================================================================================================
Error: test_refresh_line(TestReadline):
  NoMethodError: undefined method `assert_ruby_status' for #<TestReadline:0x00000003bcf6f8>
  Did you mean?  assert_raises
D:/r_test/Readline/test_readline.rb:459:in `block (2 levels) in test_refresh_line'
     456:     bug6232 = '[ruby-core:43957] [Bug #6232] refresh_line after set_screen_size'
     457:     with_temp_stdio do |stdin, stdout|
     458:       replace_stdio(stdin.path, stdout.path) do
  => 459:         assert_ruby_status(%w[-rreadline -], <<-'end;', bug6232)
     460:           Readline.set_screen_size(40, 80)
     461:           Readline.refresh_line
     462:         end;
D:/r_test/Readline/test_readline.rb:567:in `block (2 levels) in replace_stdio'
D:/r_test/Readline/test_readline.rb:557:in `open'
D:/r_test/Readline/test_readline.rb:557:in `block in replace_stdio'
D:/r_test/Readline/test_readline.rb:556:in `open'
D:/r_test/Readline/test_readline.rb:556:in `replace_stdio'
D:/r_test/Readline/test_readline.rb:458:in `block in test_refresh_line'
D:/r_test/Readline/test_readline.rb:583:in `with_temp_stdio'
D:/r_test/Readline/test_readline.rb:457:in `test_refresh_line'
====================================================================================================================================================
Error: test_using_quoting_detection_proc_with_multibyte_input(TestReadline):
  NoMethodError: undefined method `assert_separately' for #<TestReadline:0x00000003bcf2c0>
  Did you mean?  assert_empty
D:/r_test/Readline/test_readline.rb:618:in `assert_under_utf8'
D:/r_test/Readline/test_readline.rb:517:in `test_using_quoting_detection_proc_with_multibyte_input'
     514:     saved_completer_word_break_characters = Readline.completer_word_break_characters
     515:     return unless Readline.respond_to?(:quoting_detection_proc=)
     516:     unless Encoding.find("locale") == Encoding::UTF_8
  => 517:       return if assert_under_utf8
     518:       skip 'this test needs UTF-8 locale'
     519:     end
     520:
```




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>