[Lldb-commits] [PATCH] D37923: Implement interactive command interruption

Zachary Turner via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 19 10:45:21 PDT 2017


zturner added a comment.

In https://reviews.llvm.org/D37923#875322, @clayborg wrote:

> We should have a test. The test would need to use pexpect or something similar. If anyone has any pointer on how to make a test for this, please chime in. I was thinking just a pexpect based test.


This kind of thing is perfect for a unit test, but I'm not sure how easy that would be with the current design.  You'd basically do something like:

  struct MockStream {
    explicit MockStream(CommandInterpreter &Interpreter, int InterruptAfter) 
      : CommandInterpreter(Interpreter), InterruptAfter(InterruptAfter) {}
  
    CommandInterpreter &Interpreter;
    const int InterruptAfter;
    int Lines = 0;
    std::string Buffer;
  
    void Write(StringRef S) {
      ++Lines;
      if (Lines >= InterruptAfter) {
        Interpreter.Interrupt();
        return;
      }
      Buffer += S;
    }
  };
  
  TEST_F(CommandInterruption) {
    CommandInterpreter Interpreter;
    MockStream Stream(Interpreter, 3);
    Interpreter.PrintCommandOutput(Stream, "a\nb\nc\nd\ne\nf\n");
    EXPECT_EQ(Stream.Lines == 3);
    EXPECT_EQ(Stream.Buffer == "a\nb\nc\n");
  }


https://reviews.llvm.org/D37923





More information about the lldb-commits mailing list