Comments (3)
type.GetModifiers().AddCustomAttribute (<[ TestFixture ]>);
You should use full name of attribut or open appropriate namespace in file which contains macro.
def methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public);
The GetMethods() method work only at MacroPhase.WithTypedMembers phase (as, since it return typed members).
You should use MacroPhase.WithTypedMembers, or work with antyped AST (through TypeBuilder.Ast).
This version work well:
// Macro.n
using Nemerle;
using Nemerle.Collections;
using Nemerle.Compiler;
using Nemerle.Compiler.Parsetree;
using Nemerle.Compiler.Typedtree;
using Nemerle.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
namespace TestMacro
{
[MacroUsage(MacroPhase.WithTypedMembers, MacroTargets.Class)]
macro UnitTestFixture(typeBuilder : TypeBuilder)
{
UnitTestFixtureImpl.DoTransform(Macros.ImplicitCTX(), typeBuilder)
}
module UnitTestFixtureImpl
{
public DoTransform(typer : Typer, typeBuilder : TypeBuilder) : void
{
Macros.DefineCTX(typer);
typeBuilder.GetModifiers().AddCustomAttribute (<[ NUnit.Framework.TestFixtureAttribute ]>);
def methods = typeBuilder.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
foreach(method in methods)
method.GetModifiers().AddCustomAttribute(<[ NUnit.Framework.TestAttribute ]>);
}
}
}
// Test.n
using TestMacro;
[UnitTestFixture()]
public class OptionalHeaderTests
{
public SomeTest() : void
{
}
}
module Program
{
Main() : void
{
}
}
from nemerle.
Thanks. What about Assembly-level meta attributes? Is there any way to use one attribute declaration such as:
[assembly:UnitTestSuite("MyNamespace.Tests.*")]
...to apply the [UnitTestFixture()] attribute to all types within a given namespace?
from nemerle.
Thanks. What about Assembly-level meta attributes?
Simply replace the MacroTargets.Class by MacroTargets.Assembly and remove the typeBuilder parameter:
using Nemerle;
using Nemerle.Collections;
using Nemerle.Compiler;
using Nemerle.Compiler.Parsetree;
using Nemerle.Compiler.Typedtree;
using Nemerle.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
namespace TestMacro
{
[MacroUsage(MacroPhase.WithTypedMembers, MacroTargets.Assembly)]
macro UnitTestFixture()
{
UnitTestFixtureImpl.DoTransform(Macros.ImplicitCTX())
}
module UnitTestFixtureImpl
{
public DoTransform(typer : Typer) : void
{
Macros.DefineCTX(typer);
def typeBuilders = typer.Manager.CoreEnv.NameTree.NamespaceTree.GetTypeBuilders(onlyTopDeclarations = true);
foreach (typeBuilder in typeBuilders)
{
typeBuilder.GetModifiers().AddCustomAttribute (<[ NUnit.Framework.TestFixtureAttribute ]>);
def methods = typeBuilder.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
foreach(method in methods)
method.GetModifiers().AddCustomAttribute(<[ NUnit.Framework.TestAttribute ]>);
}
}
}
}
Note: If oyu specify "onlyTopDeclarations = false", you get all typebuilders including nested types.
from nemerle.
Related Issues (20)
- VS Plugin doesn't return the BuildAction property through IVsHierarchy HOT 1
- Towards Nemerle 2 - Base Language + Multiple Layers of Macro Define features HOT 4
- Copying files in VS doesn't preserve build-action
- IVsHierarchy returns BuildAction as "Content" after renaming file
- References of Nemerle project not accessible for Nitra Plugin HOT 1
- Suggestion: add list construction using range not including final HOT 8
- Not possible to have indexer with 'ref' HOT 2
- Not worked site Nemerle.org HOT 1
- support vs 2017 HOT 2
- Please support .NET core HOT 10
- Documentation: Typo
- Defining macros results in compiler errors HOT 7
- Suggestion: implement Language Server Protocol
- add wpf template
- Visual Studio 15.9.9 autocomplete not working
- Use vswhere to find the VS path
- VladD2
- Support Mono 6 HOT 1
- Current State of Nemerle HOT 5
- Please consider maintaining the Emacs-Lisp files in a separate repository HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nemerle.