Skip to content

Commit fdfa71d

Browse files
committed
Test: additional tests for assembler.
1 parent 33966ab commit fdfa71d

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

Naggum.Test/AssemblerTests.fs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
module Naggum.Test.AssemblerTests
22

3-
open System
43
open System.IO
5-
open System.Reflection
64
open System.Text
75

86
open Xunit
97

108
open Naggum.Assembler
11-
open Naggum.Assembler.Representation
129

1310
let assemble (source : string) =
1411
use stream = new MemoryStream(Encoding.UTF8.GetBytes source)
1512
let repr = Processor.prepare "file.ngi" stream
1613
let assemblies = Assembler.assemble repr
17-
Array.ofSeq assemblies
14+
List.ofSeq assemblies
15+
16+
let execute source =
17+
let fileName = "file.exe"
18+
let assembly = (Seq.exactlyOne << assemble) source
19+
assembly.Save fileName
20+
21+
Process.run fileName
1822

1923
[<Fact>]
2024
let ``Empty assembly should be assembled`` () =
2125
let source = "(.assembly Empty)"
2226
let result = assemble source
2327
Assert.Equal (1, result.Length)
2428

25-
// TODO: Additional integration tests
29+
[<Fact>]
30+
let ``Hello world should be executed`` () =
31+
let source = "(.assembly Hello
32+
(.method Main () System.Void (.entrypoint)
33+
(ldstr \"Hello, world!\")
34+
(call (mscorlib System.Console WriteLine (System.String) System.Void))
35+
(ret)))
36+
"
37+
let output = execute source
38+
Assert.Equal ("Hello, world!", output)

Naggum.Test/CompilerTest.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ type CompilerTest() =
2626
use stream = File.Open(testPath, FileMode.Open)
2727
Generator.compile stream testName executablePath []
2828

29-
let startInfo = new ProcessStartInfo(executablePath, UseShellExecute = false, RedirectStandardOutput = true)
30-
let ``process`` = Process.Start startInfo
31-
``process``.WaitForExit()
32-
let result = ``process``.StandardOutput.ReadToEnd().Replace("\r\n", "\n")
29+
let result = Process.run executablePath
3330

3431
let reference = (File.ReadAllText resultPath).Replace("\r\n", "\n")
3532
Assert.Equal(reference, result)

Naggum.Test/Naggum.Test.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5353
</Content>
5454
<Content Include="packages.config" />
55+
<Compile Include="Process.fs" />
5556
<Compile Include="CompilerTest.fs" />
5657
<Compile Include="AssemblerTests.fs" />
5758
<Compile Include="ProcessorTests.fs" />

Naggum.Test/Process.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Naggum.Test.Process
2+
3+
open System.Diagnostics
4+
5+
let run fileName =
6+
// TODO: Mono check
7+
let startInfo = ProcessStartInfo (fileName,
8+
UseShellExecute = false,
9+
RedirectStandardOutput = true)
10+
use p = Process.Start startInfo
11+
p.WaitForExit ()
12+
p.StandardOutput.ReadToEnd().Replace ("\r\n", "\n")

0 commit comments

Comments
 (0)