File tree Expand file tree Collapse file tree 4 files changed +32
-9
lines changed Expand file tree Collapse file tree 4 files changed +32
-9
lines changed Original file line number Diff line number Diff line change 11module Naggum.Test.AssemblerTests
22
3- open System
43open System.IO
5- open System.Reflection
64open System.Text
75
86open Xunit
97
108open Naggum.Assembler
11- open Naggum.Assembler .Representation
129
1310let 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>]
2024let ``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)
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change 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" />
Original file line number Diff line number Diff line change 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 " )
You can’t perform that action at this time.
0 commit comments