Skip to content

Commit 03e323a

Browse files
committed
Add the test suite and a CI job
Cover the token stream, the scanner (the exhaustive unit suite ported from the SQLite driver), the parser runtime, token value and name resolution, generated grammar-data invariants, and a corpus regression test pinning the exact acceptance tally. Run the suite on the oldest and newest supported PHP versions in CI.
1 parent fce58e9 commit 03e323a

11 files changed

Lines changed: 1010 additions & 6 deletions
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: MySQL Parser Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- trunk
7+
paths:
8+
- '.github/workflows/mysql-parser-tests.yml'
9+
- 'packages/mysql-parser/**'
10+
pull_request:
11+
paths:
12+
- '.github/workflows/mysql-parser-tests.yml'
13+
- 'packages/mysql-parser/**'
14+
workflow_dispatch:
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
# Disable permissions for all available scopes by default.
21+
# Any needed permissions should be configured at the job level.
22+
permissions: {}
23+
24+
jobs:
25+
test:
26+
# The runtime supports PHP 7.2+; test the oldest and the latest.
27+
name: PHP ${{ matrix.php }}
28+
runs-on: ubuntu-latest
29+
timeout-minutes: 10
30+
permissions:
31+
contents: read # Required to clone the repo.
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
php: [ '7.2', '8.5' ]
36+
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
41+
- name: Set up PHP
42+
uses: shivammathur/setup-php@v2
43+
with:
44+
php-version: ${{ matrix.php }}
45+
coverage: none
46+
47+
- name: Install dependencies
48+
working-directory: packages/mysql-parser
49+
run: composer install --no-interaction --no-progress
50+
51+
- name: Run tests
52+
working-directory: packages/mysql-parser
53+
run: composer run test

‎packages/mysql-parser/README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ directory of the mysql-server repository into the gitignored `build/`
130130
workspace, extracts the SQL queries from the test files, and rewrites
131131
`data/mysql-server-query-corpus/mysql-latest.csv`.
132132

133-
## Benchmark
133+
## Tests and benchmark
134134

135135
```bash
136+
composer run test # PHPUnit suite (includes a corpus regression test)
136137
composer run benchmark # corpus throughput, without and with the tracing JIT
137138
```
138139

139-
The benchmark runs the package's ~69.5k-query corpus of MySQL server test
140-
queries. The parser accepts **99.88%** of it; the 0.12%
141-
it rejects is syntax removed in MySQL 8.4 (e.g. `RESET MASTER`),
142-
multi-statement input, statements needing non-default session SQL modes, and a
143-
few lexer edge cases.
140+
The corpus tests run the package's ~69.5k-query corpus of MySQL server test
141+
queries. The parser accepts **99.88%** of it; the 0.12% it rejects is syntax
142+
removed in recent MySQL versions (e.g. `RESET MASTER`), multi-statement input,
143+
statements needing non-default session SQL modes, and a few lexer edge cases.
144144

145145
## Pinned MySQL version
146146

‎packages/mysql-parser/composer.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
"src/"
1212
]
1313
},
14+
"require-dev": {
15+
"phpunit/phpunit": "^8.5"
16+
},
1417
"scripts": {
18+
"test": "phpunit",
1519
"build-grammar": [
1620
"./bin/build-grammar"
1721
],
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<phpunit
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.2/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
backupGlobals="false"
6+
colors="true"
7+
beStrictAboutTestsThatDoNotTestAnything="true"
8+
beStrictAboutOutputDuringTests="true"
9+
convertErrorsToExceptions="true"
10+
convertWarningsToExceptions="true"
11+
convertNoticesToExceptions="true"
12+
convertDeprecationsToExceptions="true"
13+
>
14+
<php>
15+
<ini name="memory_limit" value="512M"/>
16+
</php>
17+
<testsuites>
18+
<!-- Default test suite to run all tests. -->
19+
<testsuite name="default">
20+
<directory suffix="_Tests.php">tests/</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

0 commit comments

Comments
 (0)