{"id":13737247,"url":"https://github.com/jyapayne/einheit","last_synced_at":"2025-05-13T01:43:34.137Z","repository":{"id":34693741,"uuid":"38668666","full_name":"jyapayne/einheit","owner":"jyapayne","description":"Nim unit test library","archived":false,"fork":false,"pushed_at":"2019-11-05T15:17:31.000Z","size":193,"stargazers_count":47,"open_issues_count":1,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-01T05:41:28.744Z","etag":null,"topics":["macro","nim","testing","unittest"],"latest_commit_sha":null,"homepage":null,"language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jyapayne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-07T06:30:47.000Z","updated_at":"2025-02-25T22:50:34.000Z","dependencies_parsed_at":"2022-09-14T18:21:40.794Z","dependency_job_id":null,"html_url":"https://github.com/jyapayne/einheit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyapayne%2Feinheit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyapayne%2Feinheit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyapayne%2Feinheit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyapayne%2Feinheit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jyapayne","download_url":"https://codeload.github.com/jyapayne/einheit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856602,"owners_count":21974574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["macro","nim","testing","unittest"],"created_at":"2024-08-03T03:01:38.504Z","updated_at":"2025-05-13T01:43:34.117Z","avatar_url":"https://github.com/jyapayne.png","language":"Nim","funding_links":[],"categories":["Development Tools"],"sub_categories":["Testing"],"readme":"# einheit\n\nEinheit means unit in German.\n\nEinheit is a Nim unit testing library inspired by Python's unit tests. Nim's unittest library is good, but I wanted something a little more \"Nim\" feeling. I also really like Python's unittest module and thought it would be nice to have something similar in Nim. Also, unittest doesn't have much documentation on how to use it, and it's pretty bare bones, so I wanted a little more functionality and documentation.\n\nThe benefit of the macro style I chose means that you can document your tests nicely as well :)\n\n### Description\ntestSuite is a compile-time macro that allows a user to easily define tests and run them.\n\nMethods are used for inheritance, so if you want to derive a test suite, then you have to make sure the base suite uses methods for the tests that you want to derive.\n\nIf you don't want inheritance, you can just use procs.\n\nTwo special methods/procs are called setup() and tearDown(). The macro will inject these methods/procs if they don't exist and they will be called before and after running the test suite, respectively.\n\nTest methods/procs to be run are prefixed with \"test\" in the method/proc name. This is so that you can write tests that call procs that do other things and won't be run as a test.\n\nFor each suite method/proc, an implicit variable called \"self\" is added. This lets you access the testSuite in an OO kind of way.\n\nOn failure, the macro gathers names and values of *all* arguments and functions and prints them out. It's really useful for debugging!\n\n### Installation\n\nInstall with nimble!\n\n```bash\nnimble install einheit\n```\n\n### Running\n\n```bash\nnim c -r testing_script.nim\n\n# Or no colors\nnim c -r -d:noColors testing_script.nim\n\n# No colors, quiet output\nnim c -r -d:quiet -d:noColors testing_script.nim\n\n# With Node.js as a target\nnim js -d:nodejs -r testing_script.nim\n\n```\n\n### Usage\n\n```nim\nimport einheit\n\ntestSuite SuiteName of TestSuite:\n\n  var\n    suiteVar: string\n    testObj: int\n\n  method setup()=\n    ## do setup code here\n    self.suiteVar = \"Testing\"\n    self.testObj = 90\n\n  method tearDown()=\n    ## do tear down code here\n    self.suiteVar = nil\n    self.testObj = 0\n\n  method testAddingString()=\n    ## adds a string to the suiteVar\n    self.suiteVar \u0026= \" 123\"\n    self.check(self.suiteVar == \"Testing 123\")\n\n  proc raisesOs()=\n    # This proc won't be invoked as a test, it must begin with \"test\" in lowercase\n    raise newException(OSError, \"Oh no! OS malfunction!\")\n  \n  method testRaises()=\n    # Two ways of checking\n    self.checkRaises OSError:\n      self.raisesOs()\n\n    self.checkRaises(OSError, self.raisesOs())\n\n  method testTestObj()=\n    self.check(self.testObj == 90)\n\n  method testMoreMore()=\n    self.check(\"String\" == \"String\")\n\n  when isMainModule:\n    einheit.runTests()\n```\n\nYou can also find examples in the [test.nim](test.nim) file, including inheritance.\n\n\nOutput of running\n\n```bash\nnim c -r test.nim\n```\n\nis this:\n\n```\n[Running] UnitTests  -----------------------------------------------------------\n\n[OK]     testForB\n[Failed] testArrayAssert\n  Condition: check(self.testArray == [0, 1, 2])\n  Where:\n    self.testArray -\u003e [0, 1, 2, 3]\n  Location: test.nim; line 27\n\n[Failed] testForC\n  Condition: check(c == 1)\n  Where:\n    c -\u003e 0\n  Location: test.nim; line 32\n\n\n[1/3] tests passed for UnitTests. ----------------------------------------------\n\n\n[Running] UnitTestsNew  --------------------------------------------------------\n\n[OK]     testTestObj\n[OK]     testStuff\n[Failed] testMore\n  Condition: check(more == 1)\n  Where:\n    more -\u003e 23\n  Location: test.nim; line 56\n\n[Failed] testMoreMore\n  Condition: check(self.returnTrue())\n  Where:\n    self.returnTrue() -\u003e false\n    self -\u003e ref UnitTestsNew(testObj: 90, name: UnitTestsNew, currentTestName: testMoreMore, testsPassed: 2, numTests: 4)\n  Location: test.nim; line 59\n\n\n[2/4] tests passed for UnitTestsNew. -------------------------------------------\n\n\n[Running] TestInherit  ---------------------------------------------------------\n\n[OK]     testTestObj\n[OK]     testStuff\n[Failed] testMore\n  Condition: check(more == 1)\n  Where:\n    more -\u003e 23\n  Location: test.nim; line 56\n\n[Failed] testMoreMore\n  Condition: check(self.returnTrue())\n  Where:\n    self.returnTrue() -\u003e false\n    self -\u003e ref UnitTestsNew(testObj: 90, name: TestInherit, currentTestName: testMoreMore, testsPassed: 2, numTests: 4)\n  Location: test.nim; line 59\n\n[Failed] testRaises\n  Condition: checkRaises(OSError, self.raisesOs())\n  Where:\n    self.raisesOs() -\u003e SystemError\n  Location: test.nim; line 72\n\n\n[2/5] tests passed for TestInherit. --------------------------------------------\n\n\n[Running] MoreInheritance  -----------------------------------------------------\n\n[Failed] testTestObj\n  Condition: check(self.testObj == 90)\n  Where:\n    self.testObj -\u003e 12345\n  Location: test.nim; line 46\n\n[OK]     testStuff\n[Failed] testMore\n  Condition: check(more == 1)\n  Where:\n    more -\u003e 23\n  Location: test.nim; line 56\n\n[Failed] testMoreMore\n  Condition: check(self.returnTrue())\n  Where:\n    self.returnTrue() -\u003e false\n    self -\u003e ref UnitTestsNew(testObj: 12345, name: MoreInheritance, currentTestName: testMoreMore, testsPassed: 1, numTests: 4)\n  Location: test.nim; line 59\n\n[Failed] testRaises\n  Condition: checkRaises(OSError, self.raisesOs())\n  Where:\n    self.raisesOs() -\u003e SystemError\n  Location: test.nim; line 72\n\n[OK]     testTestObj\n[OK]     testNewObj\n[Failed] testRefObject\n  Condition: check(d == k)\n  Where:\n    k -\u003e ref TestObj(t: 30)\n    d -\u003e ref TestObj(t: 3)\n  Location: test.nim; line 123\n\n[Failed] testObject\n  Condition: check(d == k)\n  Where:\n    k -\u003e TestObj(t: 30)\n    d -\u003e TestObj(t: 3)\n  Location: test.nim; line 138\n\n[Failed] testComplexObject\n  Condition: check(x.isObj(p))\n  Where:\n    x.isObj(p) -\u003e false\n    p -\u003e 4\n    x -\u003e Obj2(d: Obj1(e: Hey))\n  Location: test.nim; line 150\n\n[Failed] testTuple\n  Condition: check(t == r)\n  Where:\n    r -\u003e tuple Person(name: P, age: 3)\n    t -\u003e tuple Person(name: Peter, age: 30)\n  Location: test.nim; line 161\n\n[Failed] testComplex\n  Condition: check(self.doStuff(a, s) == \"5stuff\" and self.doStuff(a, self.doStuff(a, self.doStuff(y, s))) == \"something?\")\n  Where:\n    self.doStuff(a, s) -\u003e 5stuff\n    a -\u003e 5\n    self -\u003e ref MoreInheritance(testObj: 12345, name: MoreInheritance, currentTestName: testComplex, testsPassed: 3, numTests: 12)\n    self.doStuff(a, self.doStuff(a, self.doStuff(y, s))) -\u003e 5545stuff\n    y -\u003e 45\n    s -\u003e stuff\n    self.doStuff(y, s) -\u003e 45stuff\n    self.doStuff(a, self.doStuff(y, s)) -\u003e 545stuff\n  Location: test.nim; line 169\n\n\n[3/12] tests passed for MoreInheritance. ---------------------------------------\n\n\n[Summary]\n\n  [8/24] tests passed.\n```\n\nNotice that on failure, the test runner gives some useful information about the test in question. This is useful for determining why the test failed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjyapayne%2Feinheit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjyapayne%2Feinheit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjyapayne%2Feinheit/lists"}