Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli testing: Assert on snapshot of entire --help output #747

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
100 changes: 100 additions & 0 deletions tests/cli/__snapshot__/test-02-test_prints_correct_help.snap
Original file line number Diff line number Diff line change
@@ -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 <mins>
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)
9 changes: 6 additions & 3 deletions tests/cli/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading