Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save svetlyak40wt/a797e91c6d8dd0a7d3e627efdc856782 to your computer and use it in GitHub Desktop.
Save svetlyak40wt/a797e91c6d8dd0a7d3e627efdc856782 to your computer and use it in GitHub Desktop.
Example, how to patch 3party library on fly, converting a ordinal function into a generic.
(setf (fdefinition 'original-report-expected-line)
#'prove.reporter.list::report-expected-line)
(defgeneric report-expected-line (report)
(:documentation "Returns a line which describes a problem with failed test."))
(defmethod report-expected-line (report)
"Default behaviour is to call original Prove's function,
which formats a string, comparing two values."
(original-report-expected-line report))
(setf (fdefinition 'prove.reporter.list::report-expected-line)
#'report-expected-line)
(defclass failed-assertion-report (prove.report:failed-test-report)
())
(defmethod report-expected-line ((report failed-assertion-report))
"Blah bla bla bla")
(prove.reporter.list::report-expected-line
(make-instance 'failed-assertion-report
:got t
:expected t)) => "Blah bla bla bla"
@svetlyak40wt
Copy link
Author

Thanks to beach, from #lisp channel on freenode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment