Skip to content

Commit

Permalink
Add a test for the preprocessor and errors
Browse files Browse the repository at this point in the history
Add `asr_preprocess` test type for this purpose.
  • Loading branch information
certik committed Oct 8, 2021
1 parent 1c687b7 commit a581466
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 0 deletions.
5 changes: 5 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def main():
ast_cpp_hip = test.get("ast_cpp_hip", False)
ast_openmp = test.get("ast_openmp", False)
asr = test.get("asr", False)
asr_preprocess = test.get("asr_preprocess", False)
asr_indent = test.get("asr_indent", False)
mod_to_asr = test.get("mod_to_asr", False)
llvm = test.get("llvm", False)
Expand Down Expand Up @@ -94,6 +95,10 @@ def main():
run_test("asr", "lfortran --show-asr --no-color {infile} -o {outfile}",
filename, update_reference)

if asr_preprocess:
run_test("asr_preprocess", "lfortran --cpp --show-asr --no-color {infile} -o {outfile}",
filename, update_reference)

if asr_indent:
run_test("asr_indent", "lfortran --show-asr --indent --no-color {infile} -o {outfile}",
filename, update_reference)
Expand Down
8 changes: 8 additions & 0 deletions tests/errors/cpp1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
program cpp1
implicit none
#define X123 z12345678
integer :: x, y
x = (2+3)*5
! Error: `z12345678` not defined:
print *, x, X123, y
end program
8 changes: 8 additions & 0 deletions tests/errors/cpp2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
program cpp2
implicit none
#define X123 12345678
integer :: x
x = (2+3)*5
! Error: `yy` not defined:
print *, x, X123, yy
end program
8 changes: 8 additions & 0 deletions tests/errors/cpp3.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
program cpp3
implicit none
#define X123 12345678
integer :: x, y
x = (2+3)*5
! Error: `xx` not defined:
print *, xx, X123, y
end program
13 changes: 13 additions & 0 deletions tests/reference/asr_preprocess-cpp1-515bcd9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr_preprocess-cpp1-515bcd9",
"cmd": "lfortran --cpp --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/cpp1.f90",
"infile_hash": "ac5c43ef61efaf9750763941c8ee309b88d00bdfc414901bcd6d4fbe",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr_preprocess-cpp1-515bcd9.stderr",
"stderr_hash": "6a9dc73e6103cd15f6617fc34102816fea0bc4313283add1d1bb3d18",
"returncode": 2
}
3 changes: 3 additions & 0 deletions tests/reference/asr_preprocess-cpp1-515bcd9.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
input:7:13 semantic error: Variable 'z12345678' not declared
print *, x, X123, y
^~~~
13 changes: 13 additions & 0 deletions tests/reference/asr_preprocess-cpp2-a8d63da.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr_preprocess-cpp2-a8d63da",
"cmd": "lfortran --cpp --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/cpp2.f90",
"infile_hash": "e4f9f303812209a53776ca76314834165cd4c21ccb47e1443169ce53",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr_preprocess-cpp2-a8d63da.stderr",
"stderr_hash": "8c46515294b597d1ce46003645208f2f595f57b73e4116023d12d733",
"returncode": 2
}
3 changes: 3 additions & 0 deletions tests/reference/asr_preprocess-cpp2-a8d63da.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
input:7:19 semantic error: Variable 'yy' not declared
print *, x, X123, yy
^~
13 changes: 13 additions & 0 deletions tests/reference/asr_preprocess-cpp3-1719443.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr_preprocess-cpp3-1719443",
"cmd": "lfortran --cpp --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/cpp3.f90",
"infile_hash": "8b42a312082ab5a08623b751910516f3fa8bcc464dce36d988e4bdfe",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr_preprocess-cpp3-1719443.stderr",
"stderr_hash": "b8867c48aa80b6656e2febc5f6c6dec4c055c5b5f1c0aad60fcd7a05",
"returncode": 2
}
3 changes: 3 additions & 0 deletions tests/reference/asr_preprocess-cpp3-1719443.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
input:7:10 semantic error: Variable 'xx' not declared
print *, xx, X123, y
^~
12 changes: 12 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ asr = true
filename = "errors/subroutine5.f90"
asr = true

[[test]]
filename = "errors/cpp1.f90"
asr_preprocess = true

[[test]]
filename = "errors/cpp2.f90"
asr_preprocess = true

[[test]]
filename = "errors/cpp3.f90"
asr_preprocess = true

[[test]]
filename = "expr1.f90"
ast = true
Expand Down

0 comments on commit a581466

Please sign in to comment.