Commit 41f853db authored by Jakob Moser's avatar Jakob Moser
Browse files

Add verify() without command to API

parent 8bb9631b
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -182,9 +182,9 @@ class ExerciseExecutionContext {
    }

    /**
     * Verify the completion of the exercise by executing a command and checking
     * if the output is as expected. If yes, the exercise is treated as completed,
     * if no, the exercise is treated as failed.
     * Verify the completion of the exercise by optionally executing a command and checking
     * if the output is as expected. If yes, the exercise is treated as solved, if no,
     * the user has to try again.
     * 
     * Used like this:
     * 
@@ -192,6 +192,9 @@ class ExerciseExecutionContext {
     * this.verify("cat botschaft").hasOutput("Der Junge sieht den Mann mit dem Fernglas.")
     * ```
     * 
     * verify() can also be called without a command, in which case no command is executed – instead
     * the last command entered by the user (if any) is used.
     * 
     * When the parameter passed to `hasOutput` is a string, the verification succeeds iff
     * this string is the first and only line of output of the command.
     * When the parameter passed to `hasOutput` is a list, the verification succeeds iff
@@ -201,7 +204,9 @@ class ExerciseExecutionContext {
     * @returns An object that has the method "hasOutput"
     */
    verify(command) {
        if(command) {
            runCommand(command)
        }
        const verifyHandler = this._verifyHandler

        return {
@@ -222,7 +227,7 @@ class ExerciseExecutionContext {
                    const terminalContents = getTerminalContents()
                    const latestEntry = terminalContents[terminalContents.length - 1]

                    if (latestEntry.input !== command) {
                    if (command && latestEntry.input !== command) {
                        throw new Error("Could not find expected input in terminal")
                    }