<commit_before>#!/usr/bin/env bash
################################################################################
#
# This script tests the D4J's mutation analysis script.
#
################################################################################
# TODO: There is some code duplication in this test script, which we can avoid
# by extracting the mutation analysis workflow into a parameterized function. 

HERE=$(cd `dirname $0` && pwd)

# Import helper subroutines and variables, and init Defects4J
source "$HERE/test.include" || exit 1
init

_test_exclude_mutants_option() {

  local pid="Lang" # any pid-bid should work
  local bid="1f"
  local pid_bid_dir="$TMP_DIR/$pid-$bid"
  rm -rf "$pid_bid_dir"

  # Checkout project-version
  defects4j checkout -p "$pid" -v "$bid" -w "$pid_bid_dir" || die "It was not possible to checkout $pid-$bid to '$pid_bid_dir'!"

  ######################################################
  # Test mutation analysis without excluding any mutants
  defects4j mutation -w "$pid_bid_dir" -r || die "Mutation analysis (including all mutants) failed!"

  # MutantsGenerated,MutantsCovered,MutantsKilled,MutantsLive,RuntimePreprocSeconds,RuntimeAnalysisSeconds
  local summary_file="$pid_bid_dir/summary.csv"
  [ -s "$summary_file" ] || die "'$summary_file' doesn't exist or is empty!"

  # The last row of 'summary.csv' does not have an end of line character.
  # Otherwise, using wc would be more intuitive.
  local num_rows=$(grep -c "^" "$summary_file")
  [ "$num_rows" -eq "2" ] || die "Unexpected number of lines in '$summary_file'!"

  local summary_data=$(awk '1' "$summary_file" | tail -n1)
  local num_mutants_covered=$(echo "$summary_data" | cut -f2 -d',')
  local num_mutants_killed=$(echo "$summary_data" | cut -f3 -d',')

  [ "$num_mutants_covered" -gt 0 ] || die "0 mutants covered!"
  [ "$num_mutants_killed" -gt 0 ] || die "0 mutants killed!"

  # TODO Would be nice to test the number of excluded mutants. In order to do it
  # Major has to write that number to the '$pid_bid_dir/summary.csv' file.

  >"$summary_file" # reset it, just in case

  ###################################################
  # Test mutation analysis when excluding all mutants

  local mutants_file="$pid_bid_dir/mutants.log"
  [ -s "$summary_file" ] || die "'$summary_file' doesn't exist or is empty!"

  local exclude_file="$pid_bid_dir/exclude_all_mutants.txt"
  cut -f1 -d':' "$mutants_file" > "$exclude_file"

  defects4j mutation -w "$pid_bid_dir" -r -e "$exclude_file" || die "Mutation analysis (excluding all mutants) failed!"

  # The last row of 'summary.csv' does not have an end of line character.
  # Otherwise, using wc would be more intuitive.
  num_rows=$(grep -c "^" "$summary_file")
  [ "$num_rows" -eq "2" ] || die "Unexpected number of lines in '$summary_file'!"

  summary_data=$(awk '1' "$summary_file" | tail -n1)
  num_mutants_covered=$(echo "$summary_data" | cut -f2 -d',')
  num_mutants_killed=$(echo "$summary_data" | cut -f3 -d',')

  [ "$num_mutants_covered" -eq 0 ] || die "$num_mutants_covered mutants have been covered!"
  [ "$num_mutants_killed" -eq 0 ] || die "$num_mutants_killed mutants have been killed!"

  # TODO Would be nice to test the number of excluded mutants. In order to do it
  # Major has to write that number to the '$pid_bid_dir/summary.csv' file.

  # Clean up
  rm -rf "$pid_bid_dir"
}

_test_exclude_mutants_option || die "Test 'test_exclude_mutants_option' has failed!"

# EOF

<commit_msg>Simplified a test script.<commit_after>#!/usr/bin/env bash
################################################################################
#
# This script tests the D4J's mutation analysis script.
#
################################################################################
# TODO: There is some code duplication in this test script, which we can avoid
# by extracting the mutation analysis workflow into a parameterized function. 

HERE=$(cd `dirname $0` && pwd)

# Import helper subroutines and variables, and init Defects4J
source "$HERE/test.include" || exit 1
init

_test_exclude_mutants_option() {

  local pid="Lang" # any pid-bid should work
  local bid="1f"
  local pid_bid_dir="$TMP_DIR/$pid-$bid"
  rm -rf "$pid_bid_dir"

  # Files generated by Major
  local summary_file="$pid_bid_dir/summary.csv"
  local mutants_file="$pid_bid_dir/mutants.log"

  # Checkout project-version
  defects4j checkout -p "$pid" -v "$bid" -w "$pid_bid_dir" || die "It was not possible to checkout $pid-$bid to '$pid_bid_dir'!"

  ######################################################
  # Test mutation analysis without excluding any mutants

  defects4j mutation -w "$pid_bid_dir" -r || die "Mutation analysis (including all mutants) failed!"

  # Make sure Major generated the expected data files
  [ -s "$mutants_file" ] || die "'$mutants_file' doesn't exist or is empty!"
  [ -s "$summary_file" ] || die "'$summary_file' doesn't exist or is empty!"

  # The last row of 'summary.csv' does not have an end of line character.
  # Otherwise, using wc would be more intuitive.
  local num_rows=$(grep -c "^" "$summary_file")
  [ "$num_rows" -eq "2" ] || die "Unexpected number of lines in '$summary_file'!"

  # Columns of summary (csv) file:
  # MutantsGenerated,MutantsCovered,MutantsKilled,MutantsLive,RuntimePreprocSeconds,RuntimeAnalysisSeconds
  local num_mutants_covered=$(tail -n1 "$summary_file" | cut -f2 -d',')
  local num_mutants_killed=$(tail -n1 "$summary_file" | cut -f3 -d',')

  [ "$num_mutants_covered" -gt 0 ] || die "0 mutants covered!"
  [ "$num_mutants_killed" -gt 0 ] || die "0 mutants killed!"

  # TODO Would be nice to test the number of excluded mutants. In order to do it
  # Major has to write that number to the '$pid_bid_dir/summary.csv' file.

  # Remove the summary file to ensure it is regenerated later
  rm "$summary_file"

  ###################################################
  # Test mutation analysis when excluding all mutants

  # Exclude all generated mutants
  local exclude_file="$pid_bid_dir/exclude_all_mutants.txt"
  cut -f1 -d':' "$mutants_file" > "$exclude_file"

  defects4j mutation -w "$pid_bid_dir" -r -e "$exclude_file" || die "Mutation analysis (excluding all mutants) failed!"

  # The last row of 'summary.csv' does not have an end of line character.
  # Otherwise, using wc would be more intuitive.
  num_rows=$(grep -c "^" "$summary_file")
  [ "$num_rows" -eq "2" ] || die "Unexpected number of lines in '$summary_file'!"

  # Columns of summary (csv) file:
  # MutantsGenerated,MutantsCovered,MutantsKilled,MutantsLive,RuntimePreprocSeconds,RuntimeAnalysisSeconds
  num_mutants_covered=$(tail -n1 "$summary_file" | cut -f2 -d',')
  num_mutants_killed=$(tail -n1 "$summary_file" | cut -f3 -d',')

  [ "$num_mutants_covered" -eq 0 ] || die "$num_mutants_covered mutants have been covered!"
  [ "$num_mutants_killed" -eq 0 ] || die "$num_mutants_killed mutants have been killed!"

  # TODO Would be nice to test the number of excluded mutants. In order to do it
  # Major has to write that number to the '$pid_bid_dir/summary.csv' file.

  # Clean up
  rm -rf "$pid_bid_dir"
}

_test_exclude_mutants_option || die "Test 'test_exclude_mutants_option' has failed!"

# EOF

{'fraction_non_alphanumeric': 0.18664074434106373, 'fraction_numerical': 0.006943480072212193, 'mean_word_length': 4.766212970376301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4139405', 'n_tokens_mistral': 2340, 'n_tokens_neox': 2199, 'n_words': 743}