def has_output(state,
               text,
               incorrect_msg="The checker expected to find {{'' if fixed else 'the pattern '}}`{{text}}` in the output of your command.",
               fixed=False,
               strip_ansi=True):
    """Check whether student output contains specific text.

    Before you use ``has_output()``, have a look at ``has_expr_output()`` or ``has_expr_error()``;
    they might be more fit for your use case.

    Args:
        state: State instance describing student and solution code. Can be omitted if used with ``Ex()``.
        text : text that student output must contain. Can be a regex pattern or a simple string.
        incorrect_msg: if specified, this overrides the automatically generated feedback message
                       in case ``text`` is not found in the student output.
        fixed: whether to match ``text`` exactly, rather than using regular expressions.
        strip_ansi: whether to remove ANSI escape codes from output

    :Example:

        Suppose the solution requires you to do: ::

            echo 'this is a printout!'

        The following SCT can be written: ::

            Ex().has_output(r'this\\s+is\\s+a\\s+print\\s*out')

        Submissions that would pass: ::

            echo 'this   is a print out'
            test='this is a printout!' && echo $test

        Submissions that would fail: ::

            echo 'this is a wrong printout'
    """

    stu_output = state.student_result

    if strip_ansi: stu_output = _strip_ansi(stu_output)

    # either simple text matching or regex test
    res = text in stu_output if fixed else re.search(text, stu_output)

    if not res:
        _msg = state.build_message(incorrect_msg, fmt_kwargs={ 'text': text, 'fixed': fixed })
        state.do_test(_msg)

    return state