Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cfis committed Jan 8, 2024
1 parent 96fd008 commit 18fecc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
19 changes: 8 additions & 11 deletions ext/libxml/ruby_xml_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,34 +122,31 @@ VALUE rxml_reader_document(VALUE klass, VALUE doc)
*/
static VALUE rxml_reader_file(int argc, VALUE *argv, VALUE klass)
{
xmlTextReaderPtr xreader;
VALUE path;
VALUE options;

const char *xencoding = NULL;
int xoptions = 0;

rb_scan_args(argc, argv, "11", &path, &options);
Check_Type(path, T_STRING);

const char* xencoding = NULL;
int xoptions = 0;

if (!NIL_P(options))
{
VALUE encoding = Qnil;
VALUE parserOptions = Qnil;

Check_Type(options, T_HASH);

encoding = rb_hash_aref(options, BASE_URI_SYMBOL);
VALUE encoding = rb_hash_aref(options, BASE_URI_SYMBOL);
xencoding = NIL_P(encoding) ? NULL : xmlGetCharEncodingName(NUM2INT(encoding));

parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
VALUE parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
xoptions = NIL_P(parserOptions) ? 0 : NUM2INT(parserOptions);
}

xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);
xmlTextReaderPtr xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);

// Unfortunately libxml2 does not set xmlLastError and just returns a null reader
if (xreader == NULL)
rxml_raise(xmlGetLastError());
rb_syserr_fail(ENOENT, StringValueCStr(path));

return rxml_reader_wrap(xreader);
}
Expand Down
3 changes: 2 additions & 1 deletion test/test_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ def test_file
end

def test_invalid_file
assert_raises(LibXML::XML::Error) do
error = assert_raises(Errno::ENOENT) do
LibXML::XML::Reader.file('/does/not/exist')
end
assert_equal("No such file or directory - /does/not/exist", error.message)
end

def test_string
Expand Down

0 comments on commit 18fecc9

Please sign in to comment.