Skip to content

Commit ad27cf5

Browse files
committed
First tests running
1 parent 923a8f7 commit ad27cf5

File tree

9 files changed

+80
-3
lines changed

9 files changed

+80
-3
lines changed

Build.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ Target.create "Run" (fun _ ->
3232

3333
Target.create "RunTests" (fun _ ->
3434
run dotnet "build" testsPath
35-
[ "native", dotnet "watch run" testsPath
35+
[ "native", dotnet "run" testsPath
3636
"python", dotnet $"run -c Release -p {cliPath} -- --lang Python --exclude Fable.Core --outDir {buildPath}/tests" testsPath
3737
]
3838
|> runParallel
39+
Shell.Exec("touch", $"{buildPath}/tests/__init__.py") |> ignore
40+
run pytest $"{buildPath}/tests" ""
3941
)
4042

4143
Target.create "Format" (fun _ ->
@@ -54,6 +56,7 @@ let dependencies = [
5456
==> "Run"
5557

5658
"InstallClient"
59+
==> "Build"
5760
==> "RunTests"
5861
]
5962

Helpers.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ let createProcess exe arg dir =
7272
|> CreateProcess.ensureExitCode
7373

7474
let dotnet = createProcess "dotnet"
75+
76+
77+
let pytest = createProcess "pytest"
78+
7579
let npm =
7680
let npmPath =
7781
match ProcessUtils.tryFindFileOnPath "npm" with

src/Builtins.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Fable.Python.Builtins
2+
3+
open System.Collections.Generic
4+
open Fable.Core
5+
6+
// fsharplint:disable MemberNames,InterfaceNames
7+
8+
type Builtins =
9+
abstract print : obj: obj -> unit
10+
abstract map : ('T1 -> 'T2) * IEnumerable<'T1> -> IEnumerable<'T2>
11+
abstract map : ('T1 * 'T2 -> 'T3) * IEnumerable<'T1> * IEnumerable<'T2> -> IEnumerable<'T3>
12+
abstract map : ('T1 * 'T2 * 'T3 -> 'T4) * IEnumerable<'T1> * IEnumerable<'T2> * IEnumerable<'T3> -> IEnumerable<'T4>
13+
14+
let builtins: Builtins = nativeOnly

src/Fable.Python.fsproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
<WarnOn>3390;$(WarnOn)</WarnOn>
77
</PropertyGroup>
88
<ItemGroup>
9+
<Compile Include="Builtins.fs" />
910
<Compile Include="Json.fs" />
1011
</ItemGroup>
1112
<ItemGroup>
1213
<ProjectReference Include="../../Fable/src/Fable.Core/Fable.Core.fsproj" />
1314
</ItemGroup>
15+
<ItemGroup>
16+
<Content Include="pyproject.toml; *.fsproj; **\*.fs; **\*.fsi" PackagePath="fable\" />
17+
</ItemGroup>
1418
<Import Project="..\.paket\Paket.Restore.targets" />
1519
</Project>

src/Json.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
open Fable.Core
44

5+
// fsharplint:disable MemberNames,InterfaceNames
56

67
type Json =
78
abstract dumps : obj: obj -> string
9+
abstract loads : string -> obj
810

9-
[<ImportDefault("os")>]
11+
[<ImportDefault("json")>]
1012
let json: Json = nativeOnly

src/pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
[tool.poetry]
3+
name = "fable-python"
4+
version = "0.1.0"
5+
description = "Python bindings for Fable"
6+
authors = ["Dag Brattli <[email protected]>"]
7+
license = "MIT"
8+
9+
[tool.poetry.dependencies]
10+
python = "^3.8"
11+
fable-library = "^0.0.1"
12+
13+
[tool.poetry.dev-dependencies]
14+
15+
[build-system]
16+
requires = ["poetry-core>=1.0.0"]
17+
build-backend = "poetry.core.masonry.api"

test/Fable.Python.Test.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</ItemGroup>
1414
<ItemGroup>
1515
<Compile Include="Util.fs" />
16+
<Compile Include="TestBuiltins.fs" />
1617
<Compile Include="TestJson.fs" />
1718
<Compile Include="Main.fs" />
1819
</ItemGroup>

test/TestBuiltins.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Fable.Python.Tests.Builtins
2+
3+
open Util.Testing
4+
open Fable.Python.Builtins
5+
6+
// type MyObject = {
7+
// Foo: int
8+
// Bar: string
9+
// }
10+
11+
[<Fact>]
12+
let ``test print works`` () =
13+
let result = builtins.print "Hello, world!"
14+
result |> equal ()

test/TestJson.fs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
module Fable.Python.Tests.Json
22

33
open Util.Testing
4+
open Fable.Python.Json
45

6+
// type MyObject = {
7+
// Foo: int
8+
// Bar: string
9+
// }
510

611
[<Fact>]
7-
let ``test Seq.empty works`` () =
12+
let ``test works`` () =
813
let result = true
914
result |> equal true
15+
16+
[<Fact>]
17+
let ``test json dumps works`` () =
18+
let object = {| A=10; B=20 |}
19+
let result = json.dumps object
20+
result |> equal """{"A": 10, "B": 20}"""
21+
22+
[<Fact>]
23+
let ``test json loads works`` () =
24+
let input = """{"Foo": 10, "Bar": "test"}"""
25+
let object = {| Foo=10; Bar="test" |}
26+
let result : {| Foo: int; Bar: string |}= unbox (json.loads input)
27+
result |> equal object

0 commit comments

Comments
 (0)