<commit_before>#!/usr/bin/env bash

# no uninitialised variables
set -o nounset

PROGNAME=$(basename $0)
SCRIPTPATH=$( cd $(dirname $0) ; pwd -P )
FAILURES=0

# helper function to print something to stderr
function warn {
  >&2 echo "${PROGNAME}: ${1:-"Unknown Error"}"
}

# basic assertion function. Takes a command that needs to exit with 0 for
# success and a string to print out if it exited with another code.
#
# Parameters:
# $1 - command to execute
# $2 - string to print for error
#
function assert {
  eval "$1"
  if [[ $? != 0 ]]; then
    warn "${2}"
    FAILURES=$((FAILURES+1))
  fi
}

function tear_down {
  warn "cleaning up sandbox.."
  git clean -qfdx ../sandbox
}

# test definitions
function create_default_project {
  warn "running ${FUNCNAME}"
  ../../leoric.sh -s `pwd`/../fixtures -I `pwd`/../fixtures/macros
  assert "test -d tests"   "directory 'tests' not created"
  assert "test -f LICENSE" "file 'LICENSE' not created"
  assert "test -f README.md" "file 'README.md' not created"
  assert "grep -q sandbox README.md 2>/dev/null" "project name substitution not working in README"
}

function create_default_project_with_name {
  warn "running ${FUNCNAME}"
  ../../leoric.sh -s `pwd`/../fixtures -I `pwd`/../fixtures/macros -n the_name
  assert "test -d tests"   "directory 'tests' not created"
  assert "test -f LICENSE" "file 'LICENSE' not created"
  assert "test -f README.md" "file 'README.md' not created"
  assert "grep -q the_name README.md 2>/dev/null" "project name substitution not working in README"
}

function create_ruby_project {
  warn "running ${FUNCNAME}"
  ../../leoric.sh -s `pwd`/../fixtures -I `pwd`/../fixtures/macros -t ruby
  assert "test -d tests"   "directory 'tests' not created"
  assert "test -f LICENSE" "file 'LICENSE' not created"
  assert "test -f README.md" "file 'README.md' not created"
  assert "grep -q sandbox README.md 2>/dev/null" "project name substitution not working in README"
  assert "test -d lib"   "directory 'lib' not created"
  assert "test -f sandbox.gemspec" "file 'sandbox.gemspec' not created"
}

function create_ruby_project_with_name {
  warn "running ${FUNCNAME}"
  ../../leoric.sh -s `pwd`/../fixtures -I `pwd`/../fixtures/macros -t ruby -n the_name
  assert "test -d tests"   "directory 'tests' not created"
  assert "test -f LICENSE" "file 'LICENSE' not created"
  assert "test -f README.md" "file 'README.md' not created"
  assert "grep -q the_name README.md 2>/dev/null" "project name substitution not working in README"
  assert "test -d lib"   "directory 'lib' not created"
  assert "test -f the_name.gemspec" "file 'the_name.gemspec' not created"
}

# go into the sandbox to run tests
cd ${SCRIPTPATH}/sandbox
# run tests
create_default_project tear_down
tear_down
create_default_project_with_name
tear_down
create_ruby_project
tear_down
create_ruby_project_with_name
tear_down

if [[ ${FAILURES} -eq 0 ]]; then
  warn "All tests passed."
  exit 0
else
  warn "There were ${FAILURES} assertion failures."
  exit 1
fi
<commit_msg>account for executable rename in unit tests<commit_after>#!/usr/bin/env bash

# no uninitialised variables
set -o nounset

PROGNAME=$(basename $0)
SCRIPTPATH=$( cd $(dirname $0) ; pwd -P )
FAILURES=0

# helper function to print something to stderr
function warn {
  >&2 echo "${PROGNAME}: ${1:-"Unknown Error"}"
}

# basic assertion function. Takes a command that needs to exit with 0 for
# success and a string to print out if it exited with another code.
#
# Parameters:
# $1 - command to execute
# $2 - string to print for error
#
function assert {
  eval "$1"
  if [[ $? != 0 ]]; then
    warn "${2}"
    FAILURES=$((FAILURES+1))
  fi
}

function tear_down {
  warn "cleaning up sandbox.."
  git clean -qfdx ../sandbox
}

# test definitions
function create_default_project {
  warn "running ${FUNCNAME}"
  ../../leoric -s `pwd`/../fixtures -I `pwd`/../fixtures/macros
  assert "test -d tests"   "directory 'tests' not created"
  assert "test -f LICENSE" "file 'LICENSE' not created"
  assert "test -f README.md" "file 'README.md' not created"
  assert "grep -q sandbox README.md 2>/dev/null" "project name substitution not working in README"
}

function create_default_project_with_name {
  warn "running ${FUNCNAME}"
  ../../leoric -s `pwd`/../fixtures -I `pwd`/../fixtures/macros -n the_name
  assert "test -d tests"   "directory 'tests' not created"
  assert "test -f LICENSE" "file 'LICENSE' not created"
  assert "test -f README.md" "file 'README.md' not created"
  assert "grep -q the_name README.md 2>/dev/null" "project name substitution not working in README"
}

function create_ruby_project {
  warn "running ${FUNCNAME}"
  ../../leoric -s `pwd`/../fixtures -I `pwd`/../fixtures/macros -t ruby
  assert "test -d tests"   "directory 'tests' not created"
  assert "test -f LICENSE" "file 'LICENSE' not created"
  assert "test -f README.md" "file 'README.md' not created"
  assert "grep -q sandbox README.md 2>/dev/null" "project name substitution not working in README"
  assert "test -d lib"   "directory 'lib' not created"
  assert "test -f sandbox.gemspec" "file 'sandbox.gemspec' not created"
}

function create_ruby_project_with_name {
  warn "running ${FUNCNAME}"
  ../../leoric -s `pwd`/../fixtures -I `pwd`/../fixtures/macros -t ruby -n the_name
  assert "test -d tests"   "directory 'tests' not created"
  assert "test -f LICENSE" "file 'LICENSE' not created"
  assert "test -f README.md" "file 'README.md' not created"
  assert "grep -q the_name README.md 2>/dev/null" "project name substitution not working in README"
  assert "test -d lib"   "directory 'lib' not created"
  assert "test -f the_name.gemspec" "file 'the_name.gemspec' not created"
}

# go into the sandbox to run tests
cd ${SCRIPTPATH}/sandbox
# run tests
create_default_project tear_down
tear_down
create_default_project_with_name
tear_down
create_ruby_project
tear_down
create_ruby_project_with_name
tear_down

if [[ ${FAILURES} -eq 0 ]]; then
  warn "All tests passed."
  exit 0
else
  warn "There were ${FAILURES} assertion failures."
  exit 1
fi

{'fraction_non_alphanumeric': 0.13097987462883537, 'fraction_numerical': 0.006268558231606731, 'mean_word_length': 3.703646237393328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2052621', 'n_tokens_mistral': 2127, 'n_tokens_neox': 2062, 'n_words': 726}