diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-12-06 19:32:14 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-12-06 19:32:14 +0900 |
| commit | f4f5f0a009f6335ad13b8651bf43a216442c49a7 (patch) | |
| tree | dd3e1f0744205c5d594fb6d046d974307dc8a165 /test/ruby | |
| parent | aae85926504e448637c336aaf41b2c1ed1a6b78b (diff) | |
Add error case tests for `File.path`
- for non-String argument
- for NUL-contained argument
- for ASCII-incompatible argument
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_file_exhaustive.rb | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index 222578be26..394dc47603 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -204,12 +204,21 @@ class TestFileExhaustive < Test::Unit::TestCase end conv_error = ->(method, msg = "converting with #{method}") { - o = Struct.new(method).new(42) - assert_raise(TypeError, msg) {File.path(o)} - o = Struct.new(method).new("abc".encode(Encoding::UTF_32BE)) - assert_raise(Encoding::CompatibilityError, msg) {File.path(o)} - o = Struct.new(method).new("\0") - assert_raise(ArgumentError, msg) {File.path(o)} + test = ->(&new) do + o = new.(42) + assert_raise(TypeError, msg) {File.path(o)} + + o = new.("abc".encode(Encoding::UTF_32BE)) + assert_raise(Encoding::CompatibilityError, msg) {File.path(o)} + + ["\0", "a\0", "a\0c"].each do |path| + o = new.(path) + assert_raise(ArgumentError, msg) {File.path(o)} + end + end + + test.call(&:itself) + test.call(&Struct.new(method).method(:new)) } conv_error[:to_path] |
