summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck8
-rw-r--r--echo.sh2
-rw-r--r--templates/bash/assert.sh19
-rw-r--r--templates/bash/cap.sh17
-rw-r--r--templates/bash/ctx.sh17
-rw-r--r--templates/bash/dict.sh50
-rw-r--r--templates/bash/files.sh22
-rw-r--r--templates/bash/template.sh130
-rw-r--r--templates/bash/template.yaml6
9 files changed, 146 insertions, 125 deletions
diff --git a/check b/check
index 47857d2..ccd978d 100755
--- a/check
+++ b/check
@@ -49,6 +49,12 @@ then
$hideok flake8 templates/python lib/*.py --exclude=template.py
fi
+if command -v shellcheck > /dev/null
+then
+ shellcheck check ./*.sh
+ find templates/bash -name '*.sh' ! -name template.sh -exec shellcheck '{}' +
+fi
+
$hideok cargo build --all-targets
if cargo --list | awk '{ print $1 }' | grep 'clippy$' > /dev/null
then
@@ -67,7 +73,7 @@ then
-exec black --check '{}' +
fi
-for md in [^CR]*.md lib/*.md
+for md in [!CR]*.md lib/*.md
do
$hideok echo "$md ====================================="
codegen "$md" test.py
diff --git a/echo.sh b/echo.sh
index 44f272a..0564d42 100644
--- a/echo.sh
+++ b/echo.sh
@@ -1,3 +1,5 @@
+#!/bin/bash
+
_run()
{
if "$@" < /dev/null > stdout 2> stderr
diff --git a/templates/bash/assert.sh b/templates/bash/assert.sh
new file mode 100644
index 0000000..43bb11b
--- /dev/null
+++ b/templates/bash/assert.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# Check two values for equality and give error if they are not equal
+assert_eq() {
+ if ! diff -u <(echo "$1") <(echo "$2")
+ then
+ echo "expected values to be identical, but they're not"
+ exit 1
+ fi
+}
+
+# Check first value contains second value.
+assert_contains() {
+ if ! echo "$1" | grep -F "$2" > /dev/null
+ then
+ echo "expected first value to contain second value"
+ exit 1
+ fi
+}
diff --git a/templates/bash/cap.sh b/templates/bash/cap.sh
new file mode 100644
index 0000000..8ea35d8
--- /dev/null
+++ b/templates/bash/cap.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# Store step captures for calling the corresponding functions.
+
+cap_new() {
+ dict_new _cap
+}
+
+cap_set()
+{
+ dict_set _cap "$1" "$2"
+}
+
+cap_get()
+{
+ dict_get _cap "$1"
+}
diff --git a/templates/bash/ctx.sh b/templates/bash/ctx.sh
new file mode 100644
index 0000000..c9401c6
--- /dev/null
+++ b/templates/bash/ctx.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# A context abstraction using dictionaries.
+
+ctx_new() {
+ dict_new _ctx
+}
+
+ctx_set()
+{
+ dict_set _ctx "$1" "$2"
+}
+
+ctx_get()
+{
+ dict_get _ctx "$1"
+}
diff --git a/templates/bash/dict.sh b/templates/bash/dict.sh
new file mode 100644
index 0000000..aea5b96
--- /dev/null
+++ b/templates/bash/dict.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+# Simple dictionary abstraction. All values are stored in files so
+# they can more easily be inspected.
+
+dict_new() {
+ local name="$1"
+ rm -rf "$name"
+ mkdir "$name"
+}
+
+dict_has() {
+ local name="$1"
+ local key="$2"
+ local f="$name/$key"
+ test -e "$f"
+}
+
+dict_get() {
+ local name="$1"
+ local key="$2"
+ local f="$name/$key"
+ cat "$f"
+}
+
+dict_get_default() {
+ local name="$1"
+ local key="$2"
+ local default="$3"
+ local f="$name/$key"
+ if [ -e "$f" ]
+ then
+ cat "$f"
+ else
+ echo "$default"
+ fi
+}
+
+dict_set() {
+ local name="$1"
+ local key="$2"
+ local value="$3"
+ local f="$name/$key"
+ echo "$value" > "$f"
+}
+
+dict_keys() {
+ local name="$1"
+ ls -1 "$name"
+}
diff --git a/templates/bash/files.sh b/templates/bash/files.sh
new file mode 100644
index 0000000..50c935d
--- /dev/null
+++ b/templates/bash/files.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# Store files embedded in the markdown input.
+
+files_new() {
+ dict_new _files
+}
+
+files_set() {
+ dict_set _files "$1" "$2"
+}
+
+files_get() {
+ dict_get _files "$1"
+}
+
+
+# Decode a base64 encoded string.
+
+decode_base64() {
+ echo "$1" | base64 -d
+}
diff --git a/templates/bash/template.sh b/templates/bash/template.sh
index 565fa66..5e92371 100644
--- a/templates/bash/template.sh
+++ b/templates/bash/template.sh
@@ -14,131 +14,13 @@ set -eu -o pipefail
#############################################################################
-# Helper code generated by Subplot.
+# Scaffolding for generated test program.
-
-# Simple dictionary abstraction. All values are stored in files so
-# they can more easily be inspected.
-
-dict_new() {
- local name="$1"
- rm -rf "$name"
- mkdir "$name"
-}
-
-dict_has() {
- local name="$1"
- local key="$2"
- local f="$name/$key"
- test -e "$f"
-}
-
-dict_get() {
- local name="$1"
- local key="$2"
- local f="$name/$key"
- cat "$f"
-}
-
-dict_get_default() {
- local name="$1"
- local key="$2"
- local default="$3"
- local f="$name/$key"
- if [ -e "$f" ]
- then
- cat "$f"
- else
- echo "$default"
- fi
-}
-
-dict_set() {
- local name="$1"
- local key="$2"
- local value="$3"
- local f="$name/$key"
- echo "$value" > "$f"
-}
-
-dict_keys() {
- local name="$1"
- ls -1 "$name"
-}
-
-
-# A context abstraction using dictionaries.
-
-ctx_new() {
- dict_new _ctx
-}
-
-ctx_set()
-{
- dict_set _ctx "$1" "$2"
-}
-
-ctx_get()
-{
- dict_get _ctx "$1"
-}
-
-
-# Store step captures for calling the corresponding functions.
-
-cap_new() {
- dict_new _cap
-}
-
-cap_set()
-{
- dict_set _cap "$1" "$2"
-}
-
-cap_get()
-{
- dict_get _cap "$1"
-}
-
-
-# Store files embedded in the markdown input.
-
-files_new() {
- dict_new _files
-}
-
-files_set() {
- dict_set _files "$1" "$2"
-}
-
-files_get() {
- dict_get _files "$1"
-}
-
-
-# Decode a base64 encoded string.
-
-decode_base64() {
- echo "$1" | base64 -d
-}
-
-# Check two values for equality and give error if they are not equal
-assert_eq() {
- if ! diff -u <(echo "$1") <(echo "$2")
- then
- echo "expected values to be identical, but they're not"
- exit 1
- fi
-}
-
-# Check first value contains second value.
-assert_contains() {
- if ! echo "$1" | grep -F "$2" > /dev/null
- then
- echo "expected first value to contain second value"
- exit 1
- fi
-}
+{% include "dict.sh" %}
+{% include "ctx.sh" %}
+{% include "cap.sh" %}
+{% include "files.sh" %}
+{% include "assert.sh" %}
# Remember where we started from. The step functions may need to refer
# to files there.
diff --git a/templates/bash/template.yaml b/templates/bash/template.yaml
index b542a06..16a7523 100644
--- a/templates/bash/template.yaml
+++ b/templates/bash/template.yaml
@@ -1,2 +1,8 @@
template: template.sh
run: bash
+helpers:
+ - assert.sh
+ - cap.sh
+ - ctx.sh
+ - dict.sh
+ - files.sh