Skip to content

Commit fa5a298

Browse files
committed
Merge pull request #14 from ForNeVeR/master
Tests and bugfixes
2 parents 6d64f3f + 6b1b846 commit fa5a298

8 files changed

Lines changed: 162 additions & 4 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
bin/
22
obj/
3-
*.suo
3+
*.suo
4+
/_ReSharper.Naggum/
5+
/*.user
6+
/packages/

Naggum.Runtime/Symbol.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1-
using System;
1+
/* Copyright (C) 2012 by ForNeVeR, Hagane
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE. */
20+
21+
using System;
222

323
namespace Naggum.Runtime
424
{
@@ -16,15 +36,36 @@ public Symbol(String aName)
1636

1737
bool IEquatable<Symbol>.Equals(Symbol other)
1838
{
19-
return Name.Equals(other.Name);
39+
return AreEqual(this, other);
2040
}
2141

42+
public override bool Equals(object obj)
43+
{
44+
var symbol = obj as Symbol;
45+
if (symbol != null)
46+
{
47+
return AreEqual(this, symbol);
48+
}
49+
50+
return false;
51+
}
52+
53+
public override int GetHashCode()
54+
{
55+
return Name.GetHashCode();
56+
}
57+
2258
/// <summary>
2359
/// </summary>
2460
/// <returns>Returns symbol's name as string.</returns>
2561
public override string ToString()
2662
{
2763
return Name;
2864
}
65+
66+
private static bool AreEqual(Symbol one, Symbol other)
67+
{
68+
return one.Name.Equals(other.Name);
69+
}
2970
}
3071
}

Naggum.Test/CompilerTest.fs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(* Copyright (C) 2012 by ForNeVeR
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE. *)
20+
21+
namespace Naggum.Test
22+
open Naggum.Compiler
23+
open NUnit.Framework
24+
open System.Diagnostics
25+
open System.IO
26+
27+
[<TestFixture>]
28+
type CompilerTest() =
29+
let sourceFilename = @"..\..\..\tests\test.naggum"
30+
31+
[<Test>]
32+
member this.RunTest() =
33+
let filename = "test.exe"
34+
35+
use stream = File.Open(sourceFilename, FileMode.Open)
36+
Generator.compile stream "test" filename []
37+
ignore <| (Process.Start filename).WaitForExit(30000) // 30 sec should be enough

Naggum.Test/Naggum.Test.fsproj

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{38230cbd-de3e-4470-925f-de966e8691aa}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>Naggum.Test</RootNamespace>
11+
<AssemblyName>Naggum.Test</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<Name>Naggum.Test</Name>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<Tailcalls>false</Tailcalls>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<WarningLevel>3</WarningLevel>
23+
<DocumentationFile>bin\Debug\Naggum.Test.XML</DocumentationFile>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<Tailcalls>true</Tailcalls>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<WarningLevel>3</WarningLevel>
32+
<DocumentationFile>bin\Release\Naggum.Test.XML</DocumentationFile>
33+
</PropertyGroup>
34+
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="!Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
35+
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
36+
<ItemGroup>
37+
<Compile Include="CompilerTest.fs" />
38+
<None Include="packages.config" />
39+
</ItemGroup>
40+
<ItemGroup>
41+
<Reference Include="mscorlib" />
42+
<Reference Include="FSharp.Core" />
43+
<Reference Include="nunit.framework">
44+
<HintPath>..\packages\NUnit.2.6.1\lib\nunit.framework.dll</HintPath>
45+
<Private>True</Private>
46+
</Reference>
47+
<Reference Include="System" />
48+
<Reference Include="System.Core" />
49+
<Reference Include="System.Numerics" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<ProjectReference Include="..\ngc\ngc.fsproj">
53+
<Name>ngc</Name>
54+
<Project>{a4269c5e-e4ac-44bf-a06e-1b45248910ad}</Project>
55+
<Private>True</Private>
56+
</ProjectReference>
57+
</ItemGroup>
58+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
59+
Other similar extension points exist, see Microsoft.Common.targets.
60+
<Target Name="BeforeBuild">
61+
</Target>
62+
<Target Name="AfterBuild">
63+
</Target>
64+
-->
65+
</Project>

Naggum.Test/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="2.6.1" targetFramework="net40" />
4+
</packages>

Naggum.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test programs", "Test progr
1010
EndProject
1111
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Naggum.Runtime", "Naggum.Runtime\Naggum.Runtime.csproj", "{402B5E79-E063-4833-AE4B-2986AEEC1D75}"
1212
EndProject
13+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Naggum.Test", "Naggum.Test\Naggum.Test.fsproj", "{38230CBD-DE3E-4470-925F-DE966E8691AA}"
14+
EndProject
1315
Global
1416
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1517
Debug|Any CPU = Debug|Any CPU
@@ -24,6 +26,10 @@ Global
2426
{402B5E79-E063-4833-AE4B-2986AEEC1D75}.Debug|Any CPU.Build.0 = Debug|Any CPU
2527
{402B5E79-E063-4833-AE4B-2986AEEC1D75}.Release|Any CPU.ActiveCfg = Release|Any CPU
2628
{402B5E79-E063-4833-AE4B-2986AEEC1D75}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{38230CBD-DE3E-4470-925F-DE966E8691AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{38230CBD-DE3E-4470-925F-DE966E8691AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{38230CBD-DE3E-4470-925F-DE966E8691AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{38230CBD-DE3E-4470-925F-DE966E8691AA}.Release|Any CPU.Build.0 = Release|Any CPU
2733
EndGlobalSection
2834
GlobalSection(SolutionProperties) = preSolution
2935
HideSolutionNode = FALSE

ngc/Generator.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ let compile (source : Stream) (assemblyName : string) (fileName : string) (asmRe
5959
let rta = Assembly.LoadFrom("Naggum.Runtime.dll")
6060
context.loadAssembly rta
6161

62+
// Load .NET runtime and all referenced assemblies:
63+
context.loadAssembly <| Assembly.Load "mscorlib"
6264
List.iter context.loadAssembly (List.map Assembly.LoadFrom asmRefs)
6365

6466
prologue ilGenerator

tests/test.naggum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
(System.Console.WriteLine "Instance calls:")
5353
(let ((test-obj (new System.Random)))
5454
(System.Console.Write "Random number:")
55-
(System.Console.WriteLine (call Next test-obj))))
55+
(System.Console.WriteLine (call Next test-obj))))
5656

5757
(System.Console.WriteLine "Naggum test suite")
5858

0 commit comments

Comments
 (0)