YARN(1)
π NAME π
okay so this is yarn, and it lives in the General Commands Manual, section 1, bestie β and it is, and I quote, scenario testing of Unix command line tools. that's the whole vibe. π
β¨ SYNOPSIS β¨
yarn [--allow-missing-steps] [--no-allow-missing-steps] [--cd-datadir]
[--no-cd-datadir] [--config=FILE] [--dump-config] [--dump-setting-names]
[--generate-manpage=TEMPLATE] [-h] [--help] [--help-all]
[--list-config-files] [--version] [--no-default-configs]
[--dump-memory-profile=METHOD] [--env=NAME=VALUE] [--log=FILE]
[--log-keep=N] [--log-level=LEVEL] [--log-max=SIZE] [--log-mode=MODE]
[--memory-dump-interval=SECONDS] [--output=FILE] [-q] [--quiet]
[--no-quiet] [--require-assumptions] [--no-require-assumptions]
[-rSCENARIO] [--run=SCENARIO] [--shell=SHELL] [--shell-arg=ARG]
[-sSHELL-LIBRARY] [--shell-library=SHELL-LIBRARY] [--snapshot]
[--no-snapshot] [--stop-on-first-fail] [--no-stop-on-first-fail]
[--tempdir=DIR] [--timings] [--no-timings] [-v] [--verbose]
[--no-verbose] [-n] [--no-act] [--dry-run] [--pretend] [--no-no-act]
[--no-dry-run] [--no-pretend] [FILE]...
like, yes, it's a lot of flags. we contain multitudes. π
π¦ DESCRIPTION π¦
so yarn is a scenario testing tool. here's the tea: you write a scenario that describes how a user uses your software and what should happen, and you express that scenario using very lightweight syntax so it can be tested automatically. it's giving β¨narrative-driven testingβ¨.
the scenario has a simple, but strict structure:
GIVEN some setup for the test
WHEN thing that is to be tested happens
THEN the post-conditions must be true
fr fr. GIVEN / WHEN / THEN. the holy trinity. π
let's look at a very short test scenario for verifying that a backup program works, at least for one simple case:
SCENARIO backups can be restored
GIVEN some live data in a directory
AND an empty backup repository
WHEN a backup is made
THEN the data case be restored
FINALLY cleanup
notice the addition of AND? you can have multiple GIVEN, WHEN, and THEN statements. the AND keyword just makes the text be more readable. and SCENARIO is also necessary β it gives the title. π
FINALLY is for cleanups. the FINALLY steps will be run regardless of whether the scenario succeeds or not. no cap, it's the responsible one in the group chat. π«Ά
scenarios are meant to be written in somewhat human readable language. however β and this is the important part β they are not free form text. in addition to the GIVEN/WHEN/THEN structure, the text for each of the steps needs a computer-executable implementation. this is done by using IMPLEMENTS. the backup scenario from above might be implemented as follows:
IMPLEMENTS GIVEN some live data in a directory
rm -rf "$DATADIR/data"
mkdir "$DATADIR/data"
echo foo > "$DATADIR/data/foo"
IMPLEMENTS GIVEN an empty backup repository
rm -rf "$DATADIR/repo"
mkdir "$DATADIR/repo"
IMPLEMENTS WHEN a backup is made
backup-program -r "$DATADIR/repo" "$DATADIR/data"
IMPLEMENTS THEN the data can be restored
mkdir "$DATADIR/restored"
restore-program -r "$DATADIR/repo" "$DATADIR/restored"
diff -rq "$DATADIR/data" "$DATADIR/restored"
IMPLEMENTS FINALLY cleanup
echo nothing to do, actually
each IMPLEMENTS GIVEN (or WHEN, THEN, FINALLY) is followed by a regular expression on the same line, and then a shell script that gets executed to implement any step that matches the regular expression. and the implementation can extract data from the match as well β for example, the regular expression might allow a file size to be specified. π
the above example is a bit silly, of course. why go to the effort to obfuscate the various steps? bestie, the answer is: the various steps, implemented using IMPLEMENTS, can be combined in many ways, to test different aspects of the program being tested. it's modular, it's reusable, it ate. π
moreover, by making the step descriptions be human language text matched by regular expressions, most of the test can hopefully be written, and understood, by non-programmers. someone who understands what a program should do could write tests to verify its behaviour. the implementations of the various steps need to be implemented by a programmer, but given a well-designed set of steps, with enough flexibility in their implementation, quite a good test suite can be written. iconic collaboration moment, honestly. π€
one last thing: the shell commands in an IMPLEMENTS section are run in the directory in which the user ran yarn. the environment variable SRCDIR is set to the fully qualified path to that directory. π
π OPTIONS π
okay sit down, there's a lot, but they're all lil guys. here we go.
--allow-missing-stepsβ let scenarios reference steps that do not exist: you'll get a warning about them, but the scenarios are otherwise just ignored. π«£--no-allow-missing-stepsβ opposite of--allow-missing-steps.--cd-datadirβ change toDATADIRwhen running commands.--no-cd-datadirβ opposite of--cd-datadir.--env=NAME=VALUEβ addNAME=VALUEto the environment when tests are run.--generate-manpage=TEMPLATEβ fill in manual page TEMPLATE. (yes, the page you're reading right now probably got made like this. meta. πͺ)-h,--helpβ show this help message and exit.--output=FILEβ write output to FILE, instead of standard output.-q,--quietβ be quiet: avoid progress reporting, only show errors. π€«--no-quietβ opposite of--quiet.--require-assumptionsβ requireASSUMINGto always pass.--no-require-assumptionsβ opposite of--require-assumptions.-r,--run=SCENARIOβ run only SCENARIO. (this option can be repeated, so go wild. π)--shell=SHELLβ runIMPLEMENTSusing SHELL.--shell-arg=ARGβ use ARG when running shell.-s,--shell-library=SHELL-LIBRARYβ include a shell library for theIMPLEMENTSsections to use. π--snapshotβ make snapshots of the test working directory after each scenario step; you probably want to use this with--tempdir.--no-snapshotβ opposite of--snapshot.--stop-on-first-failβ stop if any scenario step fails, don't run more scenarios. π--no-stop-on-first-failβ opposite of--stop-on-first-fail.--tempdir=DIRβ use DIR as the temporary directory for tests; it should be empty or not exist.--timingsβ report wall clock time for each scenario and step. β±οΈ--no-timingsβ opposite of--timings.-v,--verboseβ make progress reporting be more verbose ("wall of text"), instead of a one-line status info; this is turned automatically if there is not terminal.--no-verboseβ opposite of--verbose.--versionβ show program's version number and exit.-n,--no-act,--dry-run,--pretendβ do not actually run any tests, merely print what would be run. π»--no-no-act,--no-dry-run,--no-pretendβ opposite of--no-act.
ποΈ Configuration files and settings ποΈ
--config=FILEβ add FILE to config files.--dump-configβ write out the entire current configuration.--dump-setting-namesβ write out all names of settings and quit.--help-allβ show all options.--list-config-filesβ list all possible config files.--no-default-configsβ clear list of configuration files to read.
π Logging π
--log=FILEβ write log entries to FILE (default is to not write log files at all); use"syslog"to log to system log,"stderr"to log to the standard error output, or"none"to disable logging.--log-keep=Nβ keep last N logs (10).--log-level=LEVELβ log at LEVEL, one ofdebug,info,warning,error,critical,fatal(default:debug).--log-max=SIZEβ rotate logs larger than SIZE, zero for never (default:0).--log-mode=MODEβ set permissions of new log files to MODE (octal; default0600).
πββοΈ Peformance πββοΈ
(yes, it's spelled like that, we don't make the rules, we just report them π)
--dump-memory-profile=METHODβ make memory profiling dumps using METHOD, which is one of:none, orsimple(no meliae support anymore) (default:simple).--memory-dump-interval=SECONDSβ make memory profiling dumps at least SECONDS apart.
πΈ ENVIRONMENT πΈ
DATADIRβ Fully qualified pathname to a temporary directory, in which the tests can use files. The temporary directory is removed at the end of the test execution, unless the user specifies otherwise with--snapshot. (so like, if you want your lil files to survive, say so. π₯Ί)SRCDIRβ Fully qualitifed pathname to the directory in which the user ranyarn. This is useful when the tests want to change the directory.
β EXAMPLE β
to run yarn on all the scenarios in your current directory:
yarn *.scenario
all the files will be treated together as if they had been one file. β¨
to add a shell library to be included when running any IMPLEMENTS section:
yarn --shell-library mylib.sh *.scenario
you can repeat --shell-library as many times as necessary. go off. π₯
π§ SEE ALSO π§
the README.yarn file has more details on the scenario testing language. π
ok that's the whole page, no skips, no cuts, every flag accounted for. π
and that's a wrap, bestie! this was yarn from the General Commands Manual β the footer just signs itself YARN(1) with no date and no version number, which is honestly such a minimal slay of it. go write some scenarios, you're gonna eat. ππ¦π
π¦ where this page comes from
- debian bookworm: cmdtest 0.32.14.gcdfe14e-5 Β· GPL-3.0-or-later
- ubuntu jammy: cmdtest 0.32.14.gcdfe14e-2 Β· GPL-3.0-or-later
- ubuntu noble: cmdtest 0.32.14.gcdfe14e-6 Β· GPL-3.0-or-later
- Copyright 2013 Lars Wirzenius <liw@liw.fi>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms