philippmdoerner / mockingbird Goto Github PK
View Code? Open in Web Editor NEWA package to mock procedures and functions without turning it all into OOP.
A package to mock procedures and functions without turning it all into OOP.
This currently breaks:
import std/[genasts, macros]
macro mockable*(p: typed): untyped =
when defined(mock):
let
pName = ident($p[0])
newName = ident($p[0] & "Base")
oldPrc = p.copyNimTree
oldPrc[0] = newName
result = genast(pName, oldPrc, newName):
oldPrc
var pName* = newName
else:
result = p
proc toString*[T](x: T): string {.mockable.} = $x
/home/philipp/dev/playground/src/playground.nim(18, 35) template/generic instantiation of `mockable` from here
/usr/lib/nim/std/genasts.nim(87, 13) Error: 'toStringBase' doesn't have a concrete type, due to unspecified generic parameters.
The idea is that your source code no longer has to be changed. You don't test your source-code, you test a modified copy that allows mocking.
How so?
All modules imported via mockImport
get read in, modified as they would be in mocker.nim
(so that the exported procs get the mockable pragma attached) and that modified copy gets written to "testDirectory".
You then import that modified copy in the test.
All modules imported via testImport
get read in, modified in the sense that their imports no longer point to the source code, but instead to the modified copies and that modified testImport
-ed module gets also written to "testDirectory".
You then import that modified copy in the test.
Tests get written for the procs of the testImport-ed module. This means you are no longer actually testing source-code, but near identical code, that should be similar enough.
If that isn't good enough for the user though, they can instead just use mockable themselves in their source code and work with that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.