|
@@ -9,14 +9,16 @@ import os
|
|
|
import tempfile
|
|
|
import tests_config
|
|
|
import importlib
|
|
|
+
|
|
|
importlib.reload(tests_config)
|
|
|
|
|
|
-sql_parser_tests, sql_checker_tests = tests_config.sql_parser_tests, tests_config.sql_checker_tests
|
|
|
+sql_parser_tests, sql_checker_tests = (
|
|
|
+ tests_config.sql_parser_tests,
|
|
|
+ tests_config.sql_checker_tests,
|
|
|
+)
|
|
|
|
|
|
|
|
|
-async def run_and_output(
|
|
|
- *args: str, timeout=10
|
|
|
-) -> tuple[bytes, bytes]:
|
|
|
+async def run_and_output(*args: str, timeout=10) -> tuple[bytes, bytes]:
|
|
|
p = await subprocess.create_subprocess_exec(
|
|
|
*args,
|
|
|
stdout=subprocess.PIPE,
|
|
@@ -25,9 +27,10 @@ async def run_and_output(
|
|
|
stdout, stderr = await asyncio.wait_for(p.communicate(), timeout=timeout)
|
|
|
return stdout, stderr
|
|
|
|
|
|
+
|
|
|
async def rebuild() -> bool:
|
|
|
- print(datetime.now(), colored('rebuild...', "grey"))
|
|
|
- stdout, _ = await run_and_output('xmake')
|
|
|
+ print(datetime.now(), colored("rebuild...", "grey"))
|
|
|
+ stdout, _ = await run_and_output("xmake")
|
|
|
if b"error" in stdout:
|
|
|
print(stdout.decode("utf-8"))
|
|
|
print(datetime.now(), "-" * 40)
|
|
@@ -35,8 +38,9 @@ async def rebuild() -> bool:
|
|
|
else:
|
|
|
return True
|
|
|
|
|
|
+
|
|
|
async def assert_sql(sql: str, expected: dict):
|
|
|
- stdout, stderr = await run_and_output('xmake', 'run', "sql-parser", sql)
|
|
|
+ stdout, stderr = await run_and_output("xmake", "run", "sql-parser", sql)
|
|
|
|
|
|
if b"error" in stdout:
|
|
|
print(stdout.decode("utf-8"))
|
|
@@ -82,20 +86,22 @@ async def on_parser_modified():
|
|
|
|
|
|
async def assert_checks():
|
|
|
for sql, res in sql_checker_tests:
|
|
|
- stdout, stderr = await run_and_output(
|
|
|
- 'xmake', 'run', "sql-checker",
|
|
|
- "-s", sql
|
|
|
- )
|
|
|
+ stdout, stderr = await run_and_output("xmake", "run", "sql-checker", "-s", sql)
|
|
|
print(sql, res)
|
|
|
if res is True:
|
|
|
- assert b'error' not in stdout, stdout.decode("utf-8")
|
|
|
- assert b'error' not in stderr, stderr.decode('utf-8')
|
|
|
+ assert b"error" not in stdout, (
|
|
|
+ stdout.decode("utf-8") + "\n" + stderr.decode("utf-8")
|
|
|
+ )
|
|
|
+ assert b"error" not in stderr, (
|
|
|
+ stdout.decode("utf-8") + "\n" + stderr.decode("utf-8")
|
|
|
+ )
|
|
|
elif isinstance(res, str):
|
|
|
- res = res.encode('utf-8')
|
|
|
+ res = res.encode("utf-8")
|
|
|
assert res in stderr, stderr.decode("utf-8")
|
|
|
else:
|
|
|
assert False, f"{res} 不是合适的结果"
|
|
|
|
|
|
+
|
|
|
async def on_checker_modified():
|
|
|
print(datetime.now(), colored("run checker tests...", "yellow"))
|
|
|
try:
|
|
@@ -118,7 +124,9 @@ async def watch_parser():
|
|
|
|
|
|
|
|
|
async def watch_checker():
|
|
|
- async for changes in awatch("./src/checker.cpp", "./src/checker.h", "./src/utils.h", "./src/utils.cpp"):
|
|
|
+ async for changes in awatch(
|
|
|
+ "./src/checker.cpp", "./src/checker.h", "./src/utils.h", "./src/utils.cpp"
|
|
|
+ ):
|
|
|
if await rebuild():
|
|
|
await on_checker_modified()
|
|
|
|