Git Product home page Git Product logo

mockingbird's People

Contributors

philippmdoerner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mockingbird's Issues

Make {.mockable.} useable with generics

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.

Add `testImport` and `mockImport`

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.