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

load environment

ASSERTION_SOURCE="$_GO_CORE_DIR/tests/assertion-test-helpers.bash"
load "$_GO_CORE_DIR/lib/bats/assertion-test-helpers"

EXPECT_ASSERTION_TEST_SCRIPT="run-expect-assertion.bats"

setup() {
  test_filter
  export ASSERTION=
}

teardown() {
  remove_bats_test_dirs
}

emit_debug_info() {
  printf 'STATUS: %s\nOUTPUT:\n%s\n' "$status" "$output" >&2
}

run_assertion_test() {
  local expected_output=("${@:2}")
  local expected_output_line

  ASSERTION="expect_assertion_${1}"
  ASSERTION+=" 'echo foo bar baz' 'test_assertion \"\$output\"'"

  for expected_output_line in "${expected_output[@]}"; do
    ASSERTION+=$' \\\n    '"'$expected_output_line'"
  done

  create_bats_test_script "$EXPECT_ASSERTION_TEST_SCRIPT" \
    '#! /usr/bin/env bats' \
    '' \
    "ASSERTION_SOURCE='$ASSERTION_SOURCE'" \
    ". '$_GO_CORE_DIR/lib/bats/assertion-test-helpers'" \
    '' \
    "@test \"$BATS_TEST_DESCRIPTION\" {" \
    "  $ASSERTION" \
    '}'
  run "$BATS_TEST_ROOTDIR/$EXPECT_ASSERTION_TEST_SCRIPT"
}

@test "$SUITE: printf_with_error" {
  run printf_with_error 'foo bar baz'
  emit_debug_info
  [ "$status" -eq '1' ]
  [ "$output" == 'foo bar baz' ]

  PRINTF_ERROR='127' run printf_with_error 'foo bar baz'
  emit_debug_info
  [ "$status" -eq '127' ]
  [ "$output" == 'foo bar baz' ]
}

@test "$SUITE: printf_to_test_output_file" {
  run printf_to_test_output_file 'foo bar baz'
  emit_debug_info
  [ "$status" -eq '0' ]
  [ -z "$output" ]
  [ "$(< "$TEST_OUTPUT_FILE")" == 'foo bar baz' ]
}

@test "$SUITE: error if ASSERTION_SOURCE not set" {
  ASSERTION_SOURCE= run_assertion_test
  emit_debug_info
  [ "$status" -eq '1' ]

  local err_msg='"ASSERTION_SOURCE" must be set before sourcing '
  err_msg+="$_GO_CORE_DIR/lib/bats/assertion-test-helpers."
  [ "$output" == "$err_msg" ]
}<commit_msg>assertion-helpers: Add successful assertion test<commit_after>#! /usr/bin/env bats

load environment

ASSERTION_SOURCE="$_GO_CORE_DIR/tests/assertion-test-helpers.bash"
load "$_GO_CORE_DIR/lib/bats/assertion-test-helpers"

EXPECT_ASSERTION_TEST_SCRIPT="run-expect-assertion.bats"

setup() {
  test_filter
  export ASSERTION=
}

teardown() {
  remove_bats_test_dirs
}

emit_debug_info() {
  printf 'STATUS: %s\nOUTPUT:\n%s\n' "$status" "$output" >&2
}

run_assertion_test() {
  local expected_output=("${@:2}")
  local expected_output_line

  ASSERTION="expect_assertion_${1}"
  ASSERTION+=" 'echo foo bar baz' 'test_assertion \"\$output\"'"

  for expected_output_line in "${expected_output[@]}"; do
    ASSERTION+=$' \\\n    '"'$expected_output_line'"
  done

  create_bats_test_script "$EXPECT_ASSERTION_TEST_SCRIPT" \
    '#! /usr/bin/env bats' \
    '' \
    "ASSERTION_SOURCE='$ASSERTION_SOURCE'" \
    ". '$_GO_CORE_DIR/lib/bats/assertion-test-helpers'" \
    '' \
    "@test \"$BATS_TEST_DESCRIPTION\" {" \
    "  $ASSERTION" \
    '}'
  run "$BATS_TEST_ROOTDIR/$EXPECT_ASSERTION_TEST_SCRIPT"
}

@test "$SUITE: printf_with_error" {
  run printf_with_error 'foo bar baz'
  emit_debug_info
  [ "$status" -eq '1' ]
  [ "$output" == 'foo bar baz' ]

  PRINTF_ERROR='127' run printf_with_error 'foo bar baz'
  emit_debug_info
  [ "$status" -eq '127' ]
  [ "$output" == 'foo bar baz' ]
}

@test "$SUITE: printf_to_test_output_file" {
  run printf_to_test_output_file 'foo bar baz'
  emit_debug_info
  [ "$status" -eq '0' ]
  [ -z "$output" ]
  [ "$(< "$TEST_OUTPUT_FILE")" == 'foo bar baz' ]
}

@test "$SUITE: error if ASSERTION_SOURCE not set" {
  ASSERTION_SOURCE= run_assertion_test
  emit_debug_info
  [ "$status" -eq '1' ]

  local err_msg='"ASSERTION_SOURCE" must be set before sourcing '
  err_msg+="$_GO_CORE_DIR/lib/bats/assertion-test-helpers."
  [ "$output" == "$err_msg" ]
}

@test "$SUITE: successful assertion" {
  run_assertion_test 'success'
  emit_debug_info
  [ "$status" -eq '0' ]
  [ "$output" == $'1..1\nok 1 '"$BATS_TEST_DESCRIPTION" ]
}
{'fraction_non_alphanumeric': 0.16436605316973416, 'fraction_numerical': 0.007157464212678937, 'mean_word_length': 4.273584905660377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1537024', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1547, 'n_words': 270}