-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Internal improvement: Properly time REPL inputs #5479
Conversation
config, | ||
executableCommand: "develop", | ||
displayHost: "develop" | ||
}); | ||
output = logger.contents(); | ||
}); | ||
|
||
it("Sends multiple commands to REPL", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I landed on placing a test here because it's quicker to piggyback in this scenario than breakout another file to validate our testing library. Please let me know if you think this belongs elsewhere.
// seems safe to escape parens only, as the readyprompt is constructed from | ||
// [a-zA-Z] strings and wrapping parens. | ||
const escapedPrompt = readyPrompt.replace("(", "\\(").replace(")", "\\)"); | ||
const readyPromptRex = new RegExp(`^${escapedPrompt}`, "gm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @cds-amal if it is a silly question, but what this "gm"
flag does? "g"
is for global search and "m"
is multi-line search if I am understanding correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, "g" is for global, and "m" is for multiline. It means the meta characters, ^
, and $
will match the beginning and end of each line instead of the beginning and end of the input string (which can contain multiple lines)
if (readyPromptRex.test(outputBuffer)) { | ||
// set outputBuffer to remaining segment after final match | ||
const segments = outputBuffer.split(readyPromptRex); | ||
outputBuffer = segments.pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truffle's test data won't fail on this, but as a general purpose solution this might not work. For example:
`this is a line
truffle(develop)>
this is a line
truffle(develop)>
this is a line
`
You'll skip one of the truffle(develop)>
lines, whereas I think you previous version would have properly handled it.
Currently runInREPL sends all queued commands to the child process on the first detected REPL prompt and closes the input stream on the second REPL prompt detection which terminates the child process (bad). This PR reworks the logic to send one queued command per REPL prompt.
Co-authored-by: David Murdoch <[email protected]>
1f4587c
to
2d48504
Compare
Currently,
runInREPL
sends all queued commands to the child process on the first detected REPL prompt and then closes the input stream, which terminates the child process (bad).This PR reworks the logic to send one queued command per REPL prompt.