• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
          • Er
          • Value-triple
          • Error-checking
          • Error-triple
          • Assert-event
          • Set-warnings-as-errors
          • Hard-error
          • Set-inhibit-er
          • Must-fail
            • Must-fail-with-soft-error
            • Must-fail-with-hard-error
            • Must-fail-with-error
            • Must-fail-local
          • Assert!-stobj
          • Breaks
          • Must-eval-to
          • Ctx
          • Assert!
          • Must-succeed
          • Assert$
          • Ctxp
          • Illegal
          • Er-progn
          • Error1
          • Er-hard
          • Must-succeed*
          • Toggle-inhibit-er
          • Break$
          • Assert*
          • Assert?
          • Er-soft+
          • Er-hard?
          • Must-fail-with-soft-error
          • Must-fail-with-hard-error
          • Must-fail-with-error
          • Must-eval-to-t
          • Er-soft-logic
          • Er-soft
          • Convert-soft-error
          • Toggle-inhibit-er!
          • Set-inhibit-er!
          • Must-prove
          • Must-not-prove
          • Must-fail!
          • Must-be-redundant
          • Must-succeed!
          • Must-fail-local
          • Assert-equal
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
        • Program-wrapper
        • Get-internal-time
        • Basics
        • Packages
        • Oracle-eval
        • Defmacro-untouchable
        • <<
        • Primitive
        • Revert-world
        • Unmemoize
        • Set-duplicate-keys-action
        • Symbols
        • Def-list-constructor
        • Easy-simplify-term
        • Defiteration
        • Fake-oracle-eval
        • Defopen
        • Sleep
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Std/testing
  • Errors

Must-fail

A top-level assert$-like command. Ensures that a command which returns an error-triple—e.g., defun or defthm—will not be successful.

This can be useful for adding simple unit tests of macros, theories, etc. to your books. Basic examples:

(must-fail                      ;; succeeds
  (defun 5))                    ;;   (invalid defun will indeed fail)

(must-fail                      ;; causes an error
  (thm t))                      ;;   (because this thm proves fine)

(must-fail (mv nil (hard-error 'foo "MESSAGE" nil) state))
                                ;; causes an error
                                ;;   (because hard errors propagate past
                                ;;    must-fail by default)

(must-fail (mv nil (hard-error 'foo "MESSAGE" nil) state)
           :expected :hard)     ;; succeeds

(must-fail                      ;; causes an error
  (in-theory (enable floor)))   ;;   (because this works fine)

(must-fail                      ;; causes an error
  (* 3 4))                      ;;   (doesn't return an error triple)

Must-fail is almost just like must-succeed, except that the event is expected to fail instead of succeed. The option :expected is described below; for everything else, please see the documentation for must-succeed for syntax, options, and additional discussion.

Also see must-fail-with-error, must-fail-with-soft-error, and must-fail-with-hard-error, which are essentially aliases for must-fail with different values for the option, :expected, which we now describe.

When the value of keyword :expected is :any, then must-fail succeeds if and only if ACL2 causes an error during evaluation of the supplied form. However :expected is :soft by default, in which case success requires that the error is ``soft'', not ``hard'': hard errors are caused by guard violations, by calls of illegal and hard-error, and by calls of er that are not ``soft''. Finally, if :expected is :hard, then the call of must-fail succeeds if and only if evaluation of the form causes a hard error.

CAVEAT: If a book contains a non-local form that causes proofs to be done, such as one of the form (must-fail (thm ...)), then it might not be possible to include that book. That is because proofs are generally skipped during include-book, and any thm will succeed if proofs are skipped. One fix is to make such forms local. Another fix is to use a wrapper must-fail! that creates a call of must-fail with :check-expansion to t; that causes proofs to be done even when including a book (because of the way that must-fail is implemented using make-event).

Subtopics

Must-fail-with-soft-error
A specialization of must-fail to ensure that a soft error occurs.
Must-fail-with-hard-error
A specialization of must-fail to ensure that a hard error occurs.
Must-fail-with-error
A specialization of must-fail to ensure that an error occurs.
Must-fail-local
A local variant of must-fail.