# Yarn scenario step implementations This chapter defines the various scenario steps for Yarn so they can be actually executed. Surprise! You didn't know you were reading a test suite! If you're only interested in this document as a manual, you can skip this chapter. ## Checking that the target address is set IMPLEMENTS GIVEN the (.+) variable is set env | grep -F "$MATCH_1=" ## Git repository setup Set up git repository. We add a dummy README file so that the repository has a `master` branch. IMPLEMENTS GIVEN a minimal project repository in (.+) git init "$DATADIR/$MATCH_1" cd "$DATADIR/$MATCH_1" touch README git add README git commit -m "Initial commit" ## Git tagging Add a tag to a repository. IMPLEMENTS GIVEN a git tag (\S+) on tip of (\S+) in (\S+) cd "$DATADIR/$MATCH_3" git tag -a -m "A git tag" "$MATCH_1" "$MATCH_2" ## Ick file handling Create an ick file. IMPLEMENTS GIVEN an ick file (.+).ick containing (.*) # Expand all $foo references. expand_env_vars() { local temp="$(mktemp)" printf '#!/bin/sh\ncat < "$temp" sh "$temp" rm -f "$temp" } expand_env_vars "$MATCH_2" > "$DATADIR/$MATCH_1.ick" ## Running Ick Run ick, capturing its output for later inspection. We run ick in `$DATADIR` so that relative references in the ick file work. IMPLEMENTS WHEN user runs ick (.+).ick cd "$DATADIR" if ! "$SRCDIR/ick" --no-default-config \ --log "$DATADIR/ick.log" \ --verbose \ "$DATADIR/$MATCH_1.ick" \ > "$DATADIR/ick.stdout" 2> "$DATADIR/ick.stderr" then cat "$DATADIR/ick.stdout" cat "$DATADIR/ick.stderr" exit 1 fi Inspect the captured output of the latest ick file. IMPLEMENTS THEN ick build log for (.+) in (.+) contains "(.+)" export PROJECT="$MATCH_1" export STATE="$MATCH_2" export PATTERN="$MATCH_3" builds="$DATADIR/$STATE/$PROJECT/builds" build_log="$(ls "$builds"/*/build.log | tail -n1)" cat "$build_log" grep "$PATTERN" "$build_log" IMPLEMENTS THEN ick build log for (.+) in (.+) doesn't contain "(.+)" export PROJECT="$MATCH_1" export STATE="$MATCH_2" export PATTERN="$MATCH_3" builds="$DATADIR/$STATE/$PROJECT/builds" build_log="$(ls "$builds"/*/build.log | tail -n1)" cat "$build_log" ! grep "$PATTERN" "$build_log" IMPLEMENTS THEN there is (\d+) build log(s?) for (.+) in (.+) export COUNT="$MATCH_1" export PROJECT="$MATCH_3" export STATE="$MATCH_4" builds="$DATADIR/$STATE/$PROJECT/builds" export NUM_BUILDS="$(ls "$builds" | wc -l)" if [ "$NUM_BUILDS" != "$COUNT" ] then echo "Expected $COUNT builds, found $NUM_BUILDS" 1>&2 exit 1 fi ## Creating a git repository We need a git repository with some source code. It should have a master branch, which includes at least one file. We'll create a README file for that. We also add basic Debian packaging, so packages can be built. Following the author's habit, the Debian packaging goes into the master branch as well. IMPLEMENTS GIVEN a source code repository for project (.+) version (.+) gitdir="$DATADIR/$MATCH_1" git init "$gitdir" cd "$gitdir" echo "This is $MATCH_1" > README git add README git commit -m "Add README" printf '#!/bin/sh\necho hello, world\n' > hello chmod +x hello git add hello git commit -m "Add hello" mkdir debian mkdir debian/source echo '3.0 (quilt)' > debian/source/format echo Public domain > debian/copyright echo 9 > debian/compat echo hello usr/bin > debian/install dch --create --package "$MATCH_1" --newversion "$MATCH_2" \ "Initial version." dch -r '' cat << EOF > debian/control Source: $MATCH_1 Maintainer: John Doe Section: python Priority: optional Standards-Version: 3.9.6 Build-Depends: debhelper (>= 7.3.8) Package: $MATCH_1 Architecture: all Depends: \${misc:Depends} Description: this is a test package Test package is this. EOF printf '#!/usr/bin/make -f\n%%:\n\tdh $@\n' > debian/rules chmod +x debian/rules git add debian git commit -m "Add Debian packaging" Create repository with just upstream code. IMPLEMENTS GIVEN an upstream source repository for project (\S+) gitdir="$DATADIR/$MATCH_1" git init "$gitdir" cd "$gitdir" echo "This is $MATCH_1" > README git add README git commit -m "Add README" printf '#!/bin/sh\necho hello, world\n' > hello chmod +x hello git add hello git commit -m "Add hello" Create a git repository with just Debian packaging files. IMPLEMENTS GIVEN a packaging repository called (\S+) for project (\S+) version (\S+) gitdir="$DATADIR/$MATCH_1" PROJECT="$MATCH_2" VERSION="$MATCH_3" git init "$gitdir" cd "$gitdir" mkdir source echo '3.0 (quilt)' > source/format echo Public domain > copyright echo 9 > compat echo hello usr/bin > install export DEVSCRIPTS_CHECK_DIRNAME_LEVEL=0 dch --create --package "$PROJECT" --newversion "$VERSION" \ -c changelog "Initial version." dch -c changelog -r '' cat << EOF > control Source: $PROJECT Maintainer: John Doe Section: python Priority: optional Standards-Version: 3.9.6 Build-Depends: debhelper (>= 7.3.8) Package: $PROJECT Architecture: all Depends: \${misc:Depends} Description: this is a test package Test package is this. EOF printf '#!/usr/bin/make -f\n%%:\n\tdh $@\n' > rules chmod +x rules git add . git commit -m "Add Debian packaging" ## Running "cleanly" We need to run the `cleanly` command in various ways. We invoke it from the Ick source tree, and save the standard output and error, for later investigation. IMPLEMENTS WHEN user runs, in (.+), cleanly (.+) cd "$DATADIR/$MATCH_1" # Note that we do NOT quote the second match. We let the shell # parse it as-is. This is necessary to allow multiple arguments. if ! "$SRCDIR/icklib/cleanly" --no-default-config \ --log "$DATADIR/cleanly.log" \ --results "$DATADIR" $MATCH_2 \ > "$DATADIR/cleanly.stdout" \ 2> "$DATADIR/cleanly.stderr" then echo ==== stdout ==== cat "$DATADIR/cleanly.stdout" echo ==== stderr ==== cat "$DATADIR/cleanly.stderr" 1>&2 echo ==== end of stderr ==== exit 1 fi ## Checking "cleanly" output Check what the output of the latest invocation of `cleanly` was. IMPLEMENTS THEN the output is "(.*)" printf "$MATCH_1" | diff - "$DATADIR/cleanly.stdout" ## Checking if a file exists Does a file exist? IMPLEMENTS THEN file (.+) exists ls -a "$DATADIR" test -e "$DATADIR/$MATCH_1" ## Checking for package files in the APT repository Does a file with a given basename exist in the APT repository's pool tree? IMPLEMENTS THEN the APT repository for (.+)\.ick contains (.+) find "$DATADIR/$MATCH_1.state" find "$DATADIR/$MATCH_1.state/debian/pool" \ -type f -name "$MATCH_2" | grep .