Skip to content

Commit

Permalink
Fix flaky tempfile tests (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
david942j authored Jan 20, 2021
1 parent f2ec156 commit e44e14d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions spec/elf_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
describe ELFTools::ELFFile do
before(:all) do
@filepath = File.join(__dir__, 'files', 'amd64.elf')
@elf = ELFTools::ELFFile.new(File.open(@filepath))
@elf = described_class.new(File.open(@filepath))
end

it 'basic' do
Expand Down Expand Up @@ -130,27 +130,30 @@

describe 'patches' do
it 'dup' do
out = Tempfile.new('elftools').binmode
out = Tempfile.new('elftools')
out.close
@elf.save(out.path)
out.reopen(out.path, 'rb')
expect(out.read.force_encoding('ascii-8bit')).to eq IO.binread(@filepath)
out.close
out.close!
end

it 'patch header' do
out = Tempfile.new('elftools').binmode
# prevent effect other tests
elf = ELFTools::ELFFile.new(File.open(@filepath))
out = Tempfile.new('elftools')
out.close
# prevent affect other tests
elf = described_class.new(File.open(@filepath))
expect(elf.machine).to eq 'Advanced Micro Devices X86-64'
expect(elf.section_by_name('.text').header.sh_addr).to eq 0x4005b0
elf.header.e_machine = 40
elf.section_by_name('.text').header.sh_addr = 0xdeadbeef
expect(elf.machine).to eq 'ARM'
elf.save(out.path)
out.reopen(out.path, 'rb')
patched_elf = ELFTools::ELFFile.new(out)
patched_elf = described_class.new(out)
expect(patched_elf.machine).to eq 'ARM'
expect(patched_elf.section_by_name('.text').header.sh_addr).to eq 0xdeadbeef
out.close
out.close!
end
end
end

0 comments on commit e44e14d

Please sign in to comment.