Skip to content

Commit

Permalink
Initial commit - based on standard project template
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 7, 2018
0 parents commit c3d319f
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

[*.sh]
indent_style = space
indent_size = 2

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Created by .ignore support plugin (hsz.mobi)
### Rust template
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

/.idea/

/callgrind.profile
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "grit-cli"
version = "1.0.0"
authors = ["Sebastian Thiel <[email protected]>"]
publish = false

[dependencies]
failure = "0.1.1"
failure-tools = "4.0.2"

[[bin]]
name="grit"
path="src/main.rs"

[profile.release]
panic = 'unwind'
incremental = false
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
fixture = tests/fixtures/input.txt
bench_fixture = tests/fixtures/big-input.txt
docker_image = gitrs_docker_developer_environment

help:
$(info -Targets -----------------------------------------------------------------------------)
$(info -- Use docker for all dependencies - run make interactively from there ----------------)
$(info interactive-developer-environment-in-docker | gives you everything you need to run all targets)
$(info -Development Targets -----------------------------------------------------------------)
$(info lint | run lints with clippy)
$(info benchmark | just for fun, really)
$(info profile | only on linux - run callgrind and annotate it)
$(info journey-tests | run all stateless journey test)
$(info continuous-journey-tests | run all stateless journey test whenever something changes)

always:

interactive-developer-environment-in-docker:
docker build -t $(docker_image) - < etc/developer.Dockerfile
docker run -v $$PWD:/volume -w /volume -it $(docker_image)

target/debug/rit: always
cargo build

target/release/rit: always
cargo build --release

lint:
cargo clippy

profile: target/release/rit
valgrind --callgrind-out-file=callgrind.profile --tool=callgrind $< $(bench_fixture) >/dev/null
callgrind_annotate --auto=yes callgrind.profile

benchmark: target/release/rit
hyperfine '$< $(bench_fixture)'

journey-tests: target/debug/rit
./tests/stateless-journey.sh $<

continuous-journey-tests:
watchexec $(MAKE) journey-tests

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Goal

TBD
8 changes: 8 additions & 0 deletions etc/developer.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from guangie88/rustfmt-clippy:nightly

run cargo install hyperfine watchexec

run apt-get update
run apt-get install -y valgrind

env PATH=$PATH:/root/.cargo/bin
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extern crate failure;
extern crate failure_tools;

fn main() {}
14 changes: 14 additions & 0 deletions tests/stateless-journey.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -eu

exe=${1:?First argument must be the executable to test}

root="$(cd "${0%/*}" && pwd)"
# shellcheck disable=1090
source "$root/utilities.sh"
snapshot="$root/snapshots"
fixture="$root/fixtures"

SUCCESSFULLY=0
WITH_FAILURE=1

122 changes: 122 additions & 0 deletions tests/utilities.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/bash

WHITE="$(tput setaf 9 2>/dev/null || echo -n '')"
YELLOW="$(tput setaf 3 2>/dev/null || echo -n '')"
GREEN="$(tput setaf 2 2>/dev/null || echo -n '')"
RED="$(tput setaf 1 2>/dev/null || echo -n '')"
OFFSET=( )
STEP=" "

function title () {
echo "$WHITE-----------------------------------------------------"
echo "${GREEN}$*"
echo "$WHITE-----------------------------------------------------"
}

function _context () {
local name="${1:?}"
shift
echo 1>&2 "${YELLOW}${OFFSET[*]:-}[$name] $*"
OFFSET+=("$STEP")
}

function with () {
_context with "$*"
}

function when () {
_context when "$*"
}

function _note () {
local name="${1:?}"
local color="${2:-}"
shift 2
echo 1>&2 -n "${OFFSET[*]:-}${color}[$name] ${*// /}"
}

function it () {
_note it "${GREEN}" "$*"
}

function precondition () {
_note precondition "${WHITE}" "$*"
}

function shortcoming () {
_note shortcoming "${RED}" "$*"
}

function fail () {
echo 1>&2 "${RED} $*"
exit 1
}

function sandbox () {
sandbox_tempdir="$(mktemp -t sandbox.XXXXXX -d)"
# shellcheck disable=2064
trap "popd >/dev/null" EXIT
pushd "$sandbox_tempdir" >/dev/null \
|| fail "Could not change directory into temporary directory."

local custom_init="${1:-}"
if [ -n "$custom_init" ]; then
eval "$custom_init"
fi
}

function expect_equals () {
expect_run 0 test "${1:?}" = "${2:?}"
}

function expect_exists () {
expect_run 0 test -e "${1:?}"
}

function expect_run_sh () {
expect_run "${1:?}" bash -c "${2:?}"
}

function expect_snapshot () {
local expected=${1:?}
local actual=${2:?}
if ! [ -e "$expected" ]; then
mkdir -p "${expected%/*}"
cp -R "$actual" "$expected"
fi
expect_run 0 diff -r -N "$expected" "$actual"
}

function expect_run () {
local expected_exit_code=$1
shift
local output=
set +e
output="$("$@" 2>&1)"

local actual_exit_code=$?
if [[ "$actual_exit_code" == "$expected_exit_code" ]]; then
if [[ -n "${WITH_SNAPSHOT-}" ]]; then
local expected="$WITH_SNAPSHOT"
if ! [ -f "$expected" ]; then
mkdir -p "${expected%/*}"
echo -n "$output" > "$expected" || exit 1
fi
if ! diff "$expected" <(echo -n "$output"); then
echo 1>&2 "${RED} - FAIL"
echo 1>&2 "${WHITE}\$ $*"
echo 1>&2 "Output snapshot did not match snapshot at '$expected'"
echo 1>&2 "$output"
exit 1
fi
fi
echo 1>&2
else
echo 1>&2 "${RED} - FAIL"
echo 1>&2 "${WHITE}\$ $*"
echo 1>&2 "${RED}Expected actual status $actual_exit_code to be $expected_exit_code"
echo 1>&2 "$output"
exit 1
fi
set -e
}

0 comments on commit c3d319f

Please sign in to comment.