mirror of
https://github.com/radareorg/radare2-r2papi.git
synced 2026-11-09 12:41:28 -10:00
- R2CommandError now carries the command output and formatted logs - _exec raises only on real radare2 command errors, not on soft ERROR logs - curr_seek_addr uses cmd2 directly and clears the temporary seek - Add tests for _exec raising and _exec_quiet swallowing parse errors
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
# -*- coding:utf-8 -*-
|
|
import os
|
|
|
|
import pytest
|
|
import r2pipe
|
|
from r2papi.base import R2Base, Result
|
|
|
|
|
|
@pytest.fixture
|
|
def r():
|
|
r2 = r2pipe.open(f"{os.path.dirname(__file__)}/test_bin")
|
|
return R2Base(r2)
|
|
|
|
|
|
def test_exec(r):
|
|
ret = r._exec("?e foo")
|
|
assert ret == "foo"
|
|
ret_json = r._exec("pxj 1", json=True)
|
|
assert type(ret_json) is list
|
|
assert len(ret_json) == 1
|
|
|
|
|
|
def test_at(r):
|
|
r.at(0x100)
|
|
assert r._tmp_off == "@ 256"
|
|
r.at("main")
|
|
assert r._tmp_off == "@ main"
|
|
|
|
|
|
def test_result():
|
|
o = {"bin": {"foo": "bar"}}
|
|
r = Result(o)
|
|
assert len(str(r).split("\n")) == 1
|
|
o = {"foo": "bar"}
|
|
r = Result(o)
|
|
assert len(str(r).split("\n")) == 1
|
|
|
|
|
|
def test_sym_to_addr(r):
|
|
assert r.sym_to_addr("entry0") == 0x100000F20
|
|
with pytest.raises(TypeError, match="Symbol type must be string"):
|
|
r.sym_to_addr(0x100)
|
|
|
|
|
|
def test_exec_raises_on_parse_error(r):
|
|
from r2papi.base import R2CommandError
|
|
with pytest.raises(R2CommandError) as exc_info:
|
|
r._exec("px @ invalid_address")
|
|
assert "px @ invalid_address" in str(exc_info.value)
|
|
|
|
|
|
def test_exec_quiet(r):
|
|
ret = r._exec_quiet("px @ invalid_address")
|
|
assert ret is None
|