Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .agents/plugins/marketplace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "cscheck",
"interface": {
"displayName": "CsCheck"
},
"plugins": [
{
"name": "cscheck",
"source": "./plugins/cscheck",
"description": "Find what a C# project's tests miss, and write CsCheck tests that find bugs.",
"policy": {
"installation": "AVAILABLE",
"authentication": "ON_INSTALL"
},
"category": "Developer Tools"
}
]
}
16 changes: 16 additions & 0 deletions .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "cscheck",
"owner": {
"name": "Anthony Lloyd"
},
"metadata": {
"description": "Agent skills for CsCheck, the C# random testing library."
},
"plugins": [
{
"name": "cscheck",
"source": "./plugins/cscheck",
"description": "Find what a C# project's tests miss, and write CsCheck tests that find bugs."
}
]
}
45 changes: 45 additions & 0 deletions .github/skills-check.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Checks that the finding-test-gaps scripts work on this OS, on CsCheck's PCG and its round-trip tests: coverage from the TUnit test app,
# uncovered.cs and candidates.cs on it, and mutants.cs on the candidates in the members those tests pin, with the survivors rerun against
# the SeedString tests, which kill some of them. Run it from the repo root.
# The filters leave out PCGTests' timing tests, which four copies run at once would make flaky.
param([string]$Framework = 'net10.0')
$ErrorActionPreference = 'Stop'
$scripts = 'plugins/cscheck/skills/finding-test-gaps/scripts'
$filter = '/*/*/PCGTests/*Round*'
$rerunFilter = '/*/*/PCGTests/SeedString*'
$members = 'PCG.ToString,Index,SeedString.Parse'
$out = Join-Path ($env:RUNNER_TEMP ?? [IO.Path]::GetTempPath()) 'skills-check'
if (Test-Path -LiteralPath $out) { Remove-Item -LiteralPath $out -Recurse -Force }
New-Item -ItemType Directory -Path $out | Out-Null

function Invoke-Native([string]$Name, [scriptblock]$Command) {
Write-Host "--- $Name"
$text = (& $Command 2>&1 | ForEach-Object { Write-Host $_; "$_" }) -join "`n"
$code = $LASTEXITCODE
if ($code -ne 0) { throw "$Name exited with $code" }
$text
}
function Assert-That([bool]$Ok, [string]$What) { if (-not $Ok) { throw "check failed: $What" } }

Invoke-Native 'coverage of the round-trip tests' { dotnet run -c Release --project Tests -f $Framework -- --coverage --coverage-output-format cobertura --results-directory "$out/coverage-1" --treenode-filter $filter } | Out-Null

$uncovered = Invoke-Native 'uncovered.cs' { dotnet run --file "$scripts/uncovered.cs" -- "$out/coverage-1" PCG.cs --sweep "$out/sweep.md" }
Assert-That ($uncovered -match 'PCG\.cs: \d+ of \d+ lines run') 'uncovered.cs found PCG.cs in the coverage'
Assert-That (Test-Path -LiteralPath "$out/sweep.md") 'uncovered.cs --sweep wrote the table'

$listing = Invoke-Native 'candidates.cs' { dotnet run --file "$scripts/candidates.cs" -- CsCheck/PCG.cs --members $members --coverage "$out/coverage-1" --out "$out/pcg.candidates.json" }
Assert-That ($listing -notmatch "isn't in the coverage") 'candidates.cs matched PCG.cs in the coverage'
$ids = @([regex]::Matches($listing, '(?m)^ (\S+) +\d+ ') | ForEach-Object { $_.Groups[1].Value })
Assert-That ($ids.Count -ge 4) "candidates.cs lists at least 4 candidates in $members, not $($ids.Count)"

$spec = [ordered]@{ testProject = 'Tests'; framework = $Framework; filter = $filter; rerunFilter = $rerunFilter; candidates = 'pcg.candidates.json'; mutants = @($ids | ForEach-Object { @{ id = $_ } }) }
$spec | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath "$out/pcg.json"
Invoke-Native 'mutants.cs' { dotnet run --file "$scripts/mutants.cs" -- "$out/pcg.json" } | Out-Null
$results = @(Get-Content -LiteralPath "$out/pcg-run/results.json" -Raw | ConvertFrom-Json)
Assert-That ($results.Count -eq $ids.Count) "a result for each of the $($ids.Count) mutants, not $($results.Count)"
$errors = @($results | Where-Object status -eq 'ERROR')
Assert-That ($errors.Count -eq 0) "no mutant ends in ERROR, but $($errors.id -join ', ') did"
Assert-That (@($results | Where-Object status -in 'KILLED', 'CRASHED').Count -gt 0) 'at least one mutant is killed'
Assert-That (@($results | Where-Object detail -like '*outside the filter').Count -gt 0) 'the rerun catches at least one survivor, outside the filter'
Assert-That (@($results | Where-Object status -eq 'SURVIVED').Count -gt 0) 'at least one mutant survives'
Write-Host "--- passed: $(($results | Group-Object status | ForEach-Object { "$($_.Count) $($_.Name)" }) -join ', ')"
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
10.0.x
11.0.x
- name: Test
run: dotnet run -c Release --project Tests --framework ${{ matrix.framework }} --output Detailed --no-progress
run: dotnet run -c Release --project Tests --framework ${{ matrix.framework }} --output Detailed

aot:
runs-on: ubuntu-latest
Expand All @@ -55,4 +55,4 @@ jobs:
- name: Publish
run: dotnet publish Tests -c Release -f ${{ matrix.framework }} --use-current-runtime -p:PublishAot=true -o aot
- name: Test
run: ./aot/Tests --output Detailed --no-progress
run: ./aot/Tests --output Detailed
55 changes: 55 additions & 0 deletions .github/workflows/skills.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Skills

on:
push:
branches:
- master
paths:
- 'plugins/cscheck/skills/finding-test-gaps/scripts/**'
- '.github/skills-check.ps1'
- '.github/workflows/skills.yml'
- 'CsCheck/PCG.cs'
- 'CsCheck/CsCheck.csproj'
- 'Tests/PCGTests.cs'
- 'Tests/Tests.csproj'
- 'global.json'
pull_request:
branches:
- master
paths:
- 'plugins/cscheck/skills/finding-test-gaps/scripts/**'
- '.github/skills-check.ps1'
- '.github/workflows/skills.yml'
- 'CsCheck/PCG.cs'
- 'CsCheck/CsCheck.csproj'
- 'Tests/PCGTests.cs'
- 'Tests/Tests.csproj'
- 'global.json'
workflow_dispatch:

permissions:
contents: read

jobs:
check:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
TUNIT_DISABLE_LOGO: true
TUNIT_DISABLE_HTML_REPORTER: true
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macOS-latest]
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.0.x
11.0.x
- name: Check the finding-test-gaps scripts
shell: pwsh
run: ./.github/skills-check.ps1
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ this repo, not a CsCheck requirement.
dotnet build CsCheck/CsCheck.csproj -c Release

# Run the full test suite (this is the CI command)
dotnet run -c Release --project Tests --output Detailed --disable-logo --no-progress
dotnet run -c Release --project Tests --output Detailed --disable-logo

# Run a subset by test tree filter
dotnet run -c Release --project Tests --no-restore --disable-logo --output Detailed --treenode-filter /*/*/GenTests/*
Expand Down
25 changes: 25 additions & 0 deletions CsCheck.slnx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Solution>
<Folder Name="/Solution/">
<File Path=".github/workflows/main.yml" />
<File Path=".github/workflows/skills.yml" />
<File Path="AGENTS.md" />
<File Path="docs/Comparison.md" />
<File Path="docs/GettingStarted.md" />
Expand All @@ -9,6 +10,30 @@
<File Path="docs/Why.md" />
<File Path="README.md" />
</Folder>
<Folder Name="/Skills/">
<File Path="plugins/cscheck/README.md" />
<File Path="plugins/cscheck/plugin.json" />
<File Path="plugins/cscheck/.claude-plugin/plugin.json" />
<File Path="plugins/cscheck/.codex-plugin/plugin.json" />
</Folder>
<Folder Name="/Skills/closing-test-gaps/">
<File Path="plugins/cscheck/skills/closing-test-gaps/SKILL.md" />
</Folder>
<Folder Name="/Skills/finding-test-gaps/">
<File Path="plugins/cscheck/skills/finding-test-gaps/SKILL.md" />
<File Path="plugins/cscheck/skills/finding-test-gaps/references/coverage.md" />
<File Path="plugins/cscheck/skills/finding-test-gaps/references/mutants.md" />
<File Path="plugins/cscheck/skills/finding-test-gaps/scripts/candidates.cs" />
<File Path="plugins/cscheck/skills/finding-test-gaps/scripts/mutants.cs" />
<File Path="plugins/cscheck/skills/finding-test-gaps/scripts/uncovered.cs" />
</Folder>
<Folder Name="/Skills/writing-cscheck-tests/">
<File Path="plugins/cscheck/skills/writing-cscheck-tests/SKILL.md" />
<File Path="plugins/cscheck/skills/writing-cscheck-tests/references/performance.md" />
<File Path="plugins/cscheck/skills/writing-cscheck-tests/references/regression.md" />
<File Path="plugins/cscheck/skills/writing-cscheck-tests/references/spec.md" />
<File Path="plugins/cscheck/skills/writing-cscheck-tests/references/stateful.md" />
</Folder>
<Project Path="CsCheck/CsCheck.csproj" />
<Project Path="Tests/Tests.csproj" />
</Solution>
2 changes: 1 addition & 1 deletion CsCheck/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3392,7 +3392,7 @@ public static void Equality<T>(this Gen<T> gen, Func<EqualityFields<T>, Equality
{
if (iter == -1) iter = Iter;
if (time == -1) time = Time;
if (time > 1) time /= 3;
if (time > 0) time = Math.Max(1, time / 3);

gen.Clone().Sample((t1, t2) =>
t1!.Equals(t2) && t2!.Equals(t1) && Equals(t1, t2) && t1.GetHashCode() == t2.GetHashCode()
Expand Down
8 changes: 4 additions & 4 deletions CsCheck/CsCheck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ CsCheck also makes specification, performance and regression testing simple and
<PackageProjectUrl>https://github.com/AnthonyLloyd/CsCheck</PackageProjectUrl>
<PackageIcon>CsCheck.png</PackageIcon>
<PackageTags>quickcheck;random;model-based;metamorphic;specification;model-checking;temporal;parallel;performance;causal-profiling;regression;testing</PackageTags>
<Version>5.0.1</Version>
<Version>5.0.2</Version>
<PackageReleaseNotes>
Fixed type initializers for WebAssembly.
Improved Spec.ConformExhaustive now fully parallel.
Fixed Check.Equal to compare FrozenSet, FrozenDictionary and subclasses of the known set and dictionary types as unordered collections.
Fixed Check.Equality to still run when time is set below three.
</PackageReleaseNotes>
<TargetFrameworks>net10.0;net11.0</TargetFrameworks>
<LangVersion>15</LangVersion>
Expand All @@ -46,7 +46,7 @@ Improved Spec.ConformExhaustive now fully parallel.
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisMode>All</AnalysisMode>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>5.0.0</PackageValidationBaselineVersion>
<PackageValidationBaselineVersion>5.0.1</PackageValidationBaselineVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="3.0.341" PrivateAssets="All" />
Expand Down
6 changes: 4 additions & 2 deletions CsCheck/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@ static bool RemoveEqual(List<object> items, object x)

private static bool IsUnorderedCollection(Type type)
{
if (type.IsGenericType)
// A FrozenSet is always an internal subclass, so the base types count too.
for (var t = type; t is not null; t = t.BaseType)
{
var genericType = type.GetGenericTypeDefinition();
if (!t.IsGenericType) continue;
var genericType = t.GetGenericTypeDefinition();
if (genericType == typeof(Dictionary<,>)
|| genericType == typeof(HashSet<>)
|| genericType == typeof(ConcurrentDictionary<,>)
Expand Down
23 changes: 23 additions & 0 deletions Tests/CheckTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace Tests;

using System;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -256,6 +257,16 @@ public async Task Equal_ReadOnlySet_Is_Unordered()
await Assert.That(Check.Equal(new ReadOnlySet<int>(new HashSet<int> { 1, 2 }), new ReadOnlySet<int>(new HashSet<int> { 2, 1 }))).IsTrue();
}

[Test]
public async Task Equal_FrozenSet_Is_Unordered()
{
// A FrozenSet's runtime type depends on its contents: generic for these 5 ints, and not generic for 11 or more.
var small = new[] { 1, 2, 3, 4, 5 }.ToFrozenSet();
var large = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }.ToFrozenSet();
await Assert.That(Check.Equal<IEnumerable<int>>(small, small.Reverse().ToArray())).IsTrue();
await Assert.That(Check.Equal<IEnumerable<int>>(large, large.Reverse().ToArray())).IsTrue();
}

[Test]
public async Task Equal_List_Of_Strings()
{
Expand Down Expand Up @@ -1022,6 +1033,18 @@ public void Equality_Fields_Detects_Non_Varying_Gen()
.Compared((a, v) => a with { Id = v }, Gen.Const(0))));
}

sealed record NeverEqual(int Value)
{
public bool Equals(NeverEqual? other) => false;
public override int GetHashCode() => 0;
}

[Test]
public void Equality_Time_Below_Three_Still_Runs()
{
Assert.Throws<CsCheckException>(() => Gen.Int.Select(i => new NeverEqual(i)).Equality(time: 2, threads: 1));
}

[Test]
public void Equality_Fields_Mutable()
{
Expand Down
12 changes: 12 additions & 0 deletions plugins/cscheck/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "cscheck",
"version": "0.1.0",
"description": "Find what a C# project's tests miss, and write tests that find bugs.",
"author": {
"name": "Anthony Lloyd"
},
"homepage": "https://github.com/AnthonyLloyd/CsCheck",
"repository": "https://github.com/AnthonyLloyd/CsCheck",
"license": "Apache-2.0",
"keywords": ["csharp", "dotnet", "testing", "property-based-testing", "mutation-testing", "cscheck"]
}
6 changes: 6 additions & 0 deletions plugins/cscheck/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "cscheck",
"version": "0.1.0",
"description": "Find what a C# project's tests miss, and write tests that find bugs.",
"skills": ["./skills/"]
}
Loading
Loading