Add Thrown? Thrown-with-msg? To Experimental Clojure.test Ns
Adding thrown?
and thrown-with-msg?
to Experimental Clojure.test Namespace
Introduction
As we continue to evolve and improve the Clojure testing framework, it's essential to consider the needs of our community and provide tools that make migration smoother. In this article, we'll discuss the proposal to add thrown?
and thrown-with-msg?
macros to the experimental clojure.test
namespace. These macros will simplify the process of testing for thrown exceptions and provide a more concise way to write tests.
Background
In Clojure, testing for thrown exceptions can be a bit cumbersome. The current approach involves using the throws?
function from the lazytest.core
namespace, which can be inconvenient to use directly in test code. This is where the proposed thrown?
and thrown-with-msg?
macros come in – they will provide a more convenient and readable way to test for thrown exceptions.
Proposed Solution
The proposed solution involves adding two new macros to the experimental clojure.test
namespace: thrown?
and thrown-with-msg?
. These macros will expand to the following forms:
thrown? ex form
will expand to(lazytest.core/throws? ex (fn [] form))
thrown-with-msg? ex msg form
will expand to(lazytest.core/throws-with-msg? ex msg (fn [] form))
These macros will provide a more concise and readable way to test for thrown exceptions, making it easier to write and maintain test code.
Benefits
The addition of thrown?
and thrown-with-msg?
macros will bring several benefits to the Clojure testing framework:
- Simplified testing: These macros will simplify the process of testing for thrown exceptions, making it easier to write and maintain test code.
- Improved readability: The macros will provide a more concise and readable way to test for thrown exceptions, reducing the complexity of test code.
- Consistency: The addition of these macros will bring consistency to the Clojure testing framework, making it easier for developers to learn and use.
Implementation
To implement the proposed solution, we'll need to add the following code to the experimental clojure.test
namespace:
(defmacro thrown? [ex form]
`(lazytest.core/throws? ~ex (fn [] ~form)))
(defmacro thrown-with-msg? [ex msg form]
`(lazytest.core/throws-with-msg? ~ex ~msg (fn [] ~form)))
This code defines the thrown?
and thrown-with-msg?
macros, which will expand to the desired forms.
Conclusion
The addition of thrown?
and thrown-with-msg?
macros to the experimental clojure.test
namespace will simplify the process of testing for thrown exceptions and provide a more concise way to write tests. These macros will bring several benefits to the Clojure testing framework, including simplified testing, improved readability, and consistency. By implementing these macros, we can make the Clojure testing framework more user-friendly and easier to use.
Future Work
As we continue to evolve and improve the Clojure testing framework, there are several areas for future work:
- Documentation: We'll need to update the documentation to reflect the addition of
thrown?
andthrown-with-msg?
macros. - Testing: We'll need to update the test suite to ensure that the new macros are working correctly.
- Community feedback: We'll need to gather feedback from the community to ensure that the new macros meet the needs of developers.
By addressing these areas, we can ensure that the Clojure testing framework continues to evolve and improve, providing a better experience for developers.
Frequently Asked Questions: Adding thrown?
and thrown-with-msg?
to Experimental Clojure.test Namespace
Introduction
As we continue to discuss the proposal to add thrown?
and thrown-with-msg?
macros to the experimental clojure.test
namespace, we've received several questions from the community. In this article, we'll address some of the most frequently asked questions and provide clarification on the proposed solution.
Q: What is the purpose of thrown?
and thrown-with-msg?
macros?
A: The thrown?
and thrown-with-msg?
macros are designed to simplify the process of testing for thrown exceptions in Clojure. They provide a more concise and readable way to write tests, making it easier to ensure that your code is handling exceptions correctly.
Q: How do thrown?
and thrown-with-msg?
macros differ from throws?
function?
A: The throws?
function from the lazytest.core
namespace is a powerful tool for testing thrown exceptions, but it can be inconvenient to use directly in test code. The thrown?
and thrown-with-msg?
macros provide a more convenient and readable way to test for thrown exceptions, making it easier to write and maintain test code.
Q: What is the syntax for using thrown?
and thrown-with-msg?
macros?
A: The syntax for using thrown?
and thrown-with-msg?
macros is as follows:
thrown? ex form
will expand to(lazytest.core/throws? ex (fn [] form))
thrown-with-msg? ex msg form
will expand to(lazytest.core/throws-with-msg? ex msg (fn [] form))
Q: Can I use thrown?
and thrown-with-msg?
macros with other testing frameworks?
A: Yes, you can use thrown?
and thrown-with-msg?
macros with other testing frameworks, including clojure.test
and test.check
. However, you may need to modify the macros to work with the specific testing framework you are using.
Q: How do I report issues or provide feedback on the thrown?
and thrown-with-msg?
macros?
A: You can report issues or provide feedback on the thrown?
and thrown-with-msg?
macros by opening an issue on the Clojure GitHub repository or by joining the Clojure community Slack channel.
Q: What is the timeline for implementing the thrown?
and thrown-with-msg?
macros?
A: We are currently in the process of implementing the thrown?
and thrown-with-msg?
macros, and we expect to have them available in the experimental clojure.test
namespace within the next few weeks.
Q: How will the thrown?
and thrown-with-msg?
macros be documented?
A: We will provide detailed documentation for the thrown?
and thrown-with-msg?
macros, including examples and usage guidelines. We will also update the Clojure documentation to reflect the addition of these macros.
Q: Can I contribute to the implementation of the thrown?
and thrown-with-msg?
macros?
A: Yes, we welcome contributions from the community. If you are interested in contributing to the implementation of the thrown?
and thrown-with-msg?
macros, please join the Clojure community Slack channel or open an issue on the Clojure GitHub repository.
By addressing these frequently asked questions, we hope to provide clarity and guidance on the proposed solution and encourage community participation in the implementation of the thrown?
and thrown-with-msg?
macros.