Compare commits

...

9 Commits

Author SHA1 Message Date
Patrick Stevens
277a186fda Allow properties in mocked interfaces (#336) 2025-02-12 23:53:15 +00:00
patrick-conscriptus[bot]
129687ec1c Automated commit (#334)
Co-authored-by: patrick-conscriptus[bot] <175414948+patrick-conscriptus[bot]@users.noreply.github.com>
2025-02-09 01:22:26 +00:00
dependabot[bot]
c7fea55e28 Bump FsCheck from 3.0.1 to 3.1.0 (#333)
* Bump FsCheck from 3.0.1 to 3.1.0

Bumps [FsCheck](https://github.com/Fscheck/fscheck) from 3.0.1 to 3.1.0.
- [Release notes](https://github.com/Fscheck/fscheck/releases)
- [Changelog](https://github.com/fscheck/FsCheck/blob/master/FsCheck%20Release%20Notes.md)
- [Commits](https://github.com/Fscheck/fscheck/compare/3.0.1...3.1.0)

---
updated-dependencies:
- dependency-name: FsCheck
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Deps

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Smaug123 <3138005+Smaug123@users.noreply.github.com>
2025-02-03 17:28:07 +00:00
patrick-conscriptus[bot]
ded7b32771 Automated commit (#332)
Co-authored-by: patrick-conscriptus[bot] <175414948+patrick-conscriptus[bot]@users.noreply.github.com>
2025-02-02 01:21:17 +00:00
dependabot[bot]
b272f8b645 Bump FsCheck from 3.0.0 to 3.0.1 (#330)
* Bump FsCheck from 3.0.0 to 3.0.1

Bumps [FsCheck](https://github.com/Fscheck/fscheck) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/Fscheck/fscheck/releases)
- [Changelog](https://github.com/fscheck/FsCheck/blob/master/FsCheck%20Release%20Notes.md)
- [Commits](https://github.com/Fscheck/fscheck/compare/3.0.0...3.0.1)

---
updated-dependencies:
- dependency-name: FsCheck
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Deps

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Smaug123 <3138005+Smaug123@users.noreply.github.com>
2025-01-29 00:49:28 +00:00
dependabot[bot]
b8d60aec90 Bump actions/attest-build-provenance from 2.1.0 to 2.2.0 (#331) 2025-01-27 11:36:25 +00:00
patrick-conscriptus[bot]
0e3510e1e5 Automated commit (#329)
Co-authored-by: patrick-conscriptus[bot] <175414948+patrick-conscriptus[bot]@users.noreply.github.com>
2025-01-26 01:19:46 +00:00
patrick-conscriptus[bot]
8a1edd90d5 Automated commit (#328)
Co-authored-by: patrick-conscriptus[bot] <175414948+patrick-conscriptus[bot]@users.noreply.github.com>
2025-01-19 01:22:30 +00:00
dependabot[bot]
74fdd7c0a9 Bump fantomas from 6.3.16 to 7.0.0 (#326)
* Bump fantomas from 6.3.16 to 7.0.0

Bumps [fantomas](https://github.com/fsprojects/fantomas) from 6.3.16 to 7.0.0.
- [Release notes](https://github.com/fsprojects/fantomas/releases)
- [Changelog](https://github.com/fsprojects/fantomas/blob/main/CHANGELOG.md)
- [Commits](https://github.com/fsprojects/fantomas/compare/v6.3.16...v7.0.0)

---
updated-dependencies:
- dependency-name: fantomas
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Deps

* Format

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Smaug123 <3138005+Smaug123@users.noreply.github.com>
2025-01-14 10:35:58 +00:00
13 changed files with 113 additions and 65 deletions

View File

@@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"fantomas": {
"version": "6.3.16",
"version": "7.0.0",
"commands": [
"fantomas"
]

View File

@@ -254,7 +254,7 @@ jobs:
name: nuget-package-attribute
path: packed
- name: Attest Build Provenance
uses: actions/attest-build-provenance@7668571508540a607bdfd90a87a560489fe372eb # v2.1.0
uses: actions/attest-build-provenance@520d128f165991a6c774bcb264f323e3d70747f4 # v2.2.0
with:
subject-path: "packed/*.nupkg"
@@ -273,7 +273,7 @@ jobs:
name: nuget-package-plugin
path: packed
- name: Attest Build Provenance
uses: actions/attest-build-provenance@7668571508540a607bdfd90a87a560489fe372eb # v2.1.0
uses: actions/attest-build-provenance@520d128f165991a6c774bcb264f323e3d70747f4 # v2.2.0
with:
subject-path: "packed/*.nupkg"

View File

@@ -26769,8 +26769,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"admin/cron/{task}"
.Replace ("{task}", task.ToString () |> System.Uri.EscapeDataString),
"admin/cron/{task}".Replace ("{task}", task.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -26902,8 +26901,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"admin/hooks/{id}"
.Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
"admin/hooks/{id}".Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -26945,8 +26943,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"admin/hooks/{id}"
.Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
"admin/hooks/{id}".Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -27584,8 +27581,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"amdin/hooks/{id}"
.Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
"amdin/hooks/{id}".Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -28008,8 +28004,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"org/{org}/repos"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
"org/{org}/repos".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -28292,8 +28287,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
("orgs/{org}/hooks"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
("orgs/{org}/hooks".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
+ (if "orgs/{org}/hooks".IndexOf (char 63) >= 0 then
"&"
else
@@ -28345,8 +28339,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"orgs/{org}/hooks"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
"orgs/{org}/hooks".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -28538,8 +28531,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
("orgs/{org}/labels"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
("orgs/{org}/labels".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
+ (if "orgs/{org}/labels".IndexOf (char 63) >= 0 then
"&"
else
@@ -28591,8 +28583,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"orgs/{org}/labels"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
"orgs/{org}/labels".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -28784,8 +28775,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
("orgs/{org}/members"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
("orgs/{org}/members".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
+ (if "orgs/{org}/members".IndexOf (char 63) >= 0 then
"&"
else
@@ -29086,8 +29076,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
("orgs/{org}/repos"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
("orgs/{org}/repos".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
+ (if "orgs/{org}/repos".IndexOf (char 63) >= 0 then
"&"
else
@@ -29142,8 +29131,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"orgs/{org}/repos"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
"orgs/{org}/repos".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -29197,8 +29185,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
("orgs/{org}/teams"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
("orgs/{org}/teams".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString)
+ (if "orgs/{org}/teams".IndexOf (char 63) >= 0 then
"&"
else
@@ -29250,8 +29237,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"orgs/{org}/teams"
.Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
"orgs/{org}/teams".Replace ("{org}", org.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -39381,8 +39367,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"repositories/{id}"
.Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
"repositories/{id}".Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)
@@ -39745,8 +39730,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
("teams/{id}/members"
.Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString)
("teams/{id}/members".Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString)
+ (if "teams/{id}/members".IndexOf (char 63) >= 0 then
"&"
else
@@ -39918,8 +39902,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
("teams/{id}/repos"
.Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString)
("teams/{id}/repos".Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString)
+ (if "teams/{id}/repos".IndexOf (char 63) >= 0 then
"&"
else
@@ -40807,8 +40790,7 @@ module Gitea =
System.Uri ("/api/v1/", System.UriKind.Relative)
),
System.Uri (
"user/gpg_keys/{id}"
.Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
"user/gpg_keys/{id}".Replace ("{id}", id.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)

View File

@@ -206,3 +206,34 @@ type internal TypeWithInterfaceMock =
interface System.IDisposable with
member this.Dispose () : unit = this.Dispose ()
namespace SomeNamespace
open System
open WoofWare.Myriad.Plugins
/// Mock record type for an interface
type internal TypeWithPropertiesMock =
{
/// Implementation of IDisposable.Dispose
Dispose : unit -> unit
Prop1 : unit -> int
Prop2 : unit -> unit Async
Mem1 : string option -> string[] Async
}
/// An implementation where every method throws.
static member Empty : TypeWithPropertiesMock =
{
Dispose = (fun () -> ())
Prop1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Prop1"))
Prop2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Prop2"))
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
}
interface TypeWithProperties with
member this.Mem1 arg_0_0 = this.Mem1 (arg_0_0)
member this.Prop1 = this.Prop1 ()
member this.Prop2 = this.Prop2 ()
interface System.IDisposable with
member this.Dispose () : unit = this.Dispose ()

View File

@@ -160,8 +160,7 @@ module PureGymApi =
| null -> System.Uri "https://whatnot.com/"
| v -> v),
System.Uri (
"v1/gyms/{gym}"
.Replace ("{gym}", gym.ToString () |> System.Uri.EscapeDataString),
"v1/gyms/{gym}".Replace ("{gym}", gym.ToString () |> System.Uri.EscapeDataString),
System.UriKind.Relative
)
)

View File

@@ -48,3 +48,10 @@ type TypeWithInterface =
inherit IDisposable
abstract Mem1 : string option -> string[] Async
abstract Mem2 : unit -> string[] Async
[<GenerateMock>]
type TypeWithProperties =
inherit IDisposable
abstract Mem1 : string option -> string[] Async
abstract Prop1 : int
abstract Prop2 : unit Async

View File

@@ -34,3 +34,16 @@ module TestMockGenerator =
mock.Mem1 3 'a' |> shouldEqual "aaa"
mock.Mem2 (3, "hi") 'a' |> shouldEqual "hiahiahi"
mock.Mem3 (3, "hi") 'a' |> shouldEqual "hiahiahi"
[<Test>]
let ``Example of use: properties`` () =
let mock : TypeWithProperties =
{ TypeWithPropertiesMock.Empty with
Mem1 = fun i -> async { return Option.toArray i }
Prop1 = fun () -> 44
}
:> _
mock.Mem1 (Some "hi") |> Async.RunSynchronously |> shouldEqual [| "hi" |]
mock.Prop1 |> shouldEqual 44

View File

@@ -42,7 +42,7 @@
<ItemGroup>
<PackageReference Include="ApiSurface" Version="4.1.16"/>
<PackageReference Include="FsCheck" Version="3.0.0"/>
<PackageReference Include="FsCheck" Version="3.1.0"/>
<PackageReference Include="FsUnit" Version="6.0.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="NUnit" Version="4.3.2"/>

View File

@@ -159,6 +159,15 @@ module internal InterfaceMockGenerator =
|> SynMemberDefn.memberImplementation
)
let properties =
interfaceType.Properties
|> List.map (fun pi ->
SynExpr.createLongIdent' [ Ident.create "this" ; pi.Identifier ]
|> SynExpr.applyTo (SynExpr.CreateConst ())
|> SynBinding.basic [ Ident.create "this" ; pi.Identifier ] []
|> SynMemberDefn.memberImplementation
)
let interfaceName =
let baseName = SynType.createLongIdent interfaceType.Name
@@ -174,7 +183,7 @@ module internal InterfaceMockGenerator =
SynType.app' baseName generics
SynMemberDefn.Interface (interfaceName, Some range0, Some members, range0)
SynMemberDefn.Interface (interfaceName, Some range0, Some (members @ properties), range0)
let access =
match interfaceType.Accessibility, spec.IsInternal with
@@ -248,6 +257,15 @@ module internal InterfaceMockGenerator =
|> SynField.make
|> SynField.withDocString (mem.XmlDoc |> Option.defaultValue PreXmlDoc.Empty)
let constructProperty (prop : PropertyInfo) : SynField =
{
Attrs = []
Ident = Some prop.Identifier
Type = SynType.toFun [ SynType.unit ] prop.Type
}
|> SynField.make
|> SynField.withDocString (prop.XmlDoc |> Option.defaultValue PreXmlDoc.Empty)
let createRecord
(namespaceId : LongIdent)
(opens : SynOpenDeclTarget list)
@@ -255,7 +273,12 @@ module internal InterfaceMockGenerator =
: SynModuleOrNamespace
=
let interfaceType = AstHelper.parseInterface interfaceType
let fields = interfaceType.Members |> List.map constructMember
let fields =
interfaceType.Members
|> List.map constructMember
|> List.append (interfaceType.Properties |> List.map constructProperty)
let docString = PreXmlDoc.create "Mock record type for an interface"
let name =

View File

@@ -351,10 +351,7 @@ module internal JsonParseGenerator =
let getParseOptions (fieldAttrs : SynAttribute list) =
(JsonParseOption.None, fieldAttrs)
||> List.fold (fun options attr ->
if
(SynLongIdent.toString attr.TypeName)
.EndsWith ("JsonNumberHandling", StringComparison.Ordinal)
then
if (SynLongIdent.toString attr.TypeName).EndsWith ("JsonNumberHandling", StringComparison.Ordinal) then
let qualifiedEnumValue =
match SynExpr.stripOptionalParen attr.ArgExpr with
| SynExpr.LongIdent (_, SynLongIdent (ident, _, _), _, _) when isJsonNumberHandling ident ->
@@ -384,15 +381,13 @@ module internal JsonParseGenerator =
let propertyNameAttr =
fieldData.Attrs
|> List.tryFind (fun attr ->
(SynLongIdent.toString attr.TypeName)
.EndsWith ("JsonPropertyName", StringComparison.Ordinal)
(SynLongIdent.toString attr.TypeName).EndsWith ("JsonPropertyName", StringComparison.Ordinal)
)
let extensionDataAttr =
fieldData.Attrs
|> List.tryFind (fun attr ->
(SynLongIdent.toString attr.TypeName)
.EndsWith ("JsonExtensionData", StringComparison.Ordinal)
(SynLongIdent.toString attr.TypeName).EndsWith ("JsonExtensionData", StringComparison.Ordinal)
)
let propertyName =

View File

@@ -180,8 +180,7 @@ module internal JsonSerializeGenerator =
let propertyNameAttr =
attrs
|> List.tryFind (fun attr ->
(SynLongIdent.toString attr.TypeName)
.EndsWith ("JsonPropertyName", StringComparison.Ordinal)
(SynLongIdent.toString attr.TypeName).EndsWith ("JsonPropertyName", StringComparison.Ordinal)
)
match propertyNameAttr with
@@ -198,8 +197,7 @@ module internal JsonSerializeGenerator =
let getIsJsonExtension (attrs : SynAttribute list) : bool =
attrs
|> List.tryFind (fun attr ->
(SynLongIdent.toString attr.TypeName)
.EndsWith ("JsonExtensionData", StringComparison.Ordinal)
(SynLongIdent.toString attr.TypeName).EndsWith ("JsonExtensionData", StringComparison.Ordinal)
)
|> Option.isSome

6
flake.lock generated
View File

@@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1736420959,
"narHash": "sha256-dMGNa5UwdtowEqQac+Dr0d2tFO/60ckVgdhZU9q2E2o=",
"lastModified": 1739019272,
"narHash": "sha256-7Fu7oazPoYCbDzb9k8D/DdbKrC3aU1zlnc39Y8jy/s8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "32af3611f6f05655ca166a0b1f47b57c762b5192",
"rev": "fa35a3c8e17a3de613240fea68f876e5b4896aec",
"type": "github"
},
"original": {

View File

@@ -6,8 +6,8 @@
},
{
"pname": "fantomas",
"version": "6.3.16",
"hash": "sha256-4tRdYf+/Q1iedx+DDuIKVGlIWQdr6erM51VdKzZkhCs="
"version": "7.0.0",
"hash": "sha256-v4bXmvjZOYxl5RSIHuqVfDzBQdRz5SrmzZtD6SeEYTY="
},
{
"pname": "Fantomas.Core",
@@ -21,8 +21,8 @@
},
{
"pname": "FsCheck",
"version": "3.0.0",
"hash": "sha256-/5FqiNeTVFairRtInS0cjQ3uGlqVfVJG2FsKIo8mdZ4="
"version": "3.1.0",
"hash": "sha256-u0Ha94EjClJ8evNSHu8d6+Dx9qYM3kV3sl1PEq9gF8s="
},
{
"pname": "fsharp-analyzers",
@@ -51,8 +51,8 @@
},
{
"pname": "FSharp.Core",
"version": "9.0.100",
"hash": "sha256-V1q3CjbRvWZqxpi6cXD/R0F7pyXGGtH83M5Z/ITDrp8="
"version": "9.0.101",
"hash": "sha256-bR4PHanvKrzD43qFQxmOmmhhpz+ZmKZMPlgGnlRNcp4="
},
{
"pname": "FsUnit",