{"id":2701,"date":"2022-02-23T14:18:21","date_gmt":"2022-02-23T08:48:21","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2701"},"modified":"2022-02-23T14:18:21","modified_gmt":"2022-02-23T08:48:21","slug":"selective-unit-testing-in-d-language","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/","title":{"rendered":"Selective Unit Testing in D Language"},"content":{"rendered":"<p>In the <a href=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/06\/support-for-unit-testing-in-d-language\/\" target=\"_blank\" rel=\"noopener\"><em><strong>last article<\/strong><\/em><\/a>, I briefly explained how <em><strong>D<\/strong><\/em> language has built-in support for performing unit tests. I feel this is an advantage over many current languages.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>What if we want to run only a subset of unit tests? Although it is a good idea to run the unit tests every time there is a change in the code, if the project is large, running all the tests every time might be an overhead and not necessary too.<\/p>\n<p>In a real project, we might have separate unit tests for function definitions, classes and so on. Let us suppose that at a certain point in time, we wish to test just the function unit tests, ignoring class unit tests or the other way. How do we achieve this?<\/p>\n<p>First, here is sample <em><strong>D<\/strong><\/em> code that defines a function <em><strong>&#8220;findMax&#8221;<\/strong><\/em> and a class <em><strong>&#8220;BankAccount&#8221;<\/strong><\/em> along with respective unit test blocks:<\/p>\n<figure id=\"attachment_2702\" aria-describedby=\"caption-attachment-2702\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Code1.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2702\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/code1-3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Code1.jpg\" data-orig-size=\"691,1275\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645608296&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Code with Unit Tests\" data-image-description=\"&lt;p&gt;Code with Unit Tests&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code with Unit Tests&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Code1-555x1024.jpg\" class=\"wp-image-2702\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Code1.jpg?resize=500%2C923&#038;ssl=1\" alt=\"Code with Unit Tests\" width=\"500\" height=\"923\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Code1.jpg?resize=163%2C300&amp;ssl=1 163w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Code1.jpg?resize=555%2C1024&amp;ssl=1 555w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Code1.jpg?w=691&amp;ssl=1 691w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2702\" class=\"wp-caption-text\"><strong>Code with Unit Tests<\/strong><\/figcaption><\/figure>\n<p>As before, we enable <em><strong>&#8220;unittest&#8221;<\/strong><\/em> in the <em><strong>Project<\/strong><\/em> properties:<\/p>\n<figure id=\"attachment_2703\" aria-describedby=\"caption-attachment-2703\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-Unittest.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2703\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/enable-unittest\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-Unittest.jpg\" data-orig-size=\"1058,650\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645606556&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Enabling Unit Tests\" data-image-description=\"&lt;p&gt;Enabling Unit Tests&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Enabling Unit Tests&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-Unittest-1024x629.jpg\" class=\"wp-image-2703\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-Unittest.jpg?resize=500%2C307&#038;ssl=1\" alt=\"Enabling Unit Tests\" width=\"500\" height=\"307\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-Unittest.jpg?resize=300%2C184&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-Unittest.jpg?resize=1024%2C629&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-Unittest.jpg?resize=768%2C472&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-Unittest.jpg?w=1058&amp;ssl=1 1058w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2703\" class=\"wp-caption-text\"><strong>Enabling Unit Tests<\/strong><\/figcaption><\/figure>\n<p>When we build and run the program, the output is as expected (remember, only the unit tests are run):<\/p>\n<figure id=\"attachment_2704\" aria-describedby=\"caption-attachment-2704\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2704\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/run1-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run1.jpg\" data-orig-size=\"978,110\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645608335&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Tests Run OK\" data-image-description=\"&lt;p&gt;Tests Run OK&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Tests Run OK&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run1.jpg\" class=\"wp-image-2704\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run1.jpg?resize=600%2C67&#038;ssl=1\" alt=\"Tests Run OK\" width=\"600\" height=\"67\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run1.jpg?resize=300%2C34&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run1.jpg?resize=768%2C86&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run1.jpg?w=978&amp;ssl=1 978w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2704\" class=\"wp-caption-text\"><strong>Tests Run OK<\/strong><\/figcaption><\/figure>\n<p>What we have seen above is the normal way to run unit tests. Let us now get back to our earlier question: How to run only the unit test block that tests the function <em><strong>&#8220;findMax&#8221;<\/strong><\/em>?<\/p>\n<p>It would have been nice if <em><strong>D<\/strong><\/em> language allowed <em><strong>&#8220;named&#8221;<\/strong><\/em> unit test blocks like so:<\/p>\n<figure id=\"attachment_2705\" aria-describedby=\"caption-attachment-2705\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Nolabel.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2705\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/nolabel\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Nolabel.jpg\" data-orig-size=\"798,179\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645608510&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Naming Unittest Blocks\" data-image-description=\"&lt;p&gt;Naming Unittest Blocks&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Naming Unittest Blocks&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Nolabel.jpg\" class=\"wp-image-2705\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Nolabel.jpg?resize=500%2C112&#038;ssl=1\" alt=\"Naming Unittest Blocks\" width=\"500\" height=\"112\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Nolabel.jpg?resize=300%2C67&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Nolabel.jpg?resize=768%2C172&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Nolabel.jpg?w=798&amp;ssl=1 798w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2705\" class=\"wp-caption-text\"><strong>Naming Unittest Blocks<\/strong><\/figcaption><\/figure>\n<p>If this were possible, then we might be able to specify which <em><strong>&#8220;named&#8221;<\/strong><\/em> tests must be run. Unfortunately, this won&#8217;t work and it results in compiler error!<\/p>\n<p>So what is the other option? Here is where <em><strong>&#8220;version&#8221;<\/strong><\/em> feature of the language comes in handy. It is a <em><strong>compiler (preprocessor)<\/strong><\/em> feature that can be used to include or exclude code fragments. It allows us to wrap unit test blocks in suitable <em><strong>&#8220;version&#8221;<\/strong><\/em> tags. In our case, we can do the following:<\/p>\n<figure id=\"attachment_2706\" aria-describedby=\"caption-attachment-2706\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/using-version.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2706\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/using-version\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/using-version.jpg\" data-orig-size=\"680,437\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645609067&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Using Version Tags\" data-image-description=\"&lt;p&gt;Using Version Tags&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using Version Tags&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/using-version.jpg\" class=\"wp-image-2706\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/using-version.jpg?resize=500%2C321&#038;ssl=1\" alt=\"Using Version Tags\" width=\"500\" height=\"321\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/using-version.jpg?resize=300%2C193&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/using-version.jpg?resize=140%2C90&amp;ssl=1 140w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/using-version.jpg?w=680&amp;ssl=1 680w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2706\" class=\"wp-caption-text\"><strong>Using Version Tags<\/strong><\/figcaption><\/figure>\n<p>Note that for convenience, I have grouped the unit test blocks together.<\/p>\n<p>Now, we can enable only the <em><strong>&#8220;function_unit_test&#8221;<\/strong><\/em> block this way:<\/p>\n<figure id=\"attachment_2707\" aria-describedby=\"caption-attachment-2707\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-function-test.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2707\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/enable-function-test\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-function-test.jpg\" data-orig-size=\"1058,650\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645608773&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Enabling Function Tests Only\" data-image-description=\"&lt;p&gt;Enabling Function Tests Only&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Enabling Function Tests Only&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-function-test-1024x629.jpg\" class=\"wp-image-2707\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-function-test.jpg?resize=500%2C307&#038;ssl=1\" alt=\"Enabling Function Tests Only\" width=\"500\" height=\"307\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-function-test.jpg?resize=300%2C184&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-function-test.jpg?resize=1024%2C629&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-function-test.jpg?resize=768%2C472&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enable-function-test.jpg?w=1058&amp;ssl=1 1058w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2707\" class=\"wp-caption-text\"><strong>Enabling Function Tests Only<\/strong><\/figcaption><\/figure>\n<p>When we build the project now and run it, this is what we get:<\/p>\n<figure id=\"attachment_2708\" aria-describedby=\"caption-attachment-2708\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2708\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/run2-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run2.jpg\" data-orig-size=\"972,152\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645608870&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Program Output\" data-image-description=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run2.jpg\" class=\"wp-image-2708\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run2.jpg?resize=600%2C94&#038;ssl=1\" alt=\"Program Output\" width=\"600\" height=\"94\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run2.jpg?resize=300%2C47&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run2.jpg?resize=768%2C120&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run2.jpg?w=972&amp;ssl=1 972w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2708\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>Similarly, we can enable <em><strong>&#8220;class_unit_test&#8221;<\/strong><\/em> if we want. Hope you get the idea.<\/p>\n<p>But what if we want <em><strong>&#8220;all&#8221;<\/strong><\/em> the unit tests to run? It would be tedious to enable all version tags individually. This is where <em><strong>&#8220;version assigment&#8221;<\/strong><\/em> feature comes in handy:<\/p>\n<figure id=\"attachment_2709\" aria-describedby=\"caption-attachment-2709\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2709\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/enabling-all\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all.jpg\" data-orig-size=\"610,560\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645609340&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Enabling All Unit Tests\" data-image-description=\"&lt;p&gt;Enabling All Unit Tests&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Enabling All Unit Tests&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all.jpg\" class=\"wp-image-2709\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all.jpg?resize=500%2C459&#038;ssl=1\" alt=\"Enabling All Unit Tests\" width=\"500\" height=\"459\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all.jpg?resize=300%2C275&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all.jpg?w=610&amp;ssl=1 610w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2709\" class=\"wp-caption-text\"><strong>Enabling All Unit Tests<\/strong><\/figcaption><\/figure>\n<p>We can then enable <em><strong>&#8220;all_tests&#8221;<\/strong><\/em> version tag and this automatically takes care of including the full set of unit tests (or whatever have been assigned):<\/p>\n<figure id=\"attachment_2710\" aria-describedby=\"caption-attachment-2710\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all-flag.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2710\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/enabling-all-flag\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all-flag.jpg\" data-orig-size=\"1058,650\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645609398&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Enabling the Compiler Flag\" data-image-description=\"&lt;p&gt;Enabling the Compiler Flag&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Enabling the Compiler Flag&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all-flag-1024x629.jpg\" class=\"wp-image-2710\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all-flag.jpg?resize=500%2C307&#038;ssl=1\" alt=\"Enabling the Compiler Flag\" width=\"500\" height=\"307\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all-flag.jpg?resize=300%2C184&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all-flag.jpg?resize=1024%2C629&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all-flag.jpg?resize=768%2C472&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Enabling-all-flag.jpg?w=1058&amp;ssl=1 1058w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2710\" class=\"wp-caption-text\"><strong>Enabling the Compiler Flag<\/strong><\/figcaption><\/figure>\n<p>When we build and run the program, both the unit test blocks are executed:<\/p>\n<figure id=\"attachment_2711\" aria-describedby=\"caption-attachment-2711\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2711\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/23\/selective-unit-testing-in-d-language\/run3-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run3.jpg\" data-orig-size=\"967,158\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1645609305&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Program Output\" data-image-description=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run3.jpg\" class=\"wp-image-2711\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run3.jpg?resize=600%2C98&#038;ssl=1\" alt=\"Program Output\" width=\"600\" height=\"98\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run3.jpg?resize=300%2C49&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run3.jpg?resize=768%2C125&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Run3.jpg?w=967&amp;ssl=1 967w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2711\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>This is quite convenient, isn&#8217;t it? Of course, nothing prevents us from <em><strong>grouping<\/strong><\/em> different unit tests using different version tags accoding to our requirement. What I have discussed above is just an example.<\/p>\n<p>Ideally, of course, I would prefer <em><strong>&#8220;named&#8221;<\/strong><\/em> unit test blocks as hinted earlier. Hope the language designers introduce such a feature in future!<\/p>\n<p>Here is the <a href=\"http:\/\/www.rangakrish.com\/downloads\/SelectiveUnitTesting.d\" target=\"_blank\" rel=\"noopener\"><em><strong>source code<\/strong><\/em><\/a>\u00a0used in this example.<\/p>\n<p>Have a wonderful week!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the last article, I briefly explained how D language has built-in support for performing unit tests. I feel this is an advantage over many current languages.\u00a0 What if we want to run only a subset of unit tests? Although it is a good idea to run the unit tests every time there is a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[302,17],"tags":[304,310],"class_list":["post-2701","post","type-post","status-publish","format-standard","hentry","category-d-language","category-programming","tag-d-language","tag-version-tag"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-Hz","jetpack-related-posts":[{"id":2686,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/02\/06\/support-for-unit-testing-in-d-language\/","url_meta":{"origin":2701,"position":0},"title":"Support for Unit Testing in D Language","author":"admin","date":"February 6, 2022","format":false,"excerpt":"While I admire D language for many of its elegant and powerful features, two features stand out in my opinion. These are support for Design by Contract (DBC) and Unit Testing. I am a great fan of DBC and will cover that feature in a future article. Today I let\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Enabling \"unittest\"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Unittest-settting-300x184.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Unittest-settting-300x184.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/02\/Unittest-settting-300x184.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2668,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/01\/23\/template-mixins-in-d-programming-language\/","url_meta":{"origin":2701,"position":1},"title":"Template Mixins in D Programming Language","author":"admin","date":"January 23, 2022","format":false,"excerpt":"When I heard the name Mixin\u00a0for the first time in the context of Dlang, I imagined it would be something similar to the mixins\u00a0of Common Lisp, but I was completely wrong!\u00a0 Mixins are a very interesting feature of D language. They allow code to be \"injected\" into the source at\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Simple Template Mixin","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/01\/Defn-300x98.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2645,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/12\/25\/calling-lisp-functions-from-d-language\/","url_meta":{"origin":2701,"position":2},"title":"Calling Lisp Functions from D Language","author":"admin","date":"December 25, 2021","format":false,"excerpt":"After exploring \"newLisp\" in the past few posts, I would like to start looking at the \"D Programming Language\"\u00a0(DLang). DLang\u00a0has been around since 2001. It was originally created by Walter Bright and later Andrei Alexandrescu joined the team in 2007. The main inspiration for DLang was C++, although it uses\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Lisp Function Called from D","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/12\/Lisp-300x107.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":928,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/05\/27\/calling-go-functions-from-lisp\/","url_meta":{"origin":2701,"position":3},"title":"Calling Go Functions from Lisp","author":"admin","date":"May 27, 2018","format":false,"excerpt":"For the past few weeks I was travelling in the USA and had the pleasure of meeting several friends, some of whom are senior developers and architects. It was interesting to learn that many of them were either using Go language in their daily work, or were passionately endorsing the\u2026","rel":"","context":"In &quot;Golang&quot;","block_context":{"text":"Golang","link":"https:\/\/www.rangakrish.com\/index.php\/category\/golang\/"},"img":{"alt_text":"Part of Header File","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/05\/Header-file.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/05\/Header-file.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/05\/Header-file.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2722,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/03\/06\/lazy-parameter-evaluation-in-d-language\/","url_meta":{"origin":2701,"position":4},"title":"Lazy Parameter Evaluation in D Language","author":"admin","date":"March 6, 2022","format":false,"excerpt":"Languages such as C\/C++ and Java follow an\u00a0\"eager\" argument evaluation approach, where function arguments are evaluated before the function is entered. Of course, there are idioms and tricks that one can use to force \"lazy\" evaluation. The primary benefit of \"lazy\" parameter evaluation is that the parameter is evaluated only\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Example Program","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/03\/eagercode-237x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3312,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/01\/28\/the-hy-programming-language\/","url_meta":{"origin":2701,"position":5},"title":"The Hy Programming Language","author":"admin","date":"January 28, 2024","format":false,"excerpt":"In an earlier article\u00a0I had explained how to execute Python code from within Common Lisp using \u201cCLPython\u201d package. In contrast to that approach, \u201cHy\u201d\u00a0is a Lisp-style language (not compatible with Common Lisp) that is embedded in Python and hence provides seamless interoperability with Python code. Installation is straightforward (it is\u2026","rel":"","context":"In &quot;Hy Language&quot;","block_context":{"text":"Hy Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/hy-language\/"},"img":{"alt_text":"Hy REPL","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/01\/console-300x148.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=2701"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2701\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}