diff options
author | Rohit Goswami <rog32@hi.is> | 2023-04-16 17:12:53 +0000 |
---|---|---|
committer | Rohit Goswami <rog32@hi.is> | 2023-05-12 17:41:22 +0000 |
commit | aa5b9d6665709d5ca8a098c2e4f9ce2f5c8a25b7 (patch) | |
tree | b5c0c4ec45e9e2f04271a35912c6bc24b70b9509 | |
parent | a5262604c89c61c8db93241f280c69367c493945 (diff) | |
download | numpy-aa5b9d6665709d5ca8a098c2e4f9ce2f5c8a25b7.tar.gz |
TST: Add a test for gh-23533
-rw-r--r-- | numpy/f2py/tests/src/crackfortran/gh23533.f | 5 | ||||
-rw-r--r-- | numpy/f2py/tests/test_crackfortran.py | 27 |
2 files changed, 32 insertions, 0 deletions
diff --git a/numpy/f2py/tests/src/crackfortran/gh23533.f b/numpy/f2py/tests/src/crackfortran/gh23533.f new file mode 100644 index 000000000..db522afa7 --- /dev/null +++ b/numpy/f2py/tests/src/crackfortran/gh23533.f @@ -0,0 +1,5 @@ + SUBROUTINE EXAMPLE( ) + IF( .TRUE. ) THEN + CALL DO_SOMETHING() + END IF ! ** .TRUE. ** + END diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py index dc0f7e27a..c20e2c2cf 100644 --- a/numpy/f2py/tests/test_crackfortran.py +++ b/numpy/f2py/tests/test_crackfortran.py @@ -135,6 +135,7 @@ class TestMarkinnerspaces: assert markinnerspaces("a 'b c' 'd e'") == "a 'b@_@c' 'd@_@e'" assert markinnerspaces(r'a "b c" "d e"') == r'a "b@_@c" "d@_@e"' + class TestDimSpec(util.F2PyTest): """This test suite tests various expressions that are used as dimension specifications. @@ -244,6 +245,7 @@ class TestModuleDeclaration: assert len(mod) == 1 assert mod[0]["vars"]["abar"]["="] == "bar('abar')" + class TestEval(util.F2PyTest): def test_eval_scalar(self): eval_scalar = crackfortran._eval_scalar @@ -268,6 +270,7 @@ class TestFortranReader(util.F2PyTest): mod = crackfortran.crackfortran([str(f_path)]) assert mod[0]['name'] == 'foo' + class TestUnicodeComment(util.F2PyTest): sources = [util.getpath("tests", "src", "crackfortran", "unicode_comment.f90")] @@ -278,6 +281,7 @@ class TestUnicodeComment(util.F2PyTest): def test_encoding_comment(self): self.module.foo(3) + class TestNameArgsPatternBacktracking: @pytest.mark.parametrize( ['adversary'], @@ -313,6 +317,19 @@ class TestNameArgsPatternBacktracking: # that should still be true. good_version_of_adversary = repeated_adversary + '@)@' assert nameargspattern.search(good_version_of_adversary) + if ii > start_reps: + # the hallmark of exponentially catastrophic backtracking + # is that runtime doubles for every added instance of + # the problematic pattern. + times_median_doubled += median > 2 * last_median + # also try to rule out non-exponential but still bad cases + # arbitrarily, we should set a hard limit of 10ms as too slow + assert median < trials_per_count * 0.01 + last_median = median + # we accept that maybe the median might double once, due to + # the CPU scheduler acting weird or whatever. More than that + # seems suspicious. + assert times_median_doubled < 2 class TestFunctionReturn(util.F2PyTest): @@ -321,3 +338,13 @@ class TestFunctionReturn(util.F2PyTest): def test_function_rettype(self): # gh-23598 assert self.module.intproduct(3, 4) == 12 + + +class TestFortranGroupCounters(util.F2PyTest): + def test_end_if_comment(self): + # gh-23533 + fpath = util.getpath("tests", "src", "crackfortran", "gh23533.f") + try: + crackfortran.crackfortran([str(fpath)]) + except Exception as exc: + assert False, f"'crackfortran.crackfortran' raised an exception {exc}" |