Skip to content

Commit 128f119

Browse files
committed
Testing: Add tests for new MachO.open
Ensure that MachO.open raises all expected exceptions.
1 parent 94e64ec commit 128f119

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/test_open.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@
55
class MachOOpenTest < Minitest::Test
66
include Helpers
77

8+
def test_nonexistent_file
9+
assert_raises ArgumentError do
10+
MachO.open("/this/is/a/file/that/cannot/possibly/exist")
11+
end
12+
end
13+
14+
# MachO.open has slightly looser qualifications for truncation than
15+
# either MachOFile.new or FatFile.new - it just makes sure that there are
16+
# enough magic bytes to read, and lets the actual parser raise a
17+
# TruncationError later on if required.
18+
def test_truncated_file
19+
tempfile_with_data("truncated_file", "\x00\x00") do |truncated_file|
20+
assert_raises MachO::TruncatedFileError do
21+
MachO.open(truncated_file.path)
22+
end
23+
end
24+
end
25+
26+
def test_bad_magic
27+
tempfile_with_data("junk_file", "\xFF\xFF\xFF\xFF") do |junk_file|
28+
assert_raises MachO::MagicError do
29+
MachO.open(junk_file.path)
30+
end
31+
end
32+
end
33+
834
def test_open
935
file = MachO.open("test/bin/libhello.dylib")
1036

0 commit comments

Comments
 (0)