Navigation Menu

Skip to content

Commit

Permalink
.less parsing errors now result in a ParserException
Browse files Browse the repository at this point in the history
  • Loading branch information
uluhonolulu committed Apr 22, 2012
1 parent c226907 commit 297a721
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/FubuMVC.Less.Tests/DefaultServicesTester.cs
Expand Up @@ -27,6 +27,13 @@ public void less_engine()
.Value.ShouldBeOfType<LessEngine>();
}

[Test]
public void engine_should_use_exception_logger() {
_services.DefaultServiceFor<ILessEngine>()
.Value.As<LessEngine>().Logger
.ShouldBeOfType<ExceptionLogger>();
}

[Test]
public void less_compiler()
{
Expand Down
15 changes: 13 additions & 2 deletions src/FubuMVC.Less.Tests/LessCompilerTester.cs
@@ -1,8 +1,10 @@
using System;
using FubuTestingSupport;
using NUnit.Framework;
using Rhino.Mocks;
using dotless.Core;

using dotless.Core;
using dotless.Core.Parser;

namespace FubuMVC.Less.Tests
{
[TestFixture]
Expand All @@ -14,5 +16,14 @@ public void should_use_less_engine()
ClassUnderTest.Compile(".a{}");
MockFor<ILessEngine>().AssertWasCalled(x => x.TransformToCss(".a{}", null));
}

[Test]
public void should_throw_when_invalid_source() {
var engine = MockFor<LessEngine>();
engine.Parser = new Parser();
engine.Logger = new ExceptionLogger();
Services.Inject<ILessEngine>(engine);
Assert.Throws<ParserException>(() => ClassUnderTest.Compile("bomb()"));
}
}
}
14 changes: 14 additions & 0 deletions src/FubuMVC.Less/ExceptionLogger.cs
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using dotless.Core.Loggers;

namespace FubuMVC.Less {
public class ExceptionLogger : Logger {
public ExceptionLogger() : base(LogLevel.Error) {}
protected override void Log(string message) {
throw new ParserException(message);
}
}
}
2 changes: 2 additions & 0 deletions src/FubuMVC.Less/FubuMVC.Less.csproj
Expand Up @@ -67,10 +67,12 @@
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ExceptionLogger.cs" />
<Compile Include="LessCompiler.cs" />
<Compile Include="LessExtension.cs" />
<Compile Include="LessTransformer.cs" />
<Compile Include="LessTransformerPolicy.cs" />
<Compile Include="ParserException.cs" />
</ItemGroup>
<ItemGroup>
<None Include=".package-manifest" />
Expand Down
2 changes: 1 addition & 1 deletion src/FubuMVC.Less/LessExtension.cs
Expand Up @@ -18,7 +18,7 @@ public void Configure(FubuRegistry registry)

private static void registerDefaultServices(IServiceRegistry s)
{
s.SetServiceIfNone<ILessEngine>(new LessEngine());
s.SetServiceIfNone<ILessEngine>(new LessEngine(){Logger = new ExceptionLogger()});
s.SetServiceIfNone<ILessCompiler, LessCompiler>();
s.AddService<ITransformerPolicy, LessTransformerPolicy>();
}
Expand Down
26 changes: 26 additions & 0 deletions src/FubuMVC.Less/ParserException.cs
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace FubuMVC.Less {
[Serializable]
public class ParserException : Exception {
//
// For guidelines regarding the creation of new exception types, see
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
// and
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
//

public ParserException() {}
public ParserException(string message) : base(message) {}
public ParserException(string message, Exception inner) : base(message, inner) {}

protected ParserException(
SerializationInfo info,
StreamingContext context) : base(info, context) {}
}

}

0 comments on commit 297a721

Please sign in to comment.