oi/test-templates/test.sh
#!/bin/bash

# Parameter 1: Current directory for test oi session
# 
# To have the test editor launched respond with "initialized|editor"
# rather than just "initialized"
#
# The following protocol goes for communicating between this test
# and the test runner when printed to std out.
#
#   - passed
#       Markes the test run as completed for this test and marks it
#       as passed.
#   - failed
#       Markes the test run as completed for this test and marks it
#       as failed. Can pass optional error description separated by |
#   - command|[OI COMMAND]
#       Runs the specified oi command in the test environment. The 
#       output and events generated by the command can be verified
#       through the commands below.
#   - hasoutput|[TEXT TO MATCH TO LINE]
#       Matches output lines generated by the test against line 
#       submitted with the command.
#   - hasevent|[TEXT TO MATCH TO LINE]
#       Matches event lines generated by the test against line
#       submitted with the command.

echo "initialized"
while IFS='|' read -ra COMMAND; do
    # The test script is told to exit
    if [ "${COMMAND[0]}" == "shutdown" ] ; then
        break
    fi

    # Write one line pr test
    if [ "${COMMAND[0]}" == "get-tests" ] ; then
        echo "This is a sample test"
    fi

    # Handling test runs
    if [ "${COMMAND[0]}" == "test" ] ; then
        case "${COMMAND[1]}" in
            "This is a sample test")
                echo "failed|This test fails"
                ;;
        esac
    fi

    echo "end-of-conversation"
done