<commit_before>#!/bin/bash

# This script executes all the tests on a specifically launched instance of
# the When scheduler. To do so, it shuts down any existing instance, saves its
# configuration, imports a specific configuration and performs some dummy
# actions using dummy conditions. The configuration is prepared for the
# environment where this command is executed, and time base conditions are
# specifically created to occur in reasonable times, however this does not
# prevent the test to need several minutes to perform despite the actual
# lightness of both tests and tasks.

export GRACE_TIME_MINUTES=1   # grace time to take cursor off VM desktop
export SLEEP_TEST_MINUTES=5   # time for unattended tests
export SLEEP_DEFER_MINUTES=2  # time for deferred tasks to take place

export BASE=`dirname $0`
export WHEN_BASE=/opt/when-command

export CONF_BASE=$HOME/.config/when-command
export WHEN="$WHEN_BASE/when-command"
export TIMESTAMP=`date +%Y%m%d-%H%M`
export BAR_LENGTH=50
export LC_NUMERIC="en_US.UTF-8"
export SESSIONLOG=$BASE/log/when-test.log

# common functions
. $BASE/preamble.sh

# functions
sleep_minutes_progress () {
  local secs=$(( $1 * 60 ))
  local tick=`echo "100.0 / $BAR_LENGTH.0" | bc -l`
  local tick_secs=`echo "$secs.0 / $BAR_LENGTH" | bc -l`
  local progress=0
  local span=0
  echo -en "\e[s"
  for x in `seq -f '%.2f' 0.0 $tick 100.0` ; do
    echo -en "\e[2K\e[u"
    printf "%6s" $x
    echo -n "% ["
    for y in `seq 0 $BAR_LENGTH` ; do
      if (( $y < $progress )) ; then
        echo -n "#"
      else
        echo -n "."
      fi
    done
    echo -n "] (" ; printf "%.2f" "${span}" ; echo -n "s)"
    sleep $tick_secs
    span=`echo "$span + $tick_secs" | bc -l`
    progress=$(( $progress + 1 ))
  done
  echo -en "\e[2K\e[u"
  printf "%6s" "100.00"
  echo -n "% ["
  for x in `seq 0 $BAR_LENGTH` ; do
    echo -n "#"
  done
  echo "]"
}

check_task_condition () {
  local task=$1
  local condition=$2
  retval=`cat $SESSIONLOG | fgrep "task:" | fgrep "$task:$condition" | wc -l`
  if [ "$retval" = "0" ]; then
    errors=$(( $errors + 1 ))
    failed="$failed $task:$condition"
  fi
}

checkfail_task_condition () {
  local task=$1
  local condition=$2
  retval=`cat $SESSIONLOG | fgrep "task:" | fgrep "$task:$condition" | wc -l`
  if [ "$retval" -gt "0" ]; then
    errors=$(( $errors + 1 ))
    failed="$failed $task:$condition"
  fi
}


# banner
echo "Welcome to the When test suite!"
echo "Please do not interact with the console or the desktop, unless this"
echo "script instructs to do so: please refer to README.md for details. If"
echo "the script is interrupted before end, you might need to restore both"
echo "configuration and exported items stored in the 'save' subdirectory."
echo

# verify that When is installed, and if not bail out
echo_prompt "Verifying When installation... "
if [ -d $CONF_BASE -a -f $CONF_BASE/when-command.conf ]; then
  echo_ok
else
  echo "not installed: please install it and run tests."<commit_msg>Add support for recurring tasks<commit_after>#!/bin/bash

# This script executes all the tests on a specifically launched instance of
# the When scheduler. To do so, it shuts down any existing instance, saves its
# configuration, imports a specific configuration and performs some dummy
# actions using dummy conditions. The configuration is prepared for the
# environment where this command is executed, and time base conditions are
# specifically created to occur in reasonable times, however this does not
# prevent the test to need several minutes to perform despite the actual
# lightness of both tests and tasks.

export GRACE_TIME_MINUTES=1   # grace time to take cursor off VM desktop
export SLEEP_TEST_MINUTES=5   # time for unattended tests
export SLEEP_DEFER_MINUTES=2  # time for deferred tasks to take place

export BASE=`dirname $0`
export WHEN_BASE=/opt/when-command

export CONF_BASE=$HOME/.config/when-command
export WHEN="$WHEN_BASE/when-command"
export TIMESTAMP=`date +%Y%m%d-%H%M`
export BAR_LENGTH=50
export LC_NUMERIC="en_US.UTF-8"
export SESSIONLOG=$BASE/log/when-test.log

# common functions
. $BASE/preamble.sh

# functions
sleep_minutes_progress () {
  local secs=$(( $1 * 60 ))
  local tick=`echo "100.0 / $BAR_LENGTH.0" | bc -l`
  local tick_secs=`echo "$secs.0 / $BAR_LENGTH" | bc -l`
  local progress=0
  local span=0
  echo -en "\e[s"
  for x in `seq -f '%.2f' 0.0 $tick 100.0` ; do
    echo -en "\e[2K\e[u"
    printf "%6s" $x
    echo -n "% ["
    for y in `seq 0 $BAR_LENGTH` ; do
      if (( $y < $progress )) ; then
        echo -n "#"
      else
        echo -n "."
      fi
    done
    echo -n "] (" ; printf "%.2f" "${span}" ; echo -n "s)"
    sleep $tick_secs
    span=`echo "$span + $tick_secs" | bc -l`
    progress=$(( $progress + 1 ))
  done
  echo -en "\e[2K\e[u"
  printf "%6s" "100.00"
  echo -n "% ["
  for x in `seq 0 $BAR_LENGTH` ; do
    echo -n "#"
  done
  echo "]"
}

check_task_condition () {
  local task=$1
  local condition=$2
  retval=`cat $SESSIONLOG | fgrep "task:" | fgrep "$task:$condition" | wc -l`
  if [ "$retval" = "0" ]; then
    errors=$(( $errors + 1 ))
    failed="$failed $task:$condition"
  fi
}

checkfail_task_condition () {
  local task=$1
  local condition=$2
  retval=`cat $SESSIONLOG | fgrep "task:" | fgrep "$task:$condition" | wc -l`
  if [ "$retval" -gt "0" ]; then
    errors=$(( $errors + 1 ))
    failed="$failed $task:$condition"
  fi
}

checkrec_task_condition () {
  local task=$1
  local condition=$2
  retval=`cat $SESSIONLOG | fgrep "task:" | fgrep "$task:$condition" | wc -l`
  if [ "$retval" -lt "2" ]; then
    errors=$(( $errors + 1 ))
    failed="$failed $task:$condition"
  fi
}


# banner
echo "Welcome to the When test suite!"
echo "Please do not interact with the console or the desktop, unless this"
echo "script instructs to do so: please refer to README.md for details. If"
echo "the script is interrupted before end, you might need to restore both"
echo "configuration and exported items stored in the 'save' subdirectory."
echo

# verify that When is installed, and if not bail out
echo_prompt "Verifying When installation... "
if [ -d $CONF_BASE -a -f $CONF_BASE/when-command.conf ]; then
  echo_ok
else
  echo "not installed: please install it and run tests."
{'fraction_non_alphanumeric': 0.12609736632083002, 'fraction_numerical': 0.015323224261771748, 'mean_word_length': 3.494978479196557, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6040151', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2055, 'n_words': 763}