How to speed up unit test execution?
Currently each file takes about 0.3 sec to execute. There're going to be hundreds of them. The subset of Nim I use is OOP-like with many small files. How can I speed up unit test execution? Here is a gif to demonstrate the speed: [https://github.com/mem-memov/mocknim](https://github.com/mem-memov/mocknim)
Object last values not visible in finalizer
Is there a way to check the state of a **ref object** before it is demolished by the garbage collector? type A = ref object count: int proc finalize(o: A) = echo "count: " & $o.count # shows "count: 0" instead of "count: 555" var a = A(count: 555) new(a, finalize) a = nil GC_fullCollect() Run
Re: Is this bug still valid in fieldPairs iterator?
Thanks for reply! I`ll use it then.
Is this bug still valid in fieldPairs iterator?
Trying to iterate over keys and values of a tuple. In the documentations I find such a notice "The current implementation also has a bug that affects symbol binding in the loop body." [https://nim-lang.org/docs/system.html#fieldPairs.i%2CS%2CT](https://nim-lang.org/docs/system.html#fieldPairs.i%2CS%2CT) Does this still hold true? Can this feature be used?
How to invoke finalizer?
Trying to count procedure calls at the time a mock object gets destroyed. But I cannot get any simple code running. Please explain the syntax of finalizers for **ref** types. type A = ref object proc finalizer(a: A) = echo "-" proc foo(): A = var a {.global.}: A = A() new(a, finalizer) return a var a = foo() GC_fullCollect() Run
Re: inserting one template inside another
I managed to achieve this combination of two AST trees using the quote feature. [https://github.com/mem-memov/mocknim/blob/15f1bd6f94d01a4b3d47b18c9c5b1a782c02a3cc/src/mocknim/templates/resultActionTemplate.nim#L39](https://github.com/mem-memov/mocknim/blob/15f1bd6f94d01a4b3d47b18c9c5b1a782c02a3cc/src/mocknim/templates/resultActionTemplate.nim#L39) The only thing I dislike is how the result variable of the surrounding function travels inside the quote block. But they say it has been already fixed last summer (for macros). [https://github.com/nim-lang/Nim/issues/7323#issuecomment-451684288](https://github.com/nim-lang/Nim/issues/7323#issuecomment-451684288) The activity of AST stitching resembles to me DOM manipulation in JS.
Re: inserting one template inside another
Sorry I failed to describe my problem an a sufficient way. I was trying to concatenate templates so that a variable defined in one of them is visible in the other one. But without being visible that calls the resulting combined template. You are right I have much to learn yet.
Re: inserting one template inside another
Thank you for a useful advice. I create a mock of a procedure. I load module file, get a procedure AST out of it. Then I try to replace its body with assert statements. assert(a == values.a) assert(b == values.b) Run where a and b are arguments of the procedure
inserting one template inside another
I generate two AST's using two different templates. Replacing one node of the fist tree with the whole second tree woks fine. How can I define a variable in the first template and use it in the second? template first(): untiped = var n = 1 echo "this very line gets replaced with code from another template" template second(): untiped = n = 2 # <-- undefined Run Working with macros without using templates is an exhausting affair. A couple lines of code produces a giant tree. I can't use one single template because I can't iterate over passed arguments. So I've come up with such a solution: to generate tees separately and then merge them into one.
Re: TDD reference project
Writing a mocking library. [https://github.com/mem-memov/mocknim](https://github.com/mem-memov/mocknim) Hopefully it will be able to mock itself at least.
Re: "Nim needs better documentation" - share your thoughts
I'm trying Nim for the first time, four days to be precise. I had a couple of moments when I did not understand compiler messages. I did not know which places in my code to look at. With some luck I found good suggestions on the Internet. If I hadn't found these solutions I wouldn't be using Nim now. It's because when everything is new in a language one is not sure and not ready to spend hours thinking about the roots of a problem. The first issue was about name conflicts of modules residing in different folders inside src (resolved with foo.nimble file in each sub-folder). The second issue was about import statement. I was constantly forgetting to import not only the module I use directly but also the modules for return values if I happened to use them. I'm missing cross references in the Docs ([https://nim-lang.org/docs](https://nim-lang.org/docs)). There are some, but I suppose it could be more of them. An example from PHP documentation with a **See also** section [http://php.net/manual/en/function.array-merge.php](http://php.net/manual/en/function.array-merge.php) Some functions in Nim Docks have very short description. To create projects with Nim I want to stick with the official package manager. I like Nimble for its simple config. It's not that convoluted as Webpack config. But I have not discovered how to use it for importing macros from my other projects. So videos demonstrating Nimble capabilities are in demand. The language itself is very easy to adopt. I just use the part of it I understand. With time new parts are added. It is very good. You don't have to know much (read large chunks of documentation) to start using Nim. Good modern documentation features are online code runners([https://play.kotlinlang.org](https://play.kotlinlang.org)), walk-throughs([https://www.haskell.org](https://www.haskell.org)) and fiddlers ([https://jsfiddle.net/](https://jsfiddle.net/)) where you can share code snippets and run them in a browser.
Best practices of meta-programming
What are the best practices of meta-programming? And what are anti-patterns? So far I could find: * provide debugging info * check AST node type before doing anything with it
How to nimble test nested foldes?
Is it possible to configure **nimble** somehow so that it runs tests in nested folders as well?
Re: Happy New Year! Version 0.19.2 released!
**choosenim** supplies 0.19.0 [https://nim-lang.org/install_unix.html](https://forum.nim-lang.org/postActivity.xml#https-nim-lang-org-install-unix-html)
import statement suggestion
Not sure if it's correct to place suggestions... But if collective imports from a directory could be nested it were more consistent in my opinion. [https://nim-lang.org/docs/manual.html#modules-import-statement](https://forum.nim-lang.org/postActivity.xml#https-nim-lang-org-docs-manual-html-modules-import-statement) As of Nim 0.19.0 import mocknim/[ # <-- it works name, procedure/procedure, module/[ # <-- it doesn't word directory, module ] ] Run
Re: TDD reference project
Thank you for quick response. I looked into the resources you provided. I suppose another version of JUnit is not just not idiomatic for Nim. I've tried a little meta-programming from the book. It goes surprisingly easy although not much information on the Internet. This activity is like modifying some XML. I'll try to create a macro that mocks a proc of a module. This will allow checking passed parameters and return values which is sufficient to me.
TDD reference project
Looking for a correct way to set up my project to apply TDD. I need a test runner, mocking framework and coverage report to do this properly. Some things I have already figured out but it takes a lot of time that I'd be happy to spend writing application code. **Is there an example project out there with 100% code coverage?** I try to move my project from C to some modern programming language. The project has unit tests in C. But creating mocks manually is tedious and slows development down. [https://github.com/mem-memov/net/tree/master/graph](https://github.com/mem-memov/net/tree/master/graph) At work I use PHP 7.2 and PHPUnit framework which is a great tool. I had an idea that something like this should exist for Nim or D.