Verified Commit 924c8ebf authored by Jakob Moser's avatar Jakob Moser
Browse files

Add function to verify raw terminal contents

parent 13ac94ee
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
/** API to create exercises */

import { getTerminalContents, runCommand, runUnexecutedCommand } from "./jslinux.api.mjs"
import { getTerminalContents, getRawTerminalContents, runCommand, runUnexecutedCommand } from "./jslinux.api.mjs"
import { arrayEquals } from "./util.mjs"
import { getHandInToken } from "./snakeoil.mjs"
import { State } from "./state.mjs"
@@ -316,6 +316,27 @@ class ExerciseExecutionContext {
                })
            },

            /**
             * Verify that the terminal contains the given line somewhere.
             * "Somewhere" might be a user input, a prompt, a line in an editor or something.
             * 
             * Normally, you'll probably want to use hasOutput(...) instead, because it ensures that the expected
             * line is found in an actual command's output. This command here is likely only useful when you
             * want to accept solutions where the line is displayed by an editor or pager, at the cost of
             * the user being able to trick you by just typing the solution as input.
             *  
             * @param {String} line A line of text that should be contained in the terminal
             */
            terminalContains(line) {
                // Wait until the VM has processed the input and written some output to the terminal
                commandPromise.then(async () => {
                    const terminalContents = getRawTerminalContents()
                    const result = terminalContents.includes(line)
                    await clear()
                    verifyHandler(result)
                })
            },

            /**
             * Verify the command matches a certain condition.
             * 
+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ export const practice = test("Linux-Übungsmodus", function() {

        await this.manualConfirmation()

        this.verify().hasOutput("Colorless green ideas sleep furiously")
        this.verify().terminalContains("Colorless green ideas sleep furiously")
    })

    this.exercise("Datei umbenennen", async function () {