From 859099a3135281b9bba30d38df93d2c3a89cd05c Mon Sep 17 00:00:00 2001 From: David Barnett Date: Wed, 11 Sep 2024 23:01:22 -0600 Subject: [PATCH] cli testing: Assert on snapshot of entire --help output --- tests/README.md | 5 + .../test-02-test_prints_correct_help.snap | 100 ++++++++++++++++++ tests/cli/test.bats | 9 +- 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 tests/cli/__snapshot__/test-02-test_prints_correct_help.snap diff --git a/tests/README.md b/tests/README.md index 9c495e7..5fe3db2 100644 --- a/tests/README.md +++ b/tests/README.md @@ -51,3 +51,8 @@ individually with `tox -e cli`. NOTE: They'll fail if you haven't initialized the repo submodules for Bats yet, so if you hit errors for missing test runner files, make sure you've run `git submodule update --init` in the repo. + +Some tests may fail on `assert_snapshot` calls from the +[bats-snapshot](https://github.com/markkong318/bats-snapshot) helper, in which case you can easily +update snapshots by finding and deleting the corresponding .snap file in \__snapshots__/, rerunning +the cli tests, and then reviewing the updated snapshot file to make sure the diff is expected. diff --git a/tests/cli/__snapshot__/test-02-test_prints_correct_help.snap b/tests/cli/__snapshot__/test-02-test_prints_correct_help.snap new file mode 100644 index 0000000..6d7da27 --- /dev/null +++ b/tests/cli/__snapshot__/test-02-test_prints_correct_help.snap @@ -0,0 +1,100 @@ +0 +usage: gcalcli [-h] [--version] [--client-id CLIENT_ID] + [--client-secret CLIENT_SECRET] [--noauth_local_server] + [--config-folder CONFIG_FOLDER] [--noincluderc] + [--calendar CALENDAR] + [--default-calendar DEFAULTCALENDAR] [--locale LOCALE] + [--refresh] [--nocache] [--conky] [--nocolor] + [--lineart {fancy,unicode,ascii}] + {list,search,edit,delete,agenda,agendaupdate,updates,conflicts,calw,calm,quick,add,import,remind} + ... + +Google Calendar Command Line Interface + +configuration: + gcalcli supports a few other configuration mechanisms in addition to + the command-line arguments listed below. + + $GCALCLI_CONFIG=/some/gcalcli/config + Path to user config directory. + Note: this path is also used to determine fallback paths to check + for cache/oauth files to be migrated into their proper data dir + paths. + + /some/gcalcli/config/config.toml + A toml config file where some general-purpose settings can be + configured. + Schema: + https://raw.githubusercontent.com/insanum/gcalcli/HEAD/data/config-schema.json + + gcalclirc @ /some/gcalcli/config/gcalclirc + A flag file listing additional command-line args to always pass, + one per line. + Note: Use this sparingly and prefer other configuration mechanisms + where available. This flag file mechanism can be brittle + (example: https://github.com/insanum/gcalcli/issues/513). + +positional arguments: + {list,search,edit,delete,agenda,agendaupdate,updates,conflicts,calw,calm,quick,add,import,remind} + Invoking a subcommand with --help prints + subcommand usage. + list list available calendars + search search for events within an optional time + period + edit edit calendar events + delete delete events from the calendar + agenda get an agenda for a time period + agendaupdate update calendar from agenda TSV file + updates get updates since a datetime for a time period + (defaults to through end of current month) + conflicts find event conflicts + calw get a week-based agenda in calendar format + calm get a month agenda in calendar format + quick quick-add an event to a calendar + add add a detailed event to the calendar + import import an ics/vcal file to a calendar + remind execute command if event occurs within + time + +options: + -h, --help show this help message and exit + --version show program's version number and exit + --client-id CLIENT_ID + API client_id (default: None) + --client-secret CLIENT_SECRET + API client_secret (default: None) + --noauth_local_server + Provide instructions for authenticating from a + remote system using port forwarding. Note: + Previously this option invoked an "Out-Of- + Band" variant of the auth flow, but that + deprecated mechanism is no longer supported. + (default: True) + --config-folder CONFIG_FOLDER + Optional directory used to load config files. + Deprecated: prefer $GCALCLI_CONFIG. (default: + /some/gcalcli/config) + --noincluderc Whether to include ~/.gcalclirc when using + configFolder (default: True) + --calendar CALENDAR Which calendars to use, in the format + "CalendarName" or "CalendarName#color", where + the #color suffix is the name of a valid ANSI + color (such as "brightblue"). This option may + be called multiple times to display additional + calendars. (default: []) + --default-calendar DEFAULTCALENDAR + Optional default calendar to use if no + --calendar options are given (default: []) + --locale LOCALE System locale (default: ) + --refresh Delete and refresh cached data (default: + False) + --nocache Execute command without using cache (default: + True) + --conky Use Conky color codes (default: False) + --nocolor Enable/Disable all color output (default: + True) + --lineart {fancy,unicode,ascii} + Choose line art style for calendars: "fancy": + for VTcodes, "unicode" for Unicode box drawing + characters, "ascii" for old-school plusses, + hyphens and pipes. (default: fancy) diff --git a/tests/cli/test.bats b/tests/cli/test.bats index 00ca8df..416f323 100644 --- a/tests/cli/test.bats +++ b/tests/cli/test.bats @@ -2,20 +2,23 @@ setup() { load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' load 'test_helper/bats-snapshot/load' + export GCALCLI_USERLESS_MODE=1 } @test "can run" { run gcalcli + assert_equal $status 2 assert_output --regexp 'usage: .*error:.*required: .*command' } @test "prints correct help" { - run gcalcli -h - assert_output --regexp 'positional arguments:.*list.*search.*edit.*options:' + GCALCLI_CONFIG=/some/gcalcli/config COLUMNS=72 run gcalcli -h + assert_success + assert_snapshot } @test "can run add" { - GCALCLI_USERLESS_MODE=1 run gcalcli add <<< "sometitle + run gcalcli add <<< "sometitle tomorrow