Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2aef4de

Browse files
authoredDec 12, 2024
Merge branch 'nsubstitute:main' into partial_call_forwarding
2 parents 0cd7450 + dfef728 commit 2aef4de

22 files changed

+171
-195
lines changed
 

‎.github/workflows/release_build.yml renamed to ‎.github/workflows/release_documentation.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,27 @@
1-
name: Build release packages and documentation
1+
name: Release documentation
22
on:
33
workflow_dispatch:
4-
push:
5-
tags:
6-
- 'v*'
7-
8-
env:
9-
CONFIGURATION: Release
104

115
jobs:
126
build:
137
runs-on: windows-latest
148
steps:
159
- name: Checkout
1610
uses: actions/checkout@v4
17-
with:
18-
fetch-depth: 0
1911

2012
- name: Setup .NET
2113
uses: actions/setup-dotnet@v4
2214
with:
23-
dotnet-version: |
24-
6.0.x
25-
7.0.x
26-
8.0.x
15+
dotnet-version: 9.0.x
2716

2817
- name: Setup Ruby for documentation build
2918
uses: ruby/setup-ruby@v1
3019
with:
3120
ruby-version: '3.2'
3221
bundler-cache: true
3322

34-
- name: Build package and docs
35-
run: dotnet run --project 'build/build.fsproj' -- -t All
36-
37-
- name: Upload packages
38-
uses: actions/upload-artifact@v4
39-
with:
40-
name: packages
41-
path: |
42-
bin/Release/NSubstitute/*.nupkg
43-
bin/Release/NSubstitute/*.snupkg
44-
retention-days: 7
23+
- name: Build documentation
24+
run: dotnet run --project 'build/build.fsproj' -- -t Documentation
4525

4626
- name: Upload documentation
4727
uses: actions/upload-artifact@v4
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release packages
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
build:
7+
runs-on: windows-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
12+
- name: Setup .NET
13+
uses: actions/setup-dotnet@v4
14+
with:
15+
dotnet-version: 9.0.x
16+
17+
- name: Build package
18+
run: dotnet pack src/NSubstitute/NSubstitute.csproj -p:CI=true
19+
20+
- name: Upload packages
21+
uses: actions/upload-artifact@v4
22+
with:
23+
name: packages
24+
path: |
25+
bin/Release/NSubstitute/*.nupkg
26+
bin/Release/NSubstitute/*.snupkg
27+
retention-days: 7

‎.github/workflows/build_and_test.yml renamed to ‎.github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build, Test, and Format
1+
name: Build, Test, and Format verification
22
on:
33
push:
44
branches:
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: [windows-latest, ubuntu-latest, macOS-latest]
13-
framework: [net8.0]
13+
framework: [net9.0, net8.0]
1414
include:
1515
- os: windows-latest
1616
framework: net462
@@ -24,6 +24,7 @@ jobs:
2424
uses: actions/setup-dotnet@v4
2525
with:
2626
dotnet-version: |
27+
9.0.x
2728
8.0.x
2829
2930
- name: Build
@@ -37,13 +38,12 @@ jobs:
3738
steps:
3839
- name: Checkout
3940
uses: actions/checkout@v4
40-
with:
41-
fetch-depth: 0
4241

4342
- name: Setup .NET
4443
uses: actions/setup-dotnet@v4
4544
with:
4645
dotnet-version: |
46+
9.0.x
4747
8.0.x
4848
4949
# used for documentation
@@ -53,8 +53,8 @@ jobs:
5353
ruby-version: '3.2'
5454
bundler-cache: true
5555

56-
- name: Build all targets
57-
run: build\build.cmd --target All
56+
- name: Build documentation
57+
run: build\build.cmd --target Documentation
5858

5959
format-verify:
6060
runs-on: ubuntu-latest
@@ -65,7 +65,7 @@ jobs:
6565
- name: Setup .NET
6666
uses: actions/setup-dotnet@v4
6767
with:
68-
dotnet-version: 8.0.x
68+
dotnet-version: 9.0.x
6969

7070
- name: Format
7171
run: dotnet format --verify-no-changes

‎CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* [UPDATE] Update github actions steps versions
66
* [UPDATE] Remove legacy obsolete API
77
* [UPDATE] Mark as obsolete api CompatArg with pre c# 7.0 support
8-
8+
* [NEW] Added .NET 9 to test matrix
99

1010
### 5.3.0 (October 2024)
1111

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Perfect for those new to testing, and for others who would just like to to get t
2222

2323
### Getting help
2424

25-
If you have questions, feature requests or feedback on NSubstitute please [raise an issue](https://github.com/nsubstitute/NSubstitute/issues) on our project site. All questions are welcome via our project site, but for "how-to"-style questions you can also try [StackOverflow with the \[nsubstitute\] tag](https://stackoverflow.com/tags/nsubstitute), which often leads to very good answers from the larger programming community. StackOverflow is especially useful if your question also relates to other libraries that our team may not be as familiar with (e.g. NSubstitute with Entity Framework). You can also head on over to the [NSubstitute discussion group](https://groups.google.com/group/nsubstitute) if you prefer.
25+
If you have questions, feature requests or feedback on NSubstitute please [raise an issue](https://github.com/nsubstitute/NSubstitute/issues) on our project site. All questions are welcome via our project site, but for "how-to"-style questions you can also try [StackOverflow with the \[nsubstitute\] tag](https://stackoverflow.com/tags/nsubstitute), which often leads to very good answers from the larger programming community. StackOverflow is especially useful if your question also relates to other libraries that our team may not be as familiar with (e.g. NSubstitute with Entity Framework).
2626

2727
### Basic use
2828

‎build/ExtractDocs.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module ExtractDocs
22

33
open System
4-
open System.IO
54
open System.Text.RegularExpressions
65

76
let LiquidTagRegex = @"```(?<tag>\w+)" + // Tag start with argument. e.g. "```csharp"

‎build/build.fs

Lines changed: 7 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
open System
22
open System.Diagnostics
33
open System.IO
4-
open System.Text.RegularExpressions
54

65
open Fake.Core
76
open Fake.Core.TargetOperators
87
open Fake.DotNet
98
open Fake.IO
109
open Fake.IO.Globbing.Operators
1110
open Fake.IO.FileSystemOperators
12-
open Fake.Tools
1311

1412
open ExtractDocs
1513

@@ -18,7 +16,7 @@ let description = Target.description
1816

1917
module FileReaderWriter =
2018
let Read file = File.ReadAllText(file)
21-
let Write file text = File.WriteAllText(file, text)
19+
let Write file (text: string) = File.WriteAllText(file, text)
2220
let TransformFile file target (f : string -> string) =
2321
Read file
2422
|> f
@@ -42,111 +40,15 @@ module ExamplesToCode =
4240
ConvertFile file targetDir
4341

4442
type BuildVersion = { assembly: string; file: string; info: string; package: string }
45-
let getVersion () =
46-
// The --first-parent flag is needed to make our walk linear from current commit and top.
47-
// This way also merge commit is counted as "1".
48-
let desc = Git.CommandHelper.runSimpleGitCommand "" "describe --tags --long --abbrev=40 --first-parent --match=v*"
49-
let result = Regex.Match(desc,
50-
@"^v(?<maj>\d+)\.(?<min>\d+)\.(?<rev>\d+)(?<pre>-\w+\d*)?-(?<num>\d+)-g(?<sha>[a-z0-9]+)$",
51-
RegexOptions.IgnoreCase)
52-
.Groups
53-
let getMatch (name:string) = result.[name].Value
54-
55-
let (major, minor, revision, preReleaseSuffix, commitsNum, commitSha) =
56-
(getMatch "maj" |> int, getMatch "min" |> int, getMatch "rev" |> int, getMatch "pre", getMatch "num" |> int, getMatch "sha")
57-
58-
// Assembly version should contain major and minor only, as no breaking changes are expected in bug fix releases.
59-
let assemblyVersion = sprintf "%d.%d.0.0" major minor
60-
let fileVersion = sprintf "%d.%d.%d.%d" major minor revision commitsNum
61-
62-
// If number of commits since last tag is greater than zero, we append another identifier with number of commits.
63-
// The produced version is larger than the last tag version.
64-
// If we are on a tag, we use version without modification.
65-
// Examples of output: 3.50.2.1, 3.50.2.215, 3.50.1-rc1.3, 3.50.1-rc3.35
66-
let packageVersion = match commitsNum with
67-
| 0 -> sprintf "%d.%d.%d%s" major minor revision preReleaseSuffix
68-
| _ -> sprintf "%d.%d.%d%s.%d" major minor revision preReleaseSuffix commitsNum
69-
70-
let infoVersion = match commitsNum with
71-
| 0 -> packageVersion
72-
| _ -> sprintf "%s-%s" packageVersion commitSha
73-
74-
{ assembly = assemblyVersion; file = fileVersion; info = infoVersion; package = packageVersion }
75-
43+
7644
let root = __SOURCE_DIRECTORY__ </> ".." |> Path.getFullName
7745

7846
let configuration = Environment.environVarOrDefault "configuration" "Debug"
79-
let version = getVersion ()
80-
81-
let additionalArgs = [
82-
"AssemblyVersion", version.assembly
83-
"FileVersion", version.file
84-
"InformationalVersion", version.info
85-
"PackageVersion", version.package
86-
]
8747

8848
let output = root </> "bin" </> configuration
8949
let solution = (root </> "NSubstitute.sln")
9050

9151
let initTargets() =
92-
Target.create "Default" ignore
93-
Target.create "All" ignore
94-
95-
Target.description("Clean compilation artifacts and remove output bin directory")
96-
Target.create "Clean" (fun _ ->
97-
DotNet.exec (fun p -> { p with WorkingDirectory = root }) "clean"
98-
(sprintf "--configuration %s --verbosity minimal" configuration)
99-
|> ignore
100-
Shell.cleanDirs [ output ]
101-
)
102-
103-
Target.description("Restore dependencies")
104-
Target.create "Restore" (fun _ ->
105-
DotNet.restore (fun p -> p) solution
106-
)
107-
108-
Target.description("Compile all projects")
109-
Target.create "Build" (fun _ ->
110-
DotNet.build (fun p ->
111-
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
112-
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
113-
}) solution
114-
)
115-
116-
Target.description("Run tests")
117-
Target.create "Test" (fun _ ->
118-
DotNet.test (fun p ->
119-
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
120-
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
121-
}) (root </> "tests/NSubstitute.Acceptance.Specs/NSubstitute.Acceptance.Specs.csproj")
122-
)
123-
124-
Target.description("Generate Nuget package")
125-
Target.create "Package" (fun _ ->
126-
DotNet.pack (fun p ->
127-
{ p with Configuration = DotNet.BuildConfiguration.fromString configuration
128-
MSBuildParams = { p.MSBuildParams with Properties = additionalArgs }
129-
}) (root </> "src/NSubstitute/NSubstitute.csproj")
130-
)
131-
132-
Target.description("Run all benchmarks. Must be run with configuration=Release.")
133-
Target.create "Benchmarks" (fun _ ->
134-
if configuration <> "Release" then
135-
failwith "Benchmarks can only be run in Release mode. Please re-run the build in Release configuration."
136-
137-
let benchmarkCsproj = root </> "tests/NSubstitute.Benchmarks/NSubstitute.Benchmarks.csproj" |> Path.getFullName
138-
let benchmarkToRun = Environment.environVarOrDefault "benchmark" "*" // Defaults to "*" (all)
139-
[ "netcoreapp2.1" ]
140-
|> List.iter (fun framework ->
141-
Trace.traceImportant ("Benchmarking " + framework)
142-
let work = output </> "benchmark-" + framework
143-
Directory.ensure work
144-
DotNet.exec (fun p -> { p with WorkingDirectory = work }) "run"
145-
("--framework " + framework + " --project " + benchmarkCsproj + " -- " + benchmarkToRun)
146-
|> ignore
147-
)
148-
)
149-
15052
Target.description("Extract, build and test code from documentation.")
15153
Target.create "TestCodeFromDocs" <| fun _ ->
15254
let outputCodePath = output </> "CodeFromDocs"
@@ -157,13 +59,13 @@ let initTargets() =
15759
let csproj = """
15860
<Project Sdk="Microsoft.NET.Sdk">
15961
<PropertyGroup>
160-
<TargetFrameworks>net6.0;net462</TargetFrameworks>
62+
<TargetFrameworks>net8.0;net462</TargetFrameworks>
16163
<LangVersion>latest</LangVersion>
16264
</PropertyGroup>
16365
<ItemGroup>
164-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
66+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
16567
<PackageReference Include="NUnit" Version="3.14.0" />
166-
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
68+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
16769
</ItemGroup>
16870
<ItemGroup>
16971
<ProjectReference Include="..\..\..\src\NSubstitute\NSubstitute.csproj" />
@@ -219,23 +121,7 @@ let initTargets() =
219121
printfn ""
220122
Target.listAvailable()
221123

222-
"Clean" ?=> "Build" |> ignore
223-
"Clean" ?=> "Test" |> ignore
224-
"Clean" ?=> "Restore" |> ignore
225-
"Clean" ?=> "Documentation" |> ignore
226-
"Clean" ?=> "TestCodeFromDocs" |> ignore
227-
"Clean" ?=> "Package" |> ignore
228-
"Clean" ?=> "Default" |> ignore
229-
230-
"Build" <== [ "Restore" ]
231-
"Test" <== [ "Build" ]
232124
"Documentation" <== [ "TestCodeFromDocs" ]
233-
"Benchmarks" <== [ "Build" ]
234-
// For packaging, use a clean build and make sure all tests (inc. docs) pass.
235-
"Package" <== [ "Clean"; "Build"; "Test"; "TestCodeFromDocs" ]
236-
237-
"Default" <== [ "Restore"; "Build"; "Test" ]
238-
"All" <== [ "Clean"; "Default"; "Documentation"; "Package" ]
239125

240126
[<EntryPoint>]
241127
let main argv =
@@ -245,5 +131,5 @@ let main argv =
245131
|> Context.RuntimeContext.Fake
246132
|> Context.setExecutionContext
247133
initTargets()
248-
Target.runOrDefaultWithArguments "Default"
249-
0
134+
Target.runOrDefaultWithArguments "TestCodeFromDocs"
135+
0

‎build/build.fsproj

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<OutputPath>buildOutput</OutputPath>
77
</PropertyGroup>
@@ -14,12 +14,11 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.Build" Version="17.9.5" />
18-
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.9.5" />
19-
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.235" />
20-
<PackageReference Include="Fake.DotNet.Cli" Version="6.0.0" />
21-
<PackageReference Include="Fake.Tools.Git" Version="6.0.0" />
22-
<PackageReference Include="Fake.Core.Target" Version="6.0.0" />
17+
<PackageReference Include="Microsoft.Build" Version="17.12.6" />
18+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.12.6" />
19+
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.386" />
20+
<PackageReference Include="Fake.DotNet.Cli" Version="6.1.3" />
21+
<PackageReference Include="Fake.Core.Target" Version="6.1.3" />
2322
</ItemGroup>
2423

2524
</Project>

‎docs/help.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
<p>For more in depth information start with <a href="/help/creating-a-substitute">Creating a substitute</a>.</p>
1010

11-
<p>If you can't find the answer you're looking for, or if you have feature requests or feedback on NSubstitute, please <a href="{{ site.repo }}/issues">raise an issue</a> on our project site. All questions are welcome via our project site, but for "how-to"-style questions you can also try <a href="https://stackoverflow.com/tags/nsubstitute">StackOverflow with the [nsubstitute] tag</a>, which often leads to very good answers from the larger programming community. StackOverflow is especially useful if your question also relates to other libraries that our team may not be as familiar with (e.g. NSubstitute with Entity Framework). You can also head on over to the <a href="https://groups.google.com/group/nsubstitute">NSubstitute discussion group</a> if you prefer.</p>
11+
<p>If you can't find the answer you're looking for, or if you have feature requests or feedback on NSubstitute, please <a href="{{ site.repo }}/issues">raise an issue</a> on our project site. All questions are welcome via our project site, but for "how-to"-style questions you can also try <a href="https://stackoverflow.com/tags/nsubstitute">StackOverflow with the [nsubstitute] tag</a>, which often leads to very good answers from the larger programming community. StackOverflow is especially useful if your question also relates to other libraries that our team may not be as familiar with (e.g. NSubstitute with Entity Framework).</p>

‎docs/help/_posts/2013-03-01-return-for-all.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ We can return a specific value for all calls to a substitute using `sub.ReturnsF
77

88
**Note: we need `using NSubstitute.Extensions` to import the `.ReturnsForAll<T>()` extension method.**
99

10-
The type must match exactly: `.ReturnsForAll<Cat>(cat)` will not set a return value for a call that returns `Animal`, even if `Cat` inherits from `Animal`. To return for the super-type, use `.ReturnsForAll<Animal>(cat)`. (If you'd like a change in this behaviour, please [let us know](https://groups.google.com/forum/#!forum/nsubstitute)).
10+
The type must match exactly: `.ReturnsForAll<Cat>(cat)` will not set a return value for a call that returns `Animal`, even if `Cat` inherits from `Animal`. To return for the super-type, use `.ReturnsForAll<Animal>(cat)`. (If you'd like a change in this behaviour, please [let us know](https://github.com/nsubstitute/NSubstitute/issues)).
1111

1212
There is also an overload that takes a `Func<CallInfo,T>` so the value to return will be calculated each time.
1313

0 commit comments

Comments
 (0)
Please sign in to comment.