Skip to content

Commit

Permalink
Add a new CLI test
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed Apr 8, 2024
1 parent d457f5e commit e2e42b7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ name: Artifact Tests
on:
push:
branches: [ main ]
paths: ['libbs/artifacts/**']
paths: ['libbs/artifacts/**', 'examples/**']
pull_request:
branches: [ main ]
paths: ['libbs/artifacts/**']
paths: ['libbs/artifacts/**', 'examples/**']

jobs:
build:
Expand All @@ -24,9 +24,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install .
pip install pytest . ./examples/change_watcher_plugin/
- name: Pytest
run: |
pytest ./tests/test_artifacts.py
pytest ./tests/test_artifacts.py ./tests/test_cli.py
2 changes: 2 additions & 0 deletions examples/change_watcher_plugin/bs_change_watcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from libbs.plugin_installer import LibBSPluginInstaller

__version__ = "0.0.1"


def create_plugin(*args, **kwargs):
"""
Expand Down
2 changes: 2 additions & 0 deletions examples/change_watcher_plugin/bs_change_watcher/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse

from . import BSChangeWatcherInstaller, create_plugin
import bs_change_watcher


def main():
Expand All @@ -11,6 +12,7 @@ def main():
parser.add_argument(
"-s", "--server", help="Run a a headless server for the watcher plugin", choices=["ghidra"]
)
parser.add_argument("-v", "--version", action="version", version=bs_change_watcher.__version__)
args = parser.parse_args()

if args.install:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import subprocess

import unittest


class TestCommandline(unittest.TestCase):
def test_change_watcher_plugin_cli(self):
# assumes you've pip installed ./examples/change_watcher_plugin
import bs_change_watcher

# run the CLI version check
output = subprocess.run(["bs_change_watcher", "--version"], capture_output=True)
version = output.stdout.decode().strip()
assert version == bs_change_watcher.__version__


if __name__ == "__main__":
unittest.main(argv=sys.argv)

0 comments on commit e2e42b7

Please sign in to comment.