Verified Commit 1025fec1 authored by Jakob Moser's avatar Jakob Moser
Browse files

Check all entries (not just latest) for potential solutions

Closes #56
parent 732b3552
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -283,9 +283,13 @@ class ExerciseExecutionContext {
                // Wait until the VM has processed the input and written some output to the terminal
                commandPromise.then(async () => {
                    const terminalContents = getTerminalContents()
                    const latestEntry = terminalContents[terminalContents.length - 1]

                    if (command && latestEntry.input !== command) {
                    // We start by assuming the result was a failure...
                    let result = false

                    // ... then, check every entry in the terminal (starting from the last) to see if we can be convinced otherwise
                    for(const entry of terminalContents.toReversed()) {
                        if (command && entry.input !== command) {
                            throw new Error("Could not find expected input in terminal")
                        }

@@ -297,8 +301,14 @@ class ExerciseExecutionContext {
                        }[typeof param]
    
                        // !! converts any value to a boolean (not a special operator, just two ! (boolean not) operators in series)
                    const result = !!predicate(latestEntry.output || [])
                        result = !!predicate(entry.output || [])

                        if(result) {
                            break
                        }
                    }

                    // After that is done, return the result
                    await clear()
                    verifyHandler(result)
                })