#!/bin/sh
# ---------------------------------------------------------------------------
# TEST-REM
#
# This file runs an acceptance test for Remind.  To use it, type:
#      sh test-rem  OR make test
# in the build directory.
#
# This file is part of REMIND.
# Copyright (C) 1992-2026 Dianne Skoll
# SPDX-License-Identifier: GPL-2.0-only
# ---------------------------------------------------------------------------

DIR=`dirname $0`
cd $DIR
if test $? != 0 ; then
    echo ""
    echo "Unable to cd $DIR" >&2
    echo ""
    exit 1
fi

if test `id -u` = 0 ; then
    echo ""
    echo "*** Please do not run the test suite as root; it will fail."
    echo ""
    exit 1
fi

REMIND_CMD=${REMIND_CMD:-../src/remind}
REM2PS=${REM2PS:-../src/rem2ps}
REMIND="$REMIND_CMD --flush -q"
OUT="../tests/test.out"
CMP="../tests/test.cmp"
# Set a known timezone so moon phases show up in predictable places
TZ=UTC
export TZ

# No localization, but we want a UTF-8 locale.
LANG=C.UTF-8
export LANG
LC_ALL=C.UTF-8
export LC_ALL

unset LC_PAPER

# Check if "grep" accepts "-a" flag
echo TEST | grep -a TEST > /dev/null 2>&1
if test $? = 0 ; then
    GREP_A="-a"
else
    GREP_A=""
fi

# Colorize output iff stdout is a tty
stty <&1 > /dev/null 2>&1
if test $? = 0; then
    RED="[31m"
    GRN="[32m"
    NRM="[0m"
else
    RED=""
    GRN=""
    NRM=""
fi

# See if our version of sleep supports fractional sleeps
sleep 0.2 > /dev/null 2>&1
if test $? = 0 ; then
    DELAY=0.2
else
    DELAY=1
fi

chmod 000 include_dir/04cantread.rem
TEST_GETENV="foo bar baz" ; export TEST_GETENV
echo "Test 1" > $OUT
echo "" >> $OUT
echo "Running main tests"
$REMIND -e -dxte ../tests/test.rem 16 feb 1991 12:13 2>&1 | grep -v $GREP_A 'TimetIs64bit' >> $OUT 2>&1
echo "" >> $OUT
echo "Test 2" >> $OUT
echo "" >> $OUT
$REMIND -p -l ../tests/test2.rem 1 aug 2007 >> $OUT 2>&1
echo "" >> $OUT
echo "Test 3" >> $OUT
echo "" >> $OUT
$REMIND -s ../tests/test2.rem 1 aug 2007 >> $OUT 2>&1
echo "" >> $OUT
echo "Test 4" >> $OUT
echo "" >> $OUT
$REMIND -sa ../tests/test2.rem 1 aug 2007 >> $OUT 2>&1
echo "Test 5" >> $OUT
echo "" >> $OUT
$REMIND -p -l -b0 ../tests/test3.rem 1 aug 2007 >> $OUT 2>&1
echo "Test 6" >> $OUT
echo "" >> $OUT
$REMIND -p -l -b1 ../tests/test3.rem 1 aug 2007 >> $OUT 2>&1
echo "Test 7" >> $OUT
echo "" >> $OUT
$REMIND -p -l -b2 ../tests/test3.rem 1 aug 2007 >> $OUT 2>&1

echo "Test 8" >> $OUT
echo "" >> $OUT
$REMIND -df -p -l -b2 ../tests/include_dir 1 aug 2007 >> $OUT 2>&1

echo "Test 9" >> $OUT
echo "" >> $OUT
$REMIND -df -p -l -b2 ../tests/nonexistent_include_dir 1 aug 2007 >> $OUT 2>&1
$REMIND -df -p -l -b2 ../tests/include_dir_no_rems 1 aug 2007 >> $OUT 2>&1
$REMIND -df -p -l -b2 ../tests/include_test.rem 1 aug 2007 >> $OUT 2>&1

chmod 644 include_dir/04cantread.rem

# Feb 29 bug
echo "Feb 29 Bug Test" >> $OUT
echo 'REM Sun 29 Feb MSG [$T]' | $REMIND -dt - 1 feb 2021 >> $OUT 2>&1

# Day Weekday Year out-of-year bug
echo "Mon 31 Dec Bug Test" >> $OUT
echo 'REM Mon 31 2021 MSG [$T]' | $REMIND -dt - 31 dec 2021 >> $OUT 2>&1

echo "Color Test" >> $OUT
$REMIND -ccl ../tests/colors.rem 1 aug 2007 >> $OUT 2>&1

echo "ANSI Color Test" >> $OUT
$REMIND ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@0 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@2 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@0,0 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@1,0 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@2,0 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@0,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@1,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@2,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@0,,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@1,,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@2,,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@0,0,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@1,0,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@2,0,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@0,1,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@1,1,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND -@2,1,1 ../tests/ansicolors.rem 1 Jan 2022 >> $OUT 2>&1

echo '$AddBlankLines test' >> $OUT
$REMIND ../tests/blanks.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND '-i$AddBlankLines=1' ../tests/blanks.rem 1 Jan 2022 >> $OUT 2>&1
$REMIND '-i$AddBlankLines=0' ../tests/blanks.rem 1 Jan 2022 >> $OUT 2>&1

echo "MON WKDAY DAY across year test" >> $OUT
echo 'REM Mon 29 Dec MSG x' | $REMIND -dt - 1 Jan 2000 >> $OUT 2>&1

echo "Sort Test" >> $OUT
(echo "REM AT 12:00 MSG Untimed"; echo "REM MSG Timed") | $REMIND -q -gaaa - 1 Jan 2000 >> $OUT 2>&1
(echo "REM AT 12:00 MSG Untimed"; echo "REM MSG Timed") | $REMIND -q -gaaad - 1 Jan 2000 >> $OUT 2>&1

echo "Purge Test" >> $OUT
$REMIND -j999 ../tests/purge_dir/f1.rem 3 Feb 2012 >> $OUT 2>&1
echo "F1" >> $OUT
cat ../tests/purge_dir/f1.rem.purged >> $OUT
echo "F2" >> $OUT
cat ../tests/purge_dir/f2.rem.purged >> $OUT
echo "F3" >> $OUT
cat ../tests/purge_dir/f3.rem.purged >> $OUT

rm -f ../tests/purge_dir/*.rem.purged >> $OUT 2>&1

echo "Hush Purge Test" >> $OUT
$REMIND -h -j999 ../tests/purge_dir/f1.rem 3 Feb 2012 >> $OUT 2>&1
echo "F1" >> $OUT
cat ../tests/purge_dir/f1.rem.purged >> $OUT
echo "F2" >> $OUT
cat ../tests/purge_dir/f2.rem.purged >> $OUT
echo "F3" >> $OUT
cat ../tests/purge_dir/f3.rem.purged >> $OUT

rm -f ../tests/purge_dir/*.rem.purged >> $OUT 2>&1

$REMIND ../tests/runtest.rem >> $OUT 2>&1

$REMIND -p ../tests/shade.rem 1 August 2009 | "$REM2PS" -e -l -c3 >> $OUT 2>&1
$REMIND -pp ../tests/shade.rem 1 August 2009 | "$REM2PS" -e -l -c3 >> $OUT 2>&1

TZ=America/Toronto $REMIND ../tests/sunmoon.rem 1 Jan 2011 >> $OUT 2>&1

# Test -a vs -aa
$REMIND -q -a - 1 Jan 2012 9:00 <<'EOF' >> $OUT 2>&1
REM 1 Jan 2012 AT 8:00 MSG 8am: Should not show up
REM 1 Jan 2012 AT 9:00 MSG 9am: Should not show up
REM 1 Jan 2012 AT 10:00 MSG 10am: Should not show up
MSG [$DontTrigAts]
EOF

$REMIND -q -a -a - 1 Jan 2012 9:00 <<'EOF' >> $OUT 2>&1
REM 1 Jan 2012 AT 8:00 MSG 8am: Should not show up
REM 1 Jan 2012 AT 9:00 MSG 9am: Should show up
REM 1 Jan 2012 AT 10:00 MSG 10am: Should show up
MSG [$DontTrigAts]
EOF

# OMITFUNC should indicate nonconst_expr
$REMIND -pp - 1 jan 2012 9:00 <<'EOF' >> $OUT 2>&1
REM Mon OMITFUNC foo MSG bar
EOF

# Test default color
$REMIND -pppq - 1 Jan 2012 9:00 <<'EOF' >> $OUT 2>&1
REM 2 MSG Normal
SET $DefaultColor "255 0 0"
REM 3 \
    MSG %"Red%" on the calendar!
SET $DefaultColor "-1 -1 -1"
REM 4 MSG Normal
# Should give an error - split on two lines to test line number reporting
SET $DefaultColor \
    "256 0 0"
EOF

# Test default color with weekly calendar
$REMIND -pq+ - 1 Jan 2012 9:00 <<'EOF' >> $OUT 2>&1
REM 2 MSG Normal
SET $DefaultColor "255 0 0"
REM 3 MSG %"Red%" on the calendar!
SET $DefaultColor "-1 -1 -1"
REM 4 MSG Normal
# Should give an error
SET $DefaultColor "256 0 0"
EOF

# Test stdout
$REMIND - 1 jan 2012 <<'EOF' >> $OUT 2>&1
BANNER %
MSG STDOUT is a: [stdout()]%
EOF

$REMIND - 1 jan 2012 <<'EOF' 2>&1 | cat >> $OUT
BANNER %
MSG STDOUT is a: [stdout()]%
EOF

# Test -@ option
$REMIND -w,0,0 -@0,,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@0
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF
$REMIND -w,0,0 -@0,0,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@0,0
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF
$REMIND -w,0,0 -@0,1,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@0,1
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF
$REMIND -w,0,0 -@1,,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@1
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF
$REMIND -w,0,0 -@1,0,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@1,0
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF
$REMIND -w,0,0 -@1,1,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@1,1
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF
$REMIND -w,0,0 -@2,,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@2
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF
$REMIND -w,0,0 -@2,0,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@2,0
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF
$REMIND -w,0,0 -@2,1,1 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $SuppressLRM 1
rem 1 SPECIAL COLOR 0   0   0 BLACK
rem 2 SPECIAL COLOR 0   0  65 BLUE
rem 3 SPECIAL COLOR 0  65   0 GREEN
rem 4 SPECIAL COLOR 0  65  65 CYAN
rem 5 msg -@2,1
rem 6 SPECIAL SHADE 255 255 0
rem 7 SPECIAL SHADE 255 0 255
rem 8 SPECIAL SHADE 0 255 255
rem 15 SPECIAL COLOR 65  0   0 RED
rem 16 SPECIAL COLOR 65  0  65 MAGENTA
rem 17 SPECIAL COLOR 65 65   0 YELLOW
rem 18 SPECIAL COLOR 65 65  65 WHITE
rem 8 SPECIAL COLOR 0   0   0 BLACK
rem 9 SPECIAL COLOR 0   0  200 BRIGHT BLUE
rem 10 SPECIAL COLOR 0  200   0 BRIGHT GREEN
rem 11 SPECIAL COLOR 0  200  200 BRIGHT CYAN
rem 22 SPECIAL COLOR 200  0   0 BRIGHT RED
rem 23 SPECIAL COLOR 200  0  200 BRIGHT MAGENTA
rem 24 SPECIAL COLOR 200 200   0 BRIGHT YELLOW
rem 25 SPECIAL COLOR 200 200  200 BRIGHT WHITE
EOF

$REMIND -w128 -c ../tests/utf-8.rem 1 Nov 2019 >> $OUT
$REMIND -c ../tests/test-addomit.rem 1 Sep 2021 >> $OUT

$REMIND -cu ../tests/utf-8.rem 1 Nov 2019 >> $OUT
$REMIND -cu '-i$SuppressLRM=1' ../tests/utf-8.rem 1 Nov 2019 >> $OUT

TZ=America/Toronto $REMIND -dxe ../tests/tz.rem 2026-02-01 >> $OUT 2>&1
TZ=Europe/Berlin $REMIND -dxe ../tests/tz.rem 2026-02-01 >> $OUT 2>&1

$REMIND ../tests/soleq.rem 1 April 2044 >> $OUT 2>&1

# Test that banner is printed on every iteration
echo "MSG Should be three banners." | $REMIND - 2022-10-20 '*3' >> $OUT 2>&1

# Test the -tn option
echo "REM May 23 +10 MSG Orange %b" | $REMIND - 2023-05-21 >> $OUT 2>&1
echo "REM May 23 +10 MSG Quux %b" | $REMIND -t1 - 2023-05-21 >> $OUT 2>&1
echo "REM May 23 +10 MSG Cabbage %b" | $REMIND -t2 - 2023-05-21 >> $OUT 2>&1
echo "REM May 23 MSG Banana %b" | $REMIND - 2023-05-21 >> $OUT 2>&1
echo "REM May 23 MSG Carrot %b" | $REMIND -t1 - 2023-05-21 >> $OUT 2>&1
echo "REM May 23 MSG Apple %b" | $REMIND -t2 - 2023-05-21 >> $OUT 2>&1

# Test the -tz option
echo "REM May 22 +10 MSG Foo %b" | $REMIND - 2023-05-21 >> $OUT 2>&1
echo "REM May 22 +10 MSG Bar %b" | $REMIND -tz - 2023-05-21 >> $OUT 2>&1

# World-writable file
rm -rf include_dir/ww
touch include_dir/ww
chmod 0666 include_dir/ww
$REMIND include_dir/ww 2026-02-01 >> $OUT 2>&1
rm -rf include_dir/ww

# World-writable directory
mkdir -p include_dir/ww
touch include_dir/ww/0.rem
chmod 0777 include_dir/ww
$REMIND include_dir/ww 2026-02-01 >> $OUT 2>&1
rm -rf include_dir/ww

# This segfaulted in 04.02.03
$REMIND -h '-imsgprefix(x)="foo"' /dev/null 2026-02-01 >> $OUT 2>&1

# Test --version long option
$REMIND --version >> $OUT 2>&1

# Test queueing.  Because eventstart depends on the actual system
# date, we use the --test flag to fake the date and time.
# We can't use $REMIND here because it includes the -q flag.
echo JSONQUEUE | "$REMIND_CMD" --flush --test -z0 ../tests/queue1.rem >> $OUT 2>&1
echo QUEUE     | "$REMIND_CMD" --flush --test -zj ../tests/queue1.rem >> $OUT 2>&1

# Test for leap year bug that was fixed
$REMIND -dte - 28 Feb 2024 <<'EOF' >> $OUT 2>&1
BANNER %
REM 29 MSG One
REM 29 Feb MSG two
REM 29 2024 MSG three
REM 29 Feb 2024 MSG four
REM Thursday 29 MSG One
REM Thursday 29 Feb MSG two
REM Thursday 29 2024 MSG three
REM Thursday 29 Feb 2024 MSG four
REM Wednesday 29 MSG One
REM Wednesday 29 Feb MSG two
REM Wednesday 29 2024 MSG three
REM Wednesday 29 Feb 2024 MSG four
REM Friday 29 MSG One
REM Friday 29 Feb MSG two
REM Friday 29 2024 MSG three
REM Friday 29 Feb 2024 MSG four
EOF

$REMIND -dte - 1 Mar 2024 <<'EOF' >> $OUT 2>&1
BANNER %
REM 29 MSG One
REM 29 Feb MSG two
REM 29 2024 MSG three
REM 29 Feb 2024 MSG four
REM Thursday 29 MSG One
REM Thursday 29 Feb MSG two
REM Thursday 29 2024 MSG three
REM Thursday 29 Feb 2024 MSG four
REM Wednesday 29 MSG One
REM Wednesday 29 Feb MSG two
REM Wednesday 29 2024 MSG three
REM Wednesday 29 Feb 2024 MSG four
REM Friday 29 MSG One
REM Friday 29 Feb MSG two
REM Friday 29 2024 MSG three
REM Friday 29 Feb 2024 MSG four
EOF

$REMIND -dte - 28 Feb 2025 <<'EOF' >> $OUT 2>&1
BANNER %
REM 29 MSG One
REM 29 Feb MSG two
REM 29 2025 MSG three
REM 29 Feb 2025 MSG four
REM Thursday 29 MSG One
REM Thursday 29 Feb MSG two
REM Thursday 29 2025 MSG three
REM Thursday 29 Feb 2025 MSG four
REM Wednesday 29 MSG One
REM Wednesday 29 Feb MSG two
REM Wednesday 29 2025 MSG three
REM Wednesday 29 Feb 2025 MSG four
REM Friday 29 MSG One
REM Friday 29 Feb MSG two
REM Friday 29 2025 MSG three
REM Friday 29 Feb 2025 MSG four
EOF

$REMIND -dte - 1 Mar 2025 <<'EOF' >> $OUT 2>&1
BANNER %
REM 29 MSG One
REM 29 Feb MSG two
REM 29 2025 MSG three
REM 29 Feb 2025 MSG four
REM Thursday 29 MSG One
REM Thursday 29 Feb MSG two
REM Thursday 29 2025 MSG three
REM Thursday 29 Feb 2025 MSG four
REM Wednesday 29 MSG One
REM Wednesday 29 Feb MSG two
REM Wednesday 29 2025 MSG three
REM Wednesday 29 Feb 2025 MSG four
REM Friday 29 MSG One
REM Friday 29 Feb MSG two
REM Friday 29 2025 MSG three
REM Friday 29 Feb 2025 MSG four
EOF


(echo 'BANNER %'; echo 'REM 29 MSG No bug') | $REMIND -dt - 29 Feb 2024 >> $OUT 2>&1

$REMIND -ifoo - 2026-02-01 <<'EOF' >> $OUT 2>&1
BANNER %
DUMP
EOF

$REMIND '-i$AddBlankLines' - 2026-02-01 <<'EOF' >> $OUT 2>&1
BANNER %
DUMP $AddBlankLines
EOF

$REMIND ../tests/expr.rem 2026-02-01 >> $OUT 2>&1

$REMIND - 2026-02-01 <<'EOF' >> $OUT 2>&1
PUSH
POP
PUSH
PUSH
POP
POP
PUSH
PUSH
POP
PUSH
POP
PUSH
POP
EOF

$REMIND ../tests/if1.rem 2020-03-03 >> $OUT 2>&1

# Test ONCE with a timestamp file
rm -f ../tests/once.timestamp
$REMIND ../tests/test-once.rem >> $OUT 2>&1
$REMIND ../tests/test-once.rem >> $OUT 2>&1
$REMIND ../tests/test-once.rem >> $OUT 2>&1
tail -n+2 ../tests/once.timestamp >> $OUT 2>&1
rm -f ../tests/once.timestamp

$REMIND - < ../tests/test-once.rem >> $OUT 2>&1
$REMIND - < ../tests/test-once.rem >> $OUT 2>&1
$REMIND - < ../tests/test-once.rem >> $OUT 2>&1
tail -n+2 ../tests/once.timestamp >> $OUT 2>&1
rm -f ../tests/once.timestamp

# Newlines in calendar output
(echo 'SET $SuppressLRM 1'; echo 'REM 16 MSG foo%_bar%_baz wookie quux apple   %_    %_    %_  blech'; echo "REM 16 MSG ANOTHER") | $REMIND -c -w80 - 1 sep 1990 >> $OUT 2>&1

# Dedupe feature
$REMIND -c ../tests/dedupe.rem 1 November 2023 >> $OUT 2>&1
$REMIND -q ../tests/dedupe.rem 8 November 2023 >> $OUT 2>&1

# Remove references to SysInclude, which is build-specific
grep -F -v $GREP_A '$SysInclude' < $OUT > $OUT.1 && mv -f $OUT.1 $OUT

# If "man" accepts the --warnings flag, test all the man pages.
RUNMAN=0
man man 2>&1 | grep -e --warnings > /dev/null 2>&1
if test "$?" = 0 ; then
    echo "Checking syntax of man pages"
    RUNMAN=1
fi
for i in ../man/*.1 ; do
    echo "Checking $i..." >> $OUT
    if test "$RUNMAN" = 1 ; then
        man --warnings=w $i 2>>$OUT 1>/dev/null
    fi
done

if test -d ../rem2pdf/blib ; then
    PERLMANS=`find ../rem2pdf/blib -name '*.1p' -o -name '*.3pm'`
else
    PERLMANS=""
fi

# If we have "spellintian", run it against man pages
cat <<'EOF' >> $OUT

If spellintian is installed, its output (if any) follows...

EOF

spellintian /dev/null < /dev/null > /dev/null 2>&1
if test $? = 0 ; then
    echo "Linting man pages"
    # we grep out some false-positives from rem2ps
    spellintian --picky $PERLMANS ../man/*.1 2>&1 | grep -v -F 'MinX MinX (duplicate word)' | grep -v -F 'MinY MinY (duplicate word)' | grep -v -F 'show show (duplicate word)' | grep -v -F 'TK -> Tk' >> $OUT 2>&1
fi

# If we have "hunspell", run it against man pages
cat <<'EOF' >> $OUT

If hunspell is installed, its output (if any) follows...

EOF

HUNSPELL="hunspell -d en_US -l -p manpage-personal-dict"
GOT_HUNSPELL=0
$HUNSPELL /dev/null < /dev/null > /dev/null 2>&1

# Hunspell runs.  Do we have the en_US dictionary?
if test $? = 0 ; then
    X=`(echo color; echo colour; echo returm)  | hunspell -d en_US -l 2>/dev/null`
    X=`echo $X | sed -e 's/\n/ /g'`
    if test "$X" = "colour returm" ; then
        GOT_HUNSPELL=1
    fi
fi
if test "$GOT_HUNSPELL" = "1"; then
    echo "Spell-checking man pages, WHATSNEW and README.md"
    cat ../man/*.1 $PERLMANS | $HUNSPELL -n >> $OUT 2>&1
    cat ../docs/WHATSNEW | $HUNSPELL >> $OUT 2>&1
    cat ../README.md | $HUNSPELL >> $OUT 2>&1
    # If we have pod2man, check rem2pdf and rem2html man pages too
    pod2man < ../rem2html/rem2html.in > /dev/null 2>&1
    if test $? = 0 ; then
        pod2man < ../rem2html/rem2html.in | $HUNSPELL -n >> $OUT 2>&1
    fi
fi

echo "" >> $OUT
# Test --print-tokens long option
$REMIND --print-tokens < /dev/null >> $OUT 2>&1

# Torture test #2
$REMIND ../tests/torture2.rem 2026-02-01 >> $OUT 2>&1

# Expression error-reporting
$REMIND -de - 1 Feb 2024 <<'EOF' >> $OUT 2>&1
set a 8 * "]]]" & 6
msg [8 * "]]]" & 6] is weird
set a 9 *
set a 9 * ]
EOF

# Translation template generateion
$REMIND -h - 1 Feb 2024 <<'EOF' >> $OUT 2>&1
TRANSLATE GENERATE
EOF

# Make sure stupidly-long translations of "am" and "pm" can't cause a
# segmentation fault
$REMIND -c - 1 Feb 2024 <<'EOF' >> $OUT 2>&1
TRANS "am" "alsdkjalksdj alksjd alksdj alksjd laksjd laksjd laksjd laksjd laksjd laksjd laksjd laksjd lkasjd laksjd laksjd lkajs dlkajs dlkasj dlkasjd lkajsd lkajs dlkasjd lkasj dlkajsd lkasjd lkasjd laksjd laksjd laksjd alskdj alskdj alksdj alksdj alskdj alksdj aslkdj"
TRANS "pm" "oiwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwjwwwwwwwwwwwwwwwjwpqoejkpqwojepqowjepqojwepqowjepqowjepqowjepqowjepqowjepqowjepqojwepqowjepqowjepqowjepqowjepqowjeqpweoj"

REM WED AT 11:00 MSG wookie
REM WED AT 13:00 MSG blah
EOF

# The INFO keyword
$REMIND -pp - 1 Feb 2024 <<'EOF' >> $OUT 2>&1
REM Wed INFO "Location: here" INFO "Summary: Nope" MSG Meeting [triginfo("location")] %<summary> %<nonexist> [triginfo("cabbage")]
EOF

# Invalid info strings
$REMIND - 1 Feb 2024 <<'EOF' >> $OUT 2>&1
REM Thu INFO "Invalid" MSG wookie
REM Fri INFO ": foo" MSG blat
REM Sun INFO "foo bar baz : blork" MSG uua

# Duplicate info string
REM Sat INFO "Location: here" INFO "location: there" MSG blort
EOF

# Test parsing of quoted strings and the "escape" function
$REMIND - 1 Feb 2024 <<'EOF' >> $OUT 2>&1
BANNER %
SET $AddBlankLines 0
TRANSLATE "foo" "test: \\\" \a\b\f\\n\r\t\v\x3\x1b haha"
REM msg foo translation = %(foo)
FLUSH
set a "vartest: \\\" \a\b\f\\n\r\t\v\x3\x1b haha"
REM msg a = [a]
FLUSH
dump a
set b escape(a)
REM msg b = [b]
set b escape(a,1)
REM msg b = [b]
FLUSH
dump b
FLUSH
set a "\x"
dump a
FLUSH
set a "\xPOO"
dump a
FLUSH
set a "\x0"
set a "\x00"
set a "\x0P"
set a "\x00P"
EOF

# Test diagnostics when using a timed substitution without an AT clause
$REMIND - 1 Feb 2024 1:00 <<EOF >> $OUT 2>&1
REM MSG %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 hahaha
EOF

# Test translate table dumping
$REMIND - 1 Feb 2024 <<EOF >> $OUT 2>&1
TRANSLATE "\x03" "BREAK"
TRANSLATE DUMP
EOF

$REMIND -ppp - 1 Feb 2024 <<EOF >> $OUT 2>&1
TRANSLATE "\x03" "BREAK"
EOF

# SCANFROM should be preserved even if it is today
$REMIND -ppp - 1 Feb 2024 <<EOF >> $OUT 2>&1
REM SCANFROM 2024-02-01 MSG Preserve SCANFROM
EOF
# Languages
for i in ../include/lang/??.rem ; do
    $REMIND -r -q "-ii=\"$i\"" ../tests/tstlang.rem 1 Feb 2024 13:34 >> $OUT 2>&1
done

# Fix for $DefaultColor bug with remind -s
$REMIND -s - 1 Feb 2024 >> $OUT 2>&1 <<'EOF'
SET $DefaultColor "255 0 0"
REM Wed MSG Wookie
EOF

# Test year-folding
TZ=America/Toronto $REMIND -dx ../tests/yearfold.rem 2026-02-01 >> $OUT 2>&1

# Test unused-variable debugging
$REMIND -du - 2026-02-01 <<'EOF' >> $OUT 2>&1
set a 1
set b a*2
set c "What"
if c
   set d "Told ya!"
endif

set x 44
set x 45
set y 1000
unset y
EOF

# Test RETURN statement
$REMIND ../tests/ret1.rem 4 June 2000 >> $OUT 2>&1
$REMIND ../tests/ret1.rem 5 June 2000 >> $OUT 2>&1
$REMIND ../tests/ret1.rem 7 June 2000 >> $OUT 2>&1
$REMIND -s ../tests/ret1.rem 1 June 2000 >> $OUT 2>&1

# Make sure all the include files are ok
echo "Checking syntax of *.rem files in ../include"
find ../include -type f -name '*.rem' | while read x; do $REMIND -du -n $x 21 September 2026 2>>$OUT 1>/dev/null; done

# Test todos
echo "" >> $OUT 2>&1
echo "Testing TODOS in agenda mode" >> $OUT 2>&1
$REMIND ../tests/todos.rem 2025-08-13 >> $OUT 2>&1
echo "" >> $OUT 2>&1
echo "Testing TODOS in calendar mode" >> $OUT 2>&1
$REMIND -s ../tests/todos.rem 2025-08-13 >> $OUT 2>&1
echo "" >> $OUT 2>&1
echo "Testing TODOS in calendar mode with completed todos hidden" >> $OUT 2>&1
$REMIND -s --hide-completed-todos ../tests/todos.rem 2025-08-13 >> $OUT 2>&1
echo "Testing TODOS and JSON mode" >> $OUT 2>&1
$REMIND --json ../tests/todos.rem 2025-08-13 >> $OUT 2>&1

echo "Testing proper redirection of RUN stdout in JSON mode... here's stdout" >> $OUT 2>&1
$REMIND --json ../tests/json-redirect.rem 1 Jan 2025 >> $OUT 2>/dev/null

echo "... and here is stderr" >> $OUT 2>&1
$REMIND --json ../tests/json-redirect.rem 1 Jan 2025 > /dev/null 2>> $OUT

# Test %: substitution sequence in all the languages
for i in ../include/lang/??.rem ; do
    $REMIND "-ii=\"$i\"" -p - 2025-08-13 <<'EOF' 2>&1 | grep $GREP_A 2025/ >> $OUT
DO [i]
REM TODO 2025-08-13 MSG %(LANGID) Task1%:
REM TODO 2025-08-13 COMPLETE-THROUGH 2025-08-12 MSG %(LANGID) Task2%:
REM TODO 2025-08-13 COMPLETE-THROUGH 2025-08-13 MSG %(LANGID) Task3%:
EOF
done

$REMIND -q ../tests/safety.rem 2025-08-13 >> $OUT 2>&1

# Test --max-expr-complexity
$REMIND -dh --max-expr-complexity=1000000 - 2025-01-01 <<'EOF' >> $OUT 2>&1
BANNER %
SET $AddBlankLines 0
FSET fib(n) iif(n < 3, 1, fib(n-1) + fib(n-2))

REM MSG fib(10) = [fib(10)]
REM MSG fib(15) = [fib(15)]
REM MSG fib(20) = [fib(20)]
REM MSG fib(21) = [fib(21)]
REM MSG fib(22) = [fib(22)]
REM MSG fib(23) = [fib(23)]
REM MSG fib(24) = [fib(24)]
REM MSG fib(25) = [fib(25)]
REM MSG fib(30) = [fib(30)]

EOF

# Test hex constants
$REMIND -dh - 2025-01-01 <<'EOF' >> $OUT 2>&1
BANNER %
SET $AddBlankLines 0
set a 0xfe + 0xef
rem msg a = [a]; hex(a) = [hex(a)]
rem msg hex(-1) = [hex(-1)]
set a 0x7fff
rem msg a = [a]; hex(a) = [hex(a)]
EOF

# Test proper truncation by "dumpvars"
$REMIND -h - 2025-01-01 <<'EOF' >> $OUT 2>&1
BANNER %
SET $AddBlankLines 0
set a "¢" * 41
set b "D" * 41
set c mbchar(0x1F642) * 41
DUMP
set a "¢" * 40
set b "D" * 40
set c mbchar(0x1F642) * 40
DUMP
EOF

# Test $WarningLevel
$REMIND -de -h - 2025-01-01 <<'EOF' >> $OUT 2>&1
BANNER %
SET $AddBlankLines 0
REM Monday ADDOMIT MSG woohoo!
SET $WarningLevel "06.01.02"
REM Tuesday ADDOMIT MSG Cabbage.
SET $WarningLevel "cabbage"
SET $WarningLevel today()
SET $WarningLevel "3.1.4"
EOF

# Make sure shell() and RUN redirect stdin to /dev/null
(echo 'set a shell("cat")'; sleep $DELAY; echo 'rem msg devnull test [a]') | $REMIND - 2025-10-01 >> $OUT 2>&1
(echo 'REM RUN cat'; sleep $DELAY; echo 'rem msg devnull test b') | $REMIND - 2025-10-01 >> $OUT 2>&1

# For this one, we need to force an error so we make sure the error is
# reported in -stdin- and not cat|
(echo 'INCLUDECMD cat'; sleep $DELAY; echo 'set a 1/0') | $REMIND - 2025-10-01 >> $OUT 2>&1

$REMIND --json - 2025-10-01 <<'EOF' >> $OUT 2>&1
# Nonconst-expr in trigger
set a nonconst(1)
REM 2025-10-01 MSG Nonconst NOT set [today()]
REM 2025 Oct [a] MSG Nonconst IS set [today()]
REM 2025 Oct [a] MSG Nonconst IS set
EOF

$REMIND -j - 2025-12-31 <<'EOF' >> $OUT 2>&1
# Nonconst-expr in trigger
set $ParseUntriggered 1
set a nonconst(1)
REM 2025-10-01 MSG Nonconst NOT set [today()]
REM 2025 Oct [a] MSG Nonconst IS set [today()]
REM 2025 Oct [a] MSG Nonconst IS set
REM 2025 Oct [1] MSG Expr but not nonconst [today()]
REM 2025-10-01 MSG No expr seen [1+2]
EOF

# Early exit from calendar processing
$REMIND -p - 2026-01-01 <<'EOF' >> $OUT 2>&1
REM 1 Jan 1994 MSG 1/0 = [1/0]
EOF

# No early exit from calendar processing
$REMIND -p - 2026-01-01 <<'EOF' >> $OUT 2>&1
SET $ParseUntriggered 1
REM 1 Jan 1994 MSG 1/0 = [1/0]
EOF

# Calendars with hyperlinks
$REMIND -w,0,0 -@2 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $TerminalHyperlinks 1
REM 15 INFO "Url: https://dianne.skoll.ca" MSG Hello, linky!
REM 16 INFO "Url: https://dianne.skoll.ca" MSF Hello, linky!
REM 17 INFO "Url: https://dianne.skoll.ca" CAL Hello, linky!
REM 18 INFO "Url: https://dianne.skoll.ca" SPECIAL COLOR 255 0 0 Hello, linky!
EOF

# Turn off spacing between reminders, and test the 'z' -c flag.
$REMIND -w,0,0,0 -@2 -cz - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
REM 15 INFO "Url: https://dianne.skoll.ca" MSG Hello, linky 1!
REM 15 INFO "Url: https://dianne.skoll.ca" MSF Hello, linky 2!
REM 15 INFO "Url: https://dianne.skoll.ca" CAL Hello, linky 3!
REM 15 INFO "Url: https://dianne.skoll.ca" SPECIAL COLOR 255 0 0 Hello, linky 4!
EOF

# Turn on spacing between reminders..
$REMIND -w,0,0,1 -@2 -c - 1 Jan 2020 <<'EOF' >> $OUT 2>&1
SET $TerminalHyperlinks 1
REM 15 INFO "Url: https://dianne.skoll.ca" MSG Hello, linky 1!
REM 15 INFO "Url: https://dianne.skoll.ca" MSF Hello, linky 2!
REM 15 INFO "Url: https://dianne.skoll.ca" CAL Hello, linky 3!
REM 15 INFO "Url: https://dianne.skoll.ca" SPECIAL COLOR 255 0 0 Hello, linky 4!
EOF

# Test the $Shaded system variable
$REMIND -pp ../tests/shaded.rem 2026-02-01 >> $OUT 2>&1

# Test the push/pop warnings
$REMIND ../tests/test-pushpop1.rem 2026-01-01 >> $OUT 2>&1
$REMIND -dp ../tests/test-pushpop1.rem 2026-01-01 >> $OUT 2>&1

# Test the '@trigger" command-line parameter
echo "REM MSG %y-%t-%r" | $REMIND --test - '@13 SATISFY [$Tw == 5]' >> $OUT 2>&1
echo "REM MSG %y-%t-%r" | $REMIND --test - '@January' >> $OUT 2>&1
echo "REM MSG %y-%t-%r" | $REMIND --test - '@Dec SATISFY [$Tw == 6]' >> $OUT 2>&1
echo "REM MSG %y-%t-%r" | $REMIND --test - '@Dec 1990' >> $OUT 2>&1

echo "REM MSG %y-%t-%r" | $REMIND - 2026-08-01 '@13 SATISFY [$Tw == 5]' >> $OUT 2>&1
echo "REM MSG %y-%t-%r" | $REMIND - 2026-08-01 '@January' >> $OUT 2>&1
echo "REM MSG %y-%t-%r" | $REMIND - 2026-08-01 '@Dec SATISFY [$Tw == 6]' >> $OUT 2>&1
echo "REM MSG %y-%t-%r" | $REMIND - 2026-08-01 '@Dec 1990' >> $OUT 2>&1

# Test the %1 substitution sequence for reminders days in advance
$REMIND -q - 2026-05-30@14:00 <<'EOF' >> $OUT 2>&1
SET $AddBlankLines 0
REM +100 2026-05-30@14:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@14:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@15:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@15:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@14:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@16:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@16:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?

REM +100 2026-05-31@14:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@14:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@15:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@15:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@14:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@16:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@16:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?

REM +100 2026-05-31@13:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@13:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@12:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@12:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?

REM +100 2026-06-01@14:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@14:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@15:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@15:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@14:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@16:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@16:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?

REM +100 2026-05-30@12:59 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@13:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@13:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@13:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@11:59 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@12:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@12:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-30@12:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?

REM +100 2026-05-31@12:59 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@13:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@13:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@13:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@11:59 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@12:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@12:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-05-31@12:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?

REM +100 2026-06-01@12:59 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@13:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@13:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@13:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@11:59 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@12:00 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@12:01 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?
REM +100 2026-06-01@12:02 MSG Event: (%b %2) 1=%1 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9 0=%0 !=%! ?=%?

EOF

# MaxIncludeCmdLines
$REMIND - 2026-09-09 <<'EOF' >> $OUT 2>&1
SET $MaxIncludeCmdLines 2
SET $AddBlankLines 0
BANNER %
INCLUDECMD echo REM MSG 1; echo REM MSG 2
INCLUDECMD echo REM MSG 1; echo REM MSG 2; echo REM MSG 3
EOF

# MaxLineLength
$REMIND - 2026-09-09 <<'EOF' >> $OUT 2>&1
SET $MaxLineLength 20
SET $AddBlankLines 0
BANNER %
REM MSG short
REM MSG Here is a significantly longer line.  Oh no!!
REM MSG and another short line
EOF

# FMT and test --file=xxx
echo "" >> $OUT
echo "Running remind format.rem" >> $OUT
echo "" >> $OUT
$REMIND --file=../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -@2 format.rem" >> $OUT
echo "" >> $OUT
$REMIND -@2 ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -c+1 format.rem" >> $OUT
echo "" >> $OUT
$REMIND -w80 -c+1 ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -c+1 -@2 format.rem" >> $OUT
echo "" >> $OUT
$REMIND -w80 -@2 -c+1 ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -dm format.rem" >> $OUT
echo "" >> $OUT
$REMIND --file=../tests/format.rem -dm 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -dm -@2 format.rem" >> $OUT
echo "" >> $OUT
$REMIND -dm -@2 ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1

echo "" >> $OUT
echo "Running remind --no-fmt format.rem" >> $OUT
echo "" >> $OUT
$REMIND --no-fmt ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -@2 --no-fmt format.rem" >> $OUT
echo "" >> $OUT
$REMIND -@2 --no-fmt ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -c+1 --no-fmt format.rem" >> $OUT
echo "" >> $OUT
$REMIND -w80 -c+1 --no-fmt ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -c+1 -@2 --no-fmt format.rem" >> $OUT
echo "" >> $OUT
$REMIND -w80 -@2 -c+1 --no-fmt ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -dm --no-fmt format.rem" >> $OUT
echo "" >> $OUT
$REMIND -dm --no-fmt ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -dm -@2 --no-fmt format.rem" >> $OUT
echo "" >> $OUT
$REMIND -dm -@2 --no-fmt ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1

echo "" >> $OUT
echo "Running remind --no-fmt --json format.rem" >> $OUT
echo "" >> $OUT
$REMIND --no-fmt --json ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind --json format.rem" >> $OUT
echo "" >> $OUT
$REMIND -@2 --json ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1

echo "" >> $OUT
echo "Running remind --no-fmt -pp+1 format.rem" >> $OUT
echo "" >> $OUT
$REMIND --no-fmt -pp+1 ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -pp+1 format.rem" >> $OUT
echo "" >> $OUT
$REMIND -@2 -pp+1 ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1

echo "" >> $OUT
echo "Running remind --no-fmt -pppq+1 format.rem" >> $OUT
echo "" >> $OUT
$REMIND --no-fmt -pppq+1 ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1
echo "" >> $OUT
echo "Running remind -pppq+1 format.rem" >> $OUT
echo "" >> $OUT
$REMIND -@2 -pppq+1 ../tests/format.rem 26 Aug 2024 >> $OUT 2>&1

cmp -s $OUT $CMP
if [ "$?" = "0" ]; then
   echo "remind:   Acceptance tests ${GRN}PASSED${NRM}"
   exit 0
else
   echo "remind:   Acceptance tests ${RED}FAILED${NRM}"
   echo ""
   echo "Examine the file test.out to see where it differs from the"
   echo "reference file test.cmp.  Here are the first 200 lines of"
   echo "diff -u test.out test.cmp"
   echo ""
   diff -u $OUT $CMP | head -n 200
   echo ""
   exit 1
fi

