Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
tao1122334 committed Jan 2, 2024
2 parents a0daef3 + 509289d commit 22b3a36
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ lexer
splc
*.myout

# phase4
*.s
# pyinstaller in phase4
splc.spec
build/
Expand Down
6 changes: 4 additions & 2 deletions phase4/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
splc: splc.py
pyinstaller --log-level WARN --distpath bin -F splc.py

.PHONY: clean
.PHONY: test clean
test: splc test/test.py
cd test && python3 test.py
clean:
@rm -rf __pycache__ build bin splc.spec
@rm -rf __pycache__ build bin splc.spec test/*.s
26 changes: 26 additions & 0 deletions phase4/test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# For automatic testing
# This script should run in the `test/` directory
import subprocess

spim_header = """SPIM Version 8.0 of January 8, 2010
Copyright 1990-2010, James R. Larus.
All Rights Reserved.
See the file README for a full copyright notice.
Loaded: /usr/lib/spim/exceptions.s
"""

for i in range(3):
id = f'test_4_r{i:02}'
with open(f'{id}.test', 'r') as tests:
subprocess.run(f'../bin/splc {id}.ir > {id}.s', shell=True)
for test in tests.read().split('\n\n'):
input, expect_out = test.split('\n')
res = subprocess.run(f'echo {input} | spim -file {id}.s', shell=True, capture_output=True, text=True)
actual_out = res.stdout.replace(spim_header, '').strip() # remove SPIM's header
if actual_out != expect_out:
print(f'----------{id} failed----------')
print(f'[input] {input}')
print(f'[expect] {expect_out}')
print(f'[actual] {actual_out}')
exit(1)
print('All tests passed!')
17 changes: 17 additions & 0 deletions phase4/test/test_4_r00.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
0
Enter an integer:1

1
Enter an integer:1

2
Enter an integer:2

3
Enter an integer:6

4
Enter an integer:24

5
Enter an integer:120

0 comments on commit 22b3a36

Please sign in to comment.