A dead simple functional testing tool for command line applications

Related tags

Command-line pharaoh
Overview

Pharaoh : build that test pyramid!

GitHub Workflow Status GitHub release (latest SemVer) Codecov

What it is

Pharaoh is a dead simple, no permission needed, functional test runner for command line applications, written in Rust.

This tool scans for YAML entries in a folder (by default, the current directory) and run all tests in it.

An example YAML is as follow:

name: this test will succeed
cmd: printf 'foo\n'
stdout: |
  foo
---
name: this test will fail
cmd: printf 'fou\n'
stdout: |
  foo
---
name: cat should work
cmd: cat
stdin: |
  this is a line
stdout: |
  this is a line
---
name: failing for all three reasons
cmd: cat
stdin: |
  my input
stdout: |
  a different output
stderr: |
  an unexpected stderr output
status: 1

For each entry in such a file, Pharaoh will run the given command, feed it the specified stdin, and compare the captured output to the specified stdout, stderr and exit code. If not specified, these values default to respectively empty strings and 0.

Made in TDD, for TDD

Most often, what you will want to run is the program you are working on, and run functional tests over it. Specifically, Pharaoh is made to practice double loop TDD, and should be complemented with unit tests for your project-specific language.

For example, the first few tests for a calculator could be as follows:

name: do nothing if stdin is empty
cmd: ./myevalexpr
---
name: evaluate a single expression
cmd: ./myevalexpr
stdin: |
  2 + 4
stdout: |
  6
---
name: evaluate multiple lines
cmd: ./myevalexpr
stdin: |
  5 + 2
  8 * 5
stdout: |
  7
  40
---
name: handle syntax errors
cmd: ./myevalexpr
stdin: |
  2 + +
stderr: |
  "2 + +": syntax error
status: 1

Installing

Release binaries

Release binaries are available for Linux and MacOS. Please see the release page for all available binaries.

Simply rename the downloaded file to pharaoh, make it executable via chmod +x, and place it somewhere in your $PATH.

Via Cargo

Being developed in Rust, Pharaoh is available via cargo:

$ cargo install pharaoh

Who is this project for?

Pharaoh was designed with school projects and katas in mind, or more generally any kind of short-lived project where building your own tool is not worth it.

It is generally difficult to teach TDD to students, as their project are usually weeks long at most, and no testing tools are provided. Requiring students to develop their own tool in addition to their project is by experience too high of a step, and they default to testing by hand.

In addition, many students use restricted environment with limited permissions, and as such cannot use fancy tools that may use container technologies like docker. Pharaoh is a drop-in static binary that requires no further installation or configuration, and as such is ideal for those use cases.

A guided example: developing an application in double-loop TDD

Coming soon!

You might also like...
CarLI is a framework for creating single-command and multi-command CLI applications in Rust

CarLI is a framework for creating single-command and multi-command CLI applications in Rust. The framework provides error and IO types better suited for the command line environment, especially in cases where unit testing is needed.

Pink is a command-line tool inspired by the Unix man command.

Pink is a command-line tool inspired by the Unix man command. It displays custom-formatted text pages in the terminal using a subset of HTML-like tags.

A command line tool written in Rust and designed to be a modern build tool + package manager for C/C++ projects.

CCake CCake is a command line tool written in Rust and designed to be a modern build tool + package manager for C/C++ projects. Goals To be easily und

Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're working with files or directories, this tool simplifies common file operations with ease.

Rust FileOps Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're w

A simple command line tool for creating font palettes for engines like libtcod

palscii A simple command line tool for creating font palettes for engines like libtcod. Usage This can also be viewed by running palscii --help. palsc

☘️ A simple command line tool to manage your Minecraft Bedrock worlds
☘️ A simple command line tool to manage your Minecraft Bedrock worlds

☘️ Haze A simple command line tool to manage your Minecraft Bedrock worlds Haze allows you to keep your project's worlds out of the com.mojang directo

This is a simple command-line interface tool that allows you to interact with ChatGPT from OpenAI or Azure.

HeyGPT This is a simple command-line interface tool that allows you to interact with ChatGPT from OpenAI or Azure. You can use it to: Chat with ChatGP

Koi is a simple tool built to let you use ChatGPT through the command line

Koi is a simple tool built to let you use ChatGPT through the command line. It adds the ability to let ChatGPT run commands on your computer in order to help you out, or to help you out with complicated tasks.

A simple command-line tool for conversing with ChatGPT

daberu A simple command-line tool for conversing with ChatGPT. "daberu" is a Japanese translation of "chatting". $ daberu -h ChatGPT client tool that

Owner
Kevin Sztern
Kevin Sztern
Functional command-line JSON processor

rq rq is a tiny functional language with which you can manipulate JSON. Basically, it is (an insignificant subset of!) jq, written in Rust. NOTE: This

Tony Zorman 13 Feb 10, 2024
Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

William D. Jones 5 Aug 20, 2022
An attribute macro to simplify writing simple command line applications.

fncli An attribute macro to simplify writing simple command line applications. Example #[fncli::cli] fn main(a: i32, b: i32) { println!("{}", a +

Vidhan Bhatt 29 Dec 15, 2022
A WIP property-based testing library in Rust, built with generalized targeted-property testing in mind.

Crabcheck A WIP property-based testing library in Rust, built with generalized targeted-property testing in mind. What is property-based testing? TODO

Alperen Keleş 9 Mar 27, 2024
A dead simple ANSI terminal color painting library for Rust.

yansi A dead simple ANSI terminal color painting library for Rust. use yansi::Paint; print!("{} light, {} light!", Paint::green("Green"), Paint::red(

Sergio Benitez 169 Dec 25, 2022
A Turing-complete but dead-simple spaced repetition CLI that helps you learn stuff.

Forne — Learn Stuff Forne is a Turing-complete spaced repetition engine to help you learn stuff your way. What does that mean? Well, there are a few p

Sam Brew 9 May 12, 2023
Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.

cargo-hoist Dead simple cargo subcommand to hoist cargo-built binaries into scope. stable Install | User Docs | Crate Docs | Reference | Contributing

refcell.eth 6 Nov 9, 2023
Style terminal outputs in a minimal, macro-based, and dead simple way.

sty ?? $\mathbb{\color{red}{Style \ } \color{lightblue}{terminal}\ \color{black}{outputs \ }\color{gray}{\ in\ a} \color{magenta}{\ minimal}\color{gra

斯人 5 Apr 18, 2024
Upkeep your websites and web applications with ease from the comfort of the command line.

Upkeep Upkeep your websites and web applications with ease from the comfort of the command line. Explore the docs » View Demo · Report Bug · Request F

Kevin B 0 Dec 24, 2021
A structure editor for a simple functional programming language, with Vim-like shortcuts and commands.

dilim A structure editor for a simple functional programming language, with Vim-like shortcuts and commands. Written in Rust, using the Yew framework,

Joomy Korkut 6 Nov 18, 2022