Skip to content

Commit

Permalink
Create west test command to run zmk testsuite.
Browse files Browse the repository at this point in the history
  • Loading branch information
okke-formsma authored and petejohanson committed Nov 21, 2020
1 parent 5d0532c commit c067629
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
id: west-build
with:
entrypoint: /bin/bash
args: '-c "cd app && ./run-test.sh all"'
args: '-c "west test"'
- name: Archive Build
if: ${{ always() }}
uses: actions/upload-artifact@v2
Expand Down
9 changes: 9 additions & 0 deletions app/scripts/west-commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2020, ZMK Contributors
# SPDX-License-Identifier: MIT

west-commands:
- file: scripts/west_commands/test.py
commands:
- name: test
class: Test
help: run zmk testsuite
33 changes: 33 additions & 0 deletions app/scripts/west_commands/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2020 The ZMK Contributors
#
# SPDX-License-Identifier: MIT
'''Test runner for ZMK.'''

import os
from textwrap import dedent # just for nicer code indentation

from west.commands import WestCommand
from west import log # use this for user output


class Test(WestCommand):
def __init__(self):
super().__init__(
'test', # gets stored as self.name
'run zmk testsuite', # self.help
# self.description:
dedent('''Run the zmk testsuite.'''))

def do_add_parser(self, parser_adder):
parser = parser_adder.add_parser(self.name,
help=self.help,
description=self.description)

parser.add_argument('test_path', default="all",
help='The path to the test. Defaults to "all".', nargs="?")
return parser # gets stored as self.parser

def do_run(self, args, unknown_args):
# the run-test script assumes the app directory is the current dir.
os.chdir(f'{self.topdir}/app')
exit(os.system(f'{self.topdir}/app/run-test.sh {args.test_path}'))
2 changes: 1 addition & 1 deletion app/west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ manifest:
remote: microsoft
path: tools/uf2
self:
path: zmk
west-commands: scripts/west-commands.yml
4 changes: 3 additions & 1 deletion docs/docs/development/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ sidebar_label: Tests
---

Running tests requires [native posix support](posix-board). Any folder under `/app/tests`
containing `native_posix.keymap` will be selected when running `./run-test.sh all`.
containing `native_posix.keymap` will be selected when running `west test`.

Run a single test with `west test <testname>`, like `west test tests/toggle-layer/normal`.

## Creating a New Test Set

Expand Down

0 comments on commit c067629

Please sign in to comment.