2020-07-17 18:09:14 +01:00
|
|
|
#!/usr/bin/env python3
|
2021-04-12 12:31:43 -07:00
|
|
|
###############################################################################
|
|
|
|
|
# Top contributors (to current version):
|
2022-04-05 13:38:57 -07:00
|
|
|
# Andrew V. Jones, Mathias Preiner, Aina Niemetz
|
2021-04-12 12:31:43 -07:00
|
|
|
#
|
|
|
|
|
# This file is part of the cvc5 project.
|
|
|
|
|
#
|
2022-04-05 13:38:57 -07:00
|
|
|
# Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
|
2021-04-12 12:31:43 -07:00
|
|
|
# in the top-level source directory and their institutional affiliations.
|
|
|
|
|
# All rights reserved. See the file COPYING in the top-level source
|
|
|
|
|
# directory for licensing information.
|
|
|
|
|
# #############################################################################
|
|
|
|
|
#
|
2021-04-15 13:04:55 -07:00
|
|
|
# A simple test file to interact with cvc5 with line editing
|
2020-09-22 09:51:56 -07:00
|
|
|
##
|
2020-07-17 18:09:14 +01:00
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import pexpect
|
|
|
|
|
|
|
|
|
|
def check_iteractive_shell():
|
|
|
|
|
"""
|
2021-04-15 13:04:55 -07:00
|
|
|
Interacts with cvc5's interactive shell and checks that things such a tab
|
2020-07-17 18:09:14 +01:00
|
|
|
completion and "pressing up" works.
|
|
|
|
|
"""
|
|
|
|
|
|
2021-04-15 13:04:55 -07:00
|
|
|
# Open cvc5
|
2021-04-21 10:21:34 -07:00
|
|
|
child = pexpect.spawnu("bin/cvc5", timeout=1)
|
2020-07-17 18:09:14 +01:00
|
|
|
|
2021-04-15 13:04:55 -07:00
|
|
|
# We expect to see the cvc5 prompt
|
|
|
|
|
child.expect("cvc5>")
|
2020-07-17 18:09:14 +01:00
|
|
|
|
|
|
|
|
# If we send a line with just 'BOOLE' ...
|
2021-09-22 13:38:46 -07:00
|
|
|
child.sendline("(set-log")
|
2020-07-17 18:09:14 +01:00
|
|
|
|
|
|
|
|
# ... then we get an error
|
2021-09-22 13:38:46 -07:00
|
|
|
child.expect("Parse Error: <shell>:1.7: expected SMT-LIBv2 command, got `set-log\'")
|
2020-07-17 18:09:14 +01:00
|
|
|
|
|
|
|
|
# Start sending 'BOOL' (without an E)
|
2021-09-22 13:38:46 -07:00
|
|
|
child.send("(declare-data")
|
2020-07-17 18:09:14 +01:00
|
|
|
|
|
|
|
|
# Send tab twice
|
|
|
|
|
child.sendcontrol("i")
|
|
|
|
|
child.sendcontrol("i")
|
|
|
|
|
|
|
|
|
|
# We expect to see the completion
|
2021-09-22 13:38:46 -07:00
|
|
|
child.expect("declare-datatype.*declare-datatypes")
|
2020-07-17 18:09:14 +01:00
|
|
|
|
2021-09-22 13:38:46 -07:00
|
|
|
# NOTE: the double tab has completed our '(declare-data' to '(declare-datatype'!
|
2020-07-17 18:09:14 +01:00
|
|
|
|
2021-09-22 13:38:46 -07:00
|
|
|
# Now send enter (which submits '(declare-datatype')
|
|
|
|
|
child.send(")")
|
2020-07-17 18:09:14 +01:00
|
|
|
child.sendcontrol("m")
|
|
|
|
|
|
|
|
|
|
# So we expect to see an error for 'BOOLE'
|
2021-09-22 13:38:46 -07:00
|
|
|
child.expect("Parse Error: <shell>:1.17: Unexpected token: '\)'.")
|
2020-07-17 18:09:14 +01:00
|
|
|
|
|
|
|
|
# Send enter
|
|
|
|
|
child.sendcontrol("m")
|
|
|
|
|
|
2021-04-15 13:04:55 -07:00
|
|
|
# We expect to see the cvc5 prompt
|
|
|
|
|
child.expect("cvc5>")
|
2020-07-17 18:09:14 +01:00
|
|
|
|
|
|
|
|
# Now send an up key
|
|
|
|
|
child.send("\033[A")
|
|
|
|
|
|
|
|
|
|
# Send enter
|
|
|
|
|
child.sendcontrol("m")
|
|
|
|
|
|
2021-09-22 13:38:46 -07:00
|
|
|
# We expect to see the previous error again
|
|
|
|
|
child.expect("Parse Error: <shell>:1.17: Unexpected token: '\)'.")
|
2020-07-17 18:09:14 +01:00
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
"""
|
|
|
|
|
Runs our interactive shell test
|
|
|
|
|
|
|
|
|
|
Caveats:
|
|
|
|
|
|
|
|
|
|
* If we don't have the "pexpect" model, the test doesn't get run, but
|
|
|
|
|
passes
|
|
|
|
|
|
|
|
|
|
* We expect pexpect to raise and exit with a non-zero exit code if any
|
|
|
|
|
of the steps fail
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# If any of the "steps" fail, the pexpect will raise a Python will exit
|
|
|
|
|
# with a non-zero error code
|
|
|
|
|
sys.exit(check_iteractive_shell())
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
# EOF
|