8/8/2023 0 Comments Cabal 2 download failedIn the file BasicSumTest.hs, we will import the function library BasicSum (in the lib folder), which has the function basicSum that takes two integers and return the sum, the HUnit library, and the System.Exit, which outputs the success or failure of the test: module Main where import BasicSum Now we add the following section to our basic-sum.cabal file: cabal -version: 2.4īuild -depends: base ^ >= 4.14, HUnit ^ >= 1.6, basic -sum -lib The layout should be like the following: app/ Create a directory called tests and inside it create a file named BasicSumTest.hs. In the basic-sum.cabal put the following section: cabal -version: 2.4īuild -depends: base ^ >= 4.14 default - language: Haskell2010 Now, we need to inform cabal of the existence of this library. Inside it, create a file named BasicSum.hs. First, create a directory called lib, which will be our library that will contain the functions that we want to test. Let’s start our camp by mounting our test suite. other-modules: - LANGUAGE extensions used by modules in this package. Modules included in this executable, other than Main. author: - An email address to which users can send suggestions, bug reports, and patches. bug-reports: - The license under which the package is released. description: - A URL where users can report bugs. synopsis: - A longer description of the package. 0 - A short (one-line) description of the package. Its initial look will be this: cabal -version: 2.4 Our file of interest will be the basic-sum.cabal, which is where we will configure the test suite for our application. The initial setting will be like this: app/ Let’s use Cabal to create all the files for our test purposes: cabal init Let’s start our hike by creating a simple folder, named basic-sum and get inside it: mkdir basic-sum & cd basic-sum You can find the installer in the (Downloads ()). It is necessary to have GHC and Cabal installed on your computer. Prerequisitesįor this hike, we need to prepare ourselves. With this post, I want to establish a basic starting point for those that wish to implement TDD in Haskell without much configuration. Although there were numerous sources where I could look, these sources addressed specific points in different styles of making unit tests with Haskell. Therefore, I invite you, reader, to a hike with me so I can show you how to apply TDD with functional programming by making a simple unit test using Haskell, with the HUnit library and Cabal (Common Architecture for Building Applications and Libraries). Another piece of knowledge that I became a fan of was the functional paradigm of programming, which has a more mathematical approach to code thinking. When I came to know Test-Driven Development (TDD), I became an adopter of this way of development and looked to apply it to my code. Testing is an essential step in software development and if done early, it can avoid hours of stress in debugging the code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |