Skip to content

Commit

Permalink
Add CompilationTests
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 19, 2023
1 parent 0a857d2 commit cc57b90
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,7 @@ project.lock.json
.eggs/
__pycache__/
.python-version
.hypothesis
.hypothesis

# Compilation tests
tests/**/*.actual
37 changes: 37 additions & 0 deletions tests/Integration/Integration/CompilationTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Fable.Tests.CompilationTests

open System.IO
open Expecto

let private data = Path.Combine(__SOURCE_DIRECTORY__, "data")

let tests =
Directory.EnumerateDirectories(data)
|> Seq.map (fun testCaseDir -> //
testCaseAsync
(Path.GetDirectoryName(testCaseDir))
(async {
let project =
Directory.GetFileSystemEntries(testCaseDir, "*.fsproj") |> Seq.exactlyOne
// clean up old actual files
for f in Directory.GetFileSystemEntries(testCaseDir, "*.actual") do
File.Delete f

// Compile project
let exitCode =
Fable.Cli.Entry.main [| project; "--cwd"; "$\"{testCaseDir}\""; "-e"; ".js.actual" |]

Expect.equal exitCode 0 "Expected exit code to be 0"

for expected in Directory.GetFileSystemEntries(testCaseDir, "*.expected") do
let actual = Path.ChangeExtension(expected, ".actual")
Expect.isTrue (File.Exists actual) $"No actual file was produced for {expected}"
let expectedContent = File.ReadAllText expected
let actualContent = File.ReadAllText actual
Expect.equal actualContent expectedContent "The expected content differs from the actual content"

return ()
}))

|> Seq.toList
|> ftestList "Compilation"
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ItemGroup>
<Compile Include="FileWatcherTests.fs" />
<Compile Include="CliTests.fs" />
<Compile Include="CompilationTests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions tests/Integration/Integration/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let allTests =
[
Cli.tests
FileWatcher.tests
CompilationTests.tests
]

open Expecto
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Lib

let g a = a + 1
let f b = g b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Lib

val f: b:int -> int
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

function g(a) {
return a + 1;
}

export function f(b) {
return g(b);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="Library.fsi" />
<Compile Include="Library.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fable.Core" Version="4.0.0" />
<PackageReference Update="FSharp.Core" Version="7.0.400" />
</ItemGroup>

</Project>

0 comments on commit cc57b90

Please sign in to comment.