How to verify output from bash script controlling ghci (Haskell)

I'm attempting to create a test script for evaluation. The script needs to open Haskell GHCI and send various commands to ghci and check if the outputs are correct. It needs to continue to the end of all commands and give a final score, that is, don't just stop running if the output is incorrect. Currently, I have this.

#!/bin/env expect


spawn ghci
expect ".*> "
send ":l main.hs\n"
expect "*Main>"

send "transform [(5,1),(6,1),(8,15),(9,1)]\n"

expect "*Main>"

It opens ghci and loads the proper haskell file (main.hs). It then runs the transform function with that list parameter. How can I get this to verify the output is equal to what I want and give points accordingly. EX: Pseudo

#!/bin/env expect


spawn ghci
expect ".*> "
send ":l main.hs\n"
expect "*Main>"

send "transform [(5,1),(6,1),(8,15),(9,1)]\n"
if OUTPUT = [(5,5),(6,5),(8,5),(9,5)]
then POINTS+= 5

send "translate [(5,1),(6,1),(8,15),(9,1)]\n"
if OUTPUT = [(5,10),(6,10),(8,10),(9,10)]
then POINTS+= 5

expect "*Main>"
send ":quit"

OUTPUT SCORE

All the commands are done in Haskell, but ran from a shell script. Can anyone help?


Here's one (untested) approach:

#!/bin/env expect

spawn ghci
expect "*> "
send ":l main.hs\n"
expect "*Main>"
set POINTS 0

send "transform [(5,1),(6,1),(8,15),(9,1)]\n"
expect {
    -ex {[(5,5),(6,5),(8,5),(9,5)]} {
        incr POINTS 5
        exp_continue
    }
    *Main>
}

send "translate [(5,1),(6,1),(8,15),(9,1)]\n"
expect {
    -ex {[(5,10),(6,10),(8,10),(9,10)]} {
        incr POINTS 5
        exp_continue
    }
    *Main>
}

send ":quit"

puts $POINTS

For detailed documentation, see https://www.tcl.tk/man/expect5.31/expect.1.html and https://www.tcl-lang.org/man/tcl/TclCmd/contents.htm .