diff options
author | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-10-24 16:37:00 +0000 |
---|---|---|
committer | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-10-24 16:37:00 +0000 |
commit | ade732181ad2eabfb3a6eef46bdc9ea42d27246e (patch) | |
tree | d487a25c2cc7bfbf610b57e9b4cd5cba2701a4c4 /src | |
parent | d8a8f335f4043a0117f2b92af3d1e94f285e4d30 (diff) |
Adding unit test for InteractiveShell
Diffstat (limited to 'src')
-rw-r--r-- | src/main/Makefile.am | 7 | ||||
-rw-r--r-- | src/main/interactive_shell.cpp | 41 |
2 files changed, 30 insertions, 18 deletions
diff --git a/src/main/Makefile.am b/src/main/Makefile.am index 05a451d52..52a659322 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am @@ -4,8 +4,9 @@ AM_CPPFLAGS = \ AM_CXXFLAGS = -Wall -Wno-unknown-pragmas bin_PROGRAMS = cvc4 +noinst_LIBRARIES = libmain.a -cvc4_SOURCES = \ +libmain_a_SOURCES = \ interactive_shell.h \ interactive_shell.cpp \ main.h \ @@ -13,10 +14,12 @@ cvc4_SOURCES = \ usage.h \ util.cpp +cvc4_SOURCES = cvc4_LDADD = \ ../parser/libcvc4parser.la \ ../libcvc4.la \ - ../lib/libreplacements.la + ../lib/libreplacements.la \ + libmain.a if STATIC_BINARY cvc4_LINK = $(CXXLINK) -all-static diff --git a/src/main/interactive_shell.cpp b/src/main/interactive_shell.cpp index 587c07495..8437d61b2 100644 --- a/src/main/interactive_shell.cpp +++ b/src/main/interactive_shell.cpp @@ -52,25 +52,15 @@ Command* InteractiveShell::readCommand() { line = sb.str(); // cout << "Input was '" << input << "'" << endl << flush; - /* If we hit EOF, we're done. */ - if( d_in.eof() ) { - input += line; - break; - } + Assert( !(d_in.fail() && !d_in.eof()) || line.empty() ); - /* Check for failure */ - if( d_in.fail() ) { + /* Check for failure. */ + if( d_in.fail() && !d_in.eof() ) { /* This should only happen if the input line was empty. */ Assert( line.empty() ); d_in.clear(); } - /* Extract the newline delimiter from the stream too */ - int c = d_in.get(); - Assert( c == '\n' ); - - // cout << "Next char is '" << (char)c << "'" << endl << flush; - /* Strip trailing whitespace. */ int n = line.length() - 1; while( !line.empty() && isspace(line[n]) ) { @@ -78,12 +68,31 @@ Command* InteractiveShell::readCommand() { n--; } + /* If we hit EOF, we're done. */ + if( d_in.eof() ) { + input += line; + + if( input.empty() ) { + /* Nothing left to parse. */ + return NULL; + } + + /* Some input left to parse, but nothing left to read. + Jump out of input loop. */ + break; + } + + /* Extract the newline delimiter from the stream too */ + int c = d_in.get(); + Assert( c == '\n' ); + + // cout << "Next char is '" << (char)c << "'" << endl << flush; + input += line; /* If the last char was a backslash, continue on the next line. */ - if( !line.empty() && line[n] == '\\' ) { - n = input.length() - 1; - Assert( input[n] == '\\' ); + n = input.length() - 1; + if( !line.empty() && input[n] == '\\' ) { input[n] = '\n'; d_out << "... > " << flush; } else { |