@@ -12,6 +12,27 @@ using Test
1212 end
1313end
1414
15+ function check_magic_mismatch (path, HandleType)
16+ err = try
17+ readmeta (open (path, " r" ), HandleType)
18+ catch err
19+ err
20+ end
21+
22+ @test err isa MagicMismatch
23+ if HandleType === ELFHandle
24+ @test occursin (r" Magic Number 0x[a-f0-9]{8} does not match expected ELF magic number 0x7f454c46" , repr (err))
25+ elseif HandleType === COFFHandle
26+ @test occursin (r" Magic Number 0x[a-f0-9]{8} does not match expected PE magic number 0x50450000" , repr (err))
27+ elseif HandleType === MachOHandle
28+ @test occursin (r" Invalid Magic \( 0x[a-f0-9]{8}\)\! " , repr (err))
29+ else
30+ @assert false " unexpected handle type"
31+ end
32+
33+ return nothing
34+ end
35+
1536function test_libfoo_and_fooifier (fooifier_path, libfoo_path)
1637 # Actually read it in
1738 oh_exe = only (readmeta (open (fooifier_path, " r" )))
@@ -43,6 +64,12 @@ function test_libfoo_and_fooifier(fooifier_path, libfoo_path)
4364 # Test that we got the right type
4465 @test typeof (oh) <: H
4566
67+ # Test that the wrong types all error as expected
68+ for MismatchedType in (ELFHandle, COFFHandle, MachOHandle)
69+ H === MismatchedType && continue
70+ check_magic_mismatch (fooifier_path, MismatchedType)
71+ end
72+
4673 # Test that we got the right number of bits
4774 @test is64bit (oh) == (bits == " 64" )
4875 @test platforms_match (Platform (oh), platforms[dir_path])
0 commit comments