Skip to content

Commit

Permalink
Merge pull request #124 from Fubukimaru/test-romsize
Browse files Browse the repository at this point in the history
test: Check ROM size
  • Loading branch information
Fubukimaru authored Nov 20, 2023
2 parents 3d4e55a + 1f3b3b3 commit 2bd274b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/features/bugs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Feature: Fixing issues
"""
When I build test.asm
And file test.rom exists
And file test.rom size is 48k
Then page 0 has no cartridge header
And page 1 has cartridge header
And sym contains INIT
Expand All @@ -31,6 +32,7 @@ Feature: Fixing issues
"""
When I build test.asm
Then file test.rom exists
And file test.rom size is 512k

Given I write the code to test.asm
"""
Expand Down
32 changes: 32 additions & 0 deletions test/features/program.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,35 @@ Feature: Test program functions
When I build test.asm
Then text file contains Hello ASMSX
And text file does not contain unknown assembler

# START and ROM directives have different behaviours
# depending if you put them after or before PAGE 1
Scenario: Expected ROM file size (#121) - 8k
Given I write the code to test.asm
"""
ZILOG
BIOS
PAGE 1
START MAIN
ROM
MAIN:
ld A,1
"""
When I build test.asm
Then file test.rom exists
And file test.rom size is 8k

Scenario: Expected ROM file size (#121) - 24k
Given I write the code to test.asm
"""
ZILOG
BIOS
START MAIN
ROM
PAGE 1
MAIN:
ld A,1
"""
When I build test.asm
Then file test.rom exists
And file test.rom size is 24k
18 changes: 18 additions & 0 deletions test/steps/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ def step_impl(context, folder):
def step_impl(context, file):
assert os.path.isfile(file), f"File {file} does not exist"

def human_size_to_int(size: str) -> int:
size = size.lower()
if size[-1] == 'k':
return int(size[:-1]) * 1024
elif size[-1] == 'm':
return int(size[:-1]) * 1024 * 1024
elif size.isnumeric():
return int(size)
else:
raise("Value not valid")

@step('file {file} size is {size}')
@step('file size of {file} is {size}')
def step_impl(context, file, size: str):
expected_size = human_size_to_int(size)
file_size = os.path.getsize(file)
assert file_size == expected_size, f"File {file} has size {file_size} (expected {expected_size})"

@given('I write to {file}')
@given('I write the code to {file}')
def step_impl(context, file):
Expand Down

0 comments on commit 2bd274b

Please sign in to comment.