Skip to content

Tests for zephir parser #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 24, 2019
Merged

Conversation

davidofferman
Copy link
Contributor

Hello!
Here are a few new tests so far for the parser. I'm going to continue pushing more tests to this branch, so if you want to hold off on merging, that will be fine.

Hopefully this will greatly improve code coverage so I can start working on getting the language to support uppercase classes, methods, and possibly variables.

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Thanks

* Tests for AND operator
* Tests for DECR operator
* Tests for DIV operator
* Tests for DOT operator
* Tests for INCR operator
* Tests for MOD operator
* Tests for MUL operator
* Tests for OR operator
* Tests for SUB operator
@codecov
Copy link

codecov bot commented Jul 19, 2019

Codecov Report

Merging #76 into development will increase coverage by 19.24%.
The diff coverage is 85.71%.

Impacted file tree graph

@@               Coverage Diff                @@
##           development      #76       +/-   ##
================================================
+ Coverage        39.63%   58.88%   +19.24%     
================================================
  Files                5        5               
  Lines             2712     2719        +7     
================================================
+ Hits              1075     1601      +526     
+ Misses            1637     1118      -519
Impacted Files Coverage Δ
parser/scanner.re 86.79% <100%> (+29.96%) ⬆️
parser/zephir.lemon 34.79% <75%> (+14.51%) ⬆️
parser/parser.h 65.22% <0%> (+15.82%) ⬆️
parser/base.c 82.41% <0%> (+26.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca800dc...d13c87d. Read the comment docs.

@davidofferman
Copy link
Contributor Author

While looking at the build script, I think there is a problem with code coverage generation. The codecov bash script uses find -execdir to run gcov, which changes the directory. The package.mk file strips the absolute path from the #line directives.

File 'parser/zephir.lemon'
Lines executed:34.80% of 1138
Branches executed:80.00% of 10
Taken at least once:50.00% of 10
Calls executed:30.70% of 1267
Creating 'parser#zephir.lemon.gcov'
Cannot open source file parser/zephir.lemon

https://travis-ci.org/phalcon/php-zephir-parser/jobs/561353443#L798

Is there a reason why we strip the absolute path from scanner.c and parser.c? Also I will need to change the hack-ish base.c line directive when generating parser.c to use $(top_srcdir).

https://github.com/phalcon/php-zephir-parser/blob/ca800dcd20b9af3c55a69a8b2799e5e1ca9dd05c/parser.mk#L41

@sergeyklay
Copy link
Contributor

sergeyklay commented Jul 20, 2019

Feel free to remove this logic from parser.mk as a far we no longer store parser.c and scanner.c under the version control.

Removed stripping to allow the code coverage report to properly find files.
Was initially added since parser.c and scanner.c were checked into source control
- Tests for function definitions
- Tests for erange and irange operator
- Tests for break, continue, require, return, throw, unset statements
- Tests for new class operator
@codecov
Copy link

codecov bot commented Jul 21, 2019

Codecov Report

Merging #76 into development will increase coverage by 34.21%.
The diff coverage is 85.71%.

Impacted file tree graph

@@               Coverage Diff                @@
##           development      #76       +/-   ##
================================================
+ Coverage        39.63%   73.85%   +34.21%     
================================================
  Files                5        5               
  Lines             2712     2719        +7     
================================================
+ Hits              1075     2008      +933     
+ Misses            1637      711      -926
Impacted Files Coverage Δ
parser/scanner.re 98.25% <100%> (+41.41%) ⬆️
parser/zephir.lemon 47.01% <75%> (+26.73%) ⬆️
parser/base.c 92.3% <0%> (+36.81%) ⬆️
parser/parser.h 91.04% <0%> (+41.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca800dc...f85aa67. Read the comment docs.

- tests for class constants
- tests for interfaces
- tests for closure short syntax
- modified tests for function definitions
- tests for operators instanceof, static-constant-access, static-property-access
- tests for empty, fcall, fetch, mcall, and scall statements
@davidofferman
Copy link
Contributor Author

Hello,
For now I'm done with writing test code. You can look over the code and merge if you approve it.

In zephir.lemon when we set the nonterminal of xx_declare_statement, we leave out the types of TYPE_RESOURCE, TYPE_CALLABLE and TYPE_OBJECT. I couldn't find enough documentation to determine if those should be added to the allowed types for declare statements or if I should remove them from parser.h in the function xx_ret_declare_statement().

Thank you.

@davidofferman davidofferman changed the title [WIP] Tests for zephir parser Tests for zephir parser Jul 24, 2019
@sergeyklay
Copy link
Contributor

As a far as I remember it was not finished. Do you have a reasonable proposition to work with those types? But at the moment it seems good to me. Thank you!

@sergeyklay sergeyklay merged commit f78bc60 into zephir-lang:development Jul 24, 2019
@davidofferman
Copy link
Contributor Author

I'm not sure if those types have any real purpose. In the zephir project, variables defined with those types are just set to the type variable. For now I'm going to leave it alone.

https://github.com/phalcon/zephir/blob/1b56924c834707de43db1a2002d1f16b64238b11/Library/Variable.php#L177

class Variable implements TypeAwareInterface
{
    public function __construct($type, $name, Branch $branch = null)
    {
        $this->globalsManager = new Globals();

        if (\in_array($type, ['callable', 'object', 'resource'], true)) {
            $type = 'variable';
        }

        $this->type = $type;
        $this->name = $name;
        $this->branch = $branch;
    }
}

Thanks you for your time and for reviewing all that code.

@davidofferman davidofferman deleted the tests branch July 25, 2019 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants