Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #592 from jacqueswww/590-missing-return-statement
Check for missing return statement
- Loading branch information
Showing
7 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
from pytest import raises | ||
|
||
from viper import compiler | ||
from viper.exceptions import StructureException | ||
|
||
|
||
fail_list = [ | ||
""" | ||
@public | ||
def foo() -> num: | ||
pass | ||
""", | ||
] | ||
|
||
|
||
@pytest.mark.parametrize('bad_code', fail_list) | ||
def test_missing_return(bad_code): | ||
with raises(StructureException): | ||
compiler.compile(bad_code) | ||
|
||
|
||
|
||
valid_list = [ | ||
""" | ||
@public | ||
def foo() -> num: | ||
return 123 | ||
""", | ||
""" | ||
@public | ||
def foo() -> num: | ||
if false: | ||
return 123 | ||
""", # For the time being this is valid code, even though it should not be. | ||
] | ||
|
||
@pytest.mark.parametrize('good_code', valid_list) | ||
def test_return_success(good_code): | ||
assert compiler.compile(good_code) is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters