From a6b9f12c7e59ce84dbdf6d5329b5f5435c4d64f1 Mon Sep 17 00:00:00 2001 From: Mauri Mustonen Date: Sat, 5 Feb 2022 07:39:00 +0200 Subject: [PATCH] Test case for viewcfg GDB command (#19) --- .gitignore | 2 ++ test/test_gdb.py | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index faff7b8..e469d1c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ Pipfile.lock # Vim files .*swp Session.vim +tags # GDB history .gdb_history @@ -22,3 +23,4 @@ coverage.xml # Test files a.out +main.pdf diff --git a/test/test_gdb.py b/test/test_gdb.py index 8b6d897..13d6ead 100644 --- a/test/test_gdb.py +++ b/test/test_gdb.py @@ -53,7 +53,28 @@ def test_savecfg(): 'run', 'savecfg'] ) assert os.path.isfile('main.pdf'), result.stdout - # assert 'Saved CFG to a file _start.pdf' in result.stdout, result.stdout + assert 'Saved CFG to a file main.pdf' in result.stdout, result.stdout + + +def test_viewcfg(): + stdout = '' + try: + result = execute_gdb_commands( + ['set confirm off', 'set breakpoint pending on', + 'file test/fixtures/simple_program/hello', 'b main', + 'run', 'viewcfg'] + ) + stdout = result.stdout + except subprocess.TimeoutExpired as ex: + stdout = str(ex.stdout) + viewcfg_pattern = re.compile(r'Opening a file (.*) with default viewer') + result = viewcfg_pattern.search(stdout) + + assert result is not None, stdout + + temporary_filename = result.group(1) + + assert os.path.isfile(temporary_filename), temporary_filename def execute_gdb_command(command): @@ -72,7 +93,7 @@ def execute_gdb_commands(commands): gdb_command.append('q') result = subprocess.run( gdb_command, stdout=subprocess.PIPE, stdin=None, - stderr=None, timeout=3, check=True, universal_newlines=True, + stderr=None, timeout=2, check=True, universal_newlines=True, ) return result