# Scenario step implementations

This chapter has implementations of scenario steps used elsewhere in
this document.


## Should a scenario be run?

We provide a way to control which classes of scenarios get run. This
is done by passing in an environment variable `TESTS` to lwr
(`--env` option), with a comma-separated list of classes:

* `fast`---run fast tests
* `build`---run scenarios that do builds

If `TESTS` is not set, everything gets run.

Scenarios can use the ASSUMING statements defined here to let the user
to allow them to run or not to run.

    IMPLEMENTS ASSUMING (fast|build) tests are requested
    support_required
    test_requested "$MATCH_1"

if `MIRROR` is set, use the default http mirror

    IMPLEMENTS ASSUMING (local|http) tests are requested
    support_required
    build_support_required
    mirror_requested "$MATCH_1"

## Building an image, or attempting to

Attempt to run lwr, but allow it it to fail. Capture exit
code and stderr.

    IMPLEMENTS WHEN user attempts to run lwr (.*)
    if PYTHONPATH="$SRCDIR" "$SRCDIR/bin/lwr" \
        $MATCH_1 2> lwr.stderr 1>lwr.stdout
    then
        echo 0 > lwr.exit
    else
        echo $? > lwr.exit
    fi

Check for whether the attempted lwr run had the desired exit
code.

    IMPLEMENTS THEN lwr exited with a non-zero exit code
    grep -vFx 0 lwr.exit

    IMPLEMENTS THEN lwr exited with a zero exit code
    grep -Fx 0 lwr.exit

Check the stderr of the attempted lwr run.

    IMPLEMENTS THEN lwr wrote an error message matching (.+)
    grep -P -e "$MATCH_1" lwr.stderr

Check the stdout of the dry-run lwr run.

    IMPLEMENTS THEN lwr wrote a message matching (.+)
    grep -P -e "$MATCH_1" lwr.stdout

Exclude a pattern from the stdout of the dry-run lwr run.

    IMPLEMENTS THEN lwr wrote a message not matching (.+)
    grep -P -v -e "$MATCH_1" lwr.stdout

## Static tests on disk images

The steps in this section do static tests of disk image. These all
operate on the image specified in the step "GIVEN user wants to
build...".

# isoinfo -i jessie-live-uefi.iso -ld
# CD-ROM is in ISO 9660 format
# El Torito VD version 1 found, boot catalog is in sector 3031
#         Bootid 88 (bootable)

