Examples
Real-world examples of Hone test files. Copy and adapt these for your own CLI tests.
Basic
Simple command and file assertions to get started.
# Example hone test file
#! shell: /bin/bash
TEST "echo test"
RUN echo: echo "hello world"
ASSERT exit_code == 0
ASSERT stdout contains "hello"
ASSERT stdout contains "world"
TEST "file creation"
RUN echo "test content" > /tmp/hone-test-file.txt
ASSERT exit_code == 0
ASSERT file "/tmp/hone-test-file.txt" exists
ASSERT file "/tmp/hone-test-file.txt" contains "test content"
TEST "error handling"
RUN false
ASSERT exit_code != 0 Assertions
Comprehensive examples of all assertion types.
# Comprehensive assertion examples
#! shell: /bin/bash
TEST "stdout contains assertion"
RUN echo "Hello, World!"
ASSERT stdout contains "Hello"
ASSERT stdout contains "World"
ASSERT stdout contains ","
TEST "stdout equals assertion"
RUN printf "exact output"
ASSERT stdout == "exact output"
TEST "stdout not equals assertion"
RUN echo "some output"
ASSERT stdout != "different output"
TEST "stdout regex matching"
RUN echo "Version 1.2.3"
ASSERT stdout matches /Version \d+\.\d+\.\d+/
TEST "case insensitive regex"
RUN echo "Hello World"
ASSERT stdout matches /hello world/i
TEST "exit code assertions"
RUN true
ASSERT exit_code == 0
RUN false
ASSERT exit_code != 0
# Use subshell for exit to prevent killing the shell session
RUN (exit 42)
ASSERT exit_code == 42
TEST "stderr capture"
RUN sh -c 'echo "error message" >&2'
ASSERT stderr contains "error message"
TEST "named run targets"
RUN first: echo "first command"
RUN second: echo "second command"
ASSERT first.stdout contains "first"
ASSERT second.stdout contains "second"
ASSERT first.exit_code == 0
ASSERT second.exit_code == 0 Environment
Setting and using environment variables in tests.
# Environment variable tests
#! shell: /bin/bash
#! env: MY_VAR=hello
TEST "environment from pragma"
RUN echo $MY_VAR
ASSERT exit_code == 0
ASSERT stdout contains "hello"
TEST "environment from ENV statement"
ENV GREETING=world
RUN echo $GREETING
ASSERT exit_code == 0
ASSERT stdout contains "world"
TEST "environment variable expansion"
ENV NAME=hone
RUN echo "Testing $NAME framework"
ASSERT stdout contains "Testing hone framework"
TEST "multiple env vars"
ENV FOO=bar
ENV BAZ=qux
RUN echo "$FOO $BAZ"
ASSERT stdout contains "bar qux" Filesystem
File existence and content assertions.
# Filesystem assertion examples
#! shell: /bin/bash
TEST "file exists assertion"
RUN touch /tmp/hone-test-exists.txt
ASSERT file "/tmp/hone-test-exists.txt" exists
TEST "file content assertions"
RUN echo "test content here" > /tmp/hone-test-content.txt
ASSERT file "/tmp/hone-test-content.txt" exists
ASSERT file "/tmp/hone-test-content.txt" contains "test content"
ASSERT file "/tmp/hone-test-content.txt" contains "here"
TEST "file exact match"
RUN printf "exact file content" > /tmp/hone-test-exact.txt
ASSERT file "/tmp/hone-test-exact.txt" == "exact file content"
TEST "file regex match"
RUN echo "Version: 2.0.1" > /tmp/hone-test-version.txt
ASSERT file "/tmp/hone-test-version.txt" matches /Version: \d+\.\d+\.\d+/
TEST "directory operations"
RUN mkdir -p /tmp/hone-test-dir
RUN touch /tmp/hone-test-dir/nested-file.txt
ASSERT file "/tmp/hone-test-dir/nested-file.txt" exists
TEST "cleanup files"
RUN rm -f /tmp/hone-test-exists.txt /tmp/hone-test-content.txt /tmp/hone-test-exact.txt /tmp/hone-test-version.txt
RUN rm -rf /tmp/hone-test-dir
ASSERT exit_code == 0 Shell State
Persistent shell sessions, variables, and working directories.
# Shell state persistence tests
#! shell: /bin/bash
TEST "working directory persists"
RUN cd /tmp
RUN pwd
ASSERT stdout contains "/tmp"
TEST "shell variables persist"
RUN MY_SHELL_VAR="persistent value"
RUN echo $MY_SHELL_VAR
ASSERT stdout contains "persistent value"
TEST "command chaining"
RUN echo "step1" && echo "step2"
ASSERT stdout contains "step1"
ASSERT stdout contains "step2"
TEST "pipeline commands"
RUN echo "hello world" | tr 'a-z' 'A-Z'
ASSERT stdout contains "HELLO WORLD"
TEST "command substitution"
RUN echo "Current shell: $(basename $SHELL)"
ASSERT stdout contains "Current shell:"
TEST "arithmetic in shell"
RUN echo $((2 + 3))
ASSERT stdout contains "5"
TEST "conditional execution"
RUN true && echo "success"
ASSERT stdout contains "success"
RUN false || echo "fallback"
ASSERT stdout contains "fallback" Strings
String literal handling and escape sequences.
# String literal and escape sequence tests
#! shell: /bin/bash
TEST "double quoted strings with escapes"
RUN echo "line1\nline2"
ASSERT stdout contains "line1"
TEST "single quoted strings are literal"
RUN echo 'no escape: \n stays as-is'
# In the assertion, use \\n to match a literal backslash-n
ASSERT stdout contains "\\n"
TEST "tab escape sequence"
RUN printf "col1\tcol2"
ASSERT stdout contains "col1"
ASSERT stdout contains "col2"
TEST "special characters in strings"
RUN echo "hello 'world'"
ASSERT stdout contains "hello 'world'"
TEST "unicode characters"
RUN echo "Unicode: ✓ ✗ → ←"
ASSERT stdout contains "✓"
ASSERT stdout contains "→"
TEST "empty output handling"
RUN printf ""
ASSERT exit_code == 0
TEST "multiline output"
RUN printf "line1\nline2\nline3"
ASSERT stdout contains "line1"
ASSERT stdout contains "line2"
ASSERT stdout contains "line3" Ready to write your own tests?
Get started with the documentation to learn all the features.
Read the Docs