mirror of
https://github.com/radareorg/r2xsql.git
synced 2026-11-07 06:36:02 -10:00
46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
# SPDX-License-Identifier: LicenseRef-Human-Origin-Source-1.0
|
|
"""Check an automatically discovered release plugin on every supported OS."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def check(r2):
|
|
# -Q skips plugin finalizers; process teardown must still be safe.
|
|
for quiet in ("-q", "-Q"):
|
|
commands = [
|
|
'"sqlj SELECT NULL AS missing, 7 > 3 AS ok; SELECT 2 AS n"',
|
|
'"sqlj INSERT INTO comments(addr,text) VALUES(4, \'release smoke\'); '
|
|
"SELECT text FROM comments WHERE addr=4; "
|
|
"DELETE FROM comments WHERE addr=4; "
|
|
'SELECT count(*) FROM comments WHERE addr=4"',
|
|
'"sqlj SELECT * FROM missing_table"',
|
|
'"sqlj SELECT 42 AS alive"',
|
|
'"sql,:csv SELECT 1 AS n, \'a,b\' AS name"',
|
|
]
|
|
args = [r2, "-N", quiet, "-e", "scr.color=0", "-e", "scr.utf8=false"]
|
|
for command in commands:
|
|
args.extend(["-c", command])
|
|
result = subprocess.run(args + ["malloc://64"], capture_output=True,
|
|
text=True, timeout=30)
|
|
assert result.returncode == 0, (quiet, result.returncode, result.stderr)
|
|
lines = result.stdout.splitlines()
|
|
assert len(lines) == 6, (result.stdout, result.stderr)
|
|
multi, write, error, alive = map(json.loads, lines[:4])
|
|
assert multi["success"] and multi["statement_count"] == 2, multi
|
|
assert multi["results"][0]["rows"] == [[None, "1"]], multi
|
|
assert multi["results"][1]["rows"] == [["2"]], multi
|
|
assert write["success"] and write["statement_count"] == 4, write
|
|
assert write["results"][1]["rows"] == [["release smoke"]], write
|
|
assert write["results"][3]["rows"] == [["0"]], write
|
|
assert not error["success"], error
|
|
assert alive["success"] and alive["results"][0]["rows"] == [["42"]], alive
|
|
assert lines[4:] == ["n,name", '1,"a,b"'], result.stdout
|
|
print("Packaged plugin: JSON, CRUD, errors, CSV and process cleanup OK")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
check(str(Path(sys.argv[1]).resolve()))
|