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

# A basic assert utility for sanity checks.
#
# Examples:
#
# function foo() {
#   # We need exactly two parameters.
#   assert_eq $# 2
# }
#
# function bar() {
#   # We need at least two parameters.
#   assert "$# -ge 2"
# }

# To exit immediately from a subshell, we need to
# send a custom signal (in this case, SIGUSR1) to the top-most 
# parent process, and call exit from there.
# This is necessary when, for instance, dictGet is called
# in a subshell (like $(dictGet "dict" "key")).
trap "exit ${E_FAILURE}" USR1
TOP_PID=$$

function _backtrace() {
  echo "backtrace is:"
  i=0
  while caller ${i}
  do
    i=$((i+1))
  done
}

function assert_fail() {
  # Print assert errors to stderr!
  echo "assert failed: \"$1\"" >&2
  _backtrace >&2

  # And crash immediately.
  kill -s USR1 ${TOP_PID}
}

function assert() {
  if [ $# -ne 1 ]
  then  
    assert_fail "assert called with wrong number of parameters!"<commit_msg>assert_fail: Display full failed assertion string.<commit_after>#!/usr/bin/env bash

# A basic assert utility for sanity checks.
#
# Examples:
#
# function foo() {
#   # We need exactly two parameters.
#   assert_eq $# 2
# }
#
# function bar() {
#   # We need at least two parameters.
#   assert "$# -ge 2"
# }

# To exit immediately from a subshell, we need to
# send a custom signal (in this case, SIGUSR1) to the top-most 
# parent process, and call exit from there.
# This is necessary when, for instance, dictGet is called
# in a subshell (like $(dictGet "dict" "key")).
trap "exit ${E_FAILURE}" USR1
TOP_PID=$$

function _backtrace() {
  echo "backtrace is:"
  i=0
  while caller ${i}
  do
    i=$((i+1))
  done
}

function assert_fail() {
  # Print assert errors to stderr!
  echo "assert failed: \"$@\"" >&2
  _backtrace >&2

  # And crash immediately.
  kill -s USR1 ${TOP_PID}
}

function assert() {
  if [ $# -ne 1 ]
  then  
    assert_fail "assert called with wrong number of parameters!"
{'fraction_non_alphanumeric': 0.13078880407124682, 'fraction_numerical': 0.010687022900763359, 'mean_word_length': 3.320879120879121, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4358333', 'n_tokens_mistral': 698, 'n_tokens_neox': 680, 'n_words': 253}