Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify that there's no unused test data and no tests that didn't produced test data #514

Merged
merged 8 commits into from
Jan 14, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/perform-common-steps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ description: "Performs common steps over the workflows"
runs:
using: "composite"
steps:
- name: ⚙ Setup .NET 7.0 SDK ⚙
- name: ⚙ Setup .NET SDK ⚙
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'

- name: ♻ NuGet Cache ♻
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Building

### Prerequisites

To build Cesium, install [.NET 7 SDK][dotnet.download] or later.
To build Cesium, install [.NET 8 SDK][dotnet.download] or later.

Testing
-------
Expand Down
4 changes: 3 additions & 1 deletion Cesium.CodeGen.Tests/ArchitectureDependentTypeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Cesium.TestFramework;
using JetBrains.Annotations;

namespace Cesium.CodeGen.Tests;
Expand Down Expand Up @@ -52,7 +53,8 @@ typedef struct
} foo;
""");

[Fact(DisplayName = "Struct with a fixed array of a pointer type isn't supported for dynamic architecture")]
[Fact(DisplayName = "Struct with a fixed array of a pointer type isn't supported for dynamic architecture"),
NoVerify]
public void StructWithPointerArrayDynamic() => DoesNotCompile("""
typedef struct
{
Expand Down
4 changes: 2 additions & 2 deletions Cesium.CodeGen.Tests/Cesium.CodeGen.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>

<IsPackable>false</IsPackable>
Expand All @@ -28,7 +28,7 @@
<ProjectReference Include="..\Cesium.Core\Cesium.Core.csproj" />
<ProjectReference Include="..\Cesium.Parser\Cesium.Parser.csproj" />
<ProjectReference Include="..\Cesium.Runtime\Cesium.Runtime.csproj" />
<ProjectReference Include="..\Cesium.Test.Framework\Cesium.Test.Framework.csproj" />
<ProjectReference Include="..\Cesium.TestFramework\Cesium.TestFramework.csproj" />
</ItemGroup>

</Project>
7 changes: 4 additions & 3 deletions Cesium.CodeGen.Tests/CliImportTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Cesium.TestFramework;
using JetBrains.Annotations;

namespace Cesium.CodeGen.Tests;
Expand All @@ -22,21 +23,21 @@ int main()
return console_read();
}");

[Fact]
[Fact, NoVerify]
public void CliImportReturnTypeMismatch() => DoesNotCompile(
@"__cli_import(""System.Console::Read"")
void console_read(void);",
"Returns types do not match"
);

[Fact]
[Fact, NoVerify]
public void CliImportArgumentCountMismatch() => DoesNotCompile(
@"__cli_import(""System.Console::Read"")
int console_read(int a, int b);",
"Cannot find CLI-imported member System.Console::Read(System.Int32, System.Int32)."
);

[Fact]
[Fact, NoVerify]
public void CliImportArgumentTypesMismatch() => DoesNotCompile(
@"__cli_import(""System.Console::SetCursorPosition"")
void console_set_cursor_position(int a, char b);",
Expand Down
3 changes: 2 additions & 1 deletion Cesium.CodeGen.Tests/CodeGenBreakStatementTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cesium.Core;
using Cesium.TestFramework;
using JetBrains.Annotations;

namespace Cesium.CodeGen.Tests;
Expand All @@ -20,7 +21,7 @@ public Task BreakInFor() => DoTest(@"int main()
for(;;) break;
}");

[Fact]
[Fact, NoVerify]
public Task BreakNotInFor() => Assert.ThrowsAsync<CompilationException>(
() => DoTest(@"int main()
{
Expand Down
5 changes: 3 additions & 2 deletions Cesium.CodeGen.Tests/CodeGenContinueStatementTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cesium.Core;
using Cesium.TestFramework;
using JetBrains.Annotations;

namespace Cesium.CodeGen.Tests;
Expand Down Expand Up @@ -42,14 +43,14 @@ public Task ContinueInDoWhile() => DoTest(@"int main()
while (i < 10);
}");

[Fact]
[Fact, NoVerify]
public Task ContinueNotInFor() => Assert.ThrowsAsync<CompilationException>(
() => DoTest(@"int main()
{
continue;
}"));

[Fact]
[Fact, NoVerify]
public void ContinueInSwitch() => DoesNotCompile(@"int main()
{
switch (1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Cesium.TestFramework;
using JetBrains.Annotations;

namespace Cesium.CodeGen.Tests;
Expand All @@ -21,7 +22,7 @@ public Task PostfixIncrementVariable() => DoTest(@"int main()
return x;
}");

[Fact]
[Fact, NoVerify]
public void PostfixIncrementCannotBeConstant() => DoesNotCompile(@"int main()
{
int x;
Expand All @@ -37,15 +38,15 @@ public Task PrefixIncrementVariable() => DoTest(@"int main()
return x;
}");

[Fact]
[Fact, NoVerify]
public void PrefixIncrementCannotBeConstant() => DoesNotCompile(@"int main()
{
int x;
x = ++5;
return x;
}", "'++' needs l-value");

[Fact]
[Fact, NoVerify]
public void PrefixDecrementCannotBeConstant() => DoesNotCompile(@"int main()
{
int x;
Expand Down
31 changes: 16 additions & 15 deletions Cesium.CodeGen.Tests/CodeGenMethodTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cesium.Core;
using Cesium.TestFramework;
using JetBrains.Annotations;

namespace Cesium.CodeGen.Tests;
Expand Down Expand Up @@ -75,9 +76,9 @@ int main()
[Fact] public Task VoidParameterMain() => DoTest("int main(void){}");
[Fact] public Task PointerReceivingFunction() => DoTest("void foo(int *ptr){}");
[Fact] public Task StandardMain() => DoTest("int main(int argc, char *argv[]){}");
[Fact] public void NonstandardMainDoesNotCompile1() => DoesNotCompile("void main(){}", "Invalid return type");
[Fact] public void NonstandardMainDoesNotCompile2() => DoesNotCompile("int main(int c){}", "Invalid parameter");
[Fact]
[Fact, NoVerify] public void NonstandardMainDoesNotCompile1() => DoesNotCompile("void main(){}", "Invalid return type");
[Fact, NoVerify] public void NonstandardMainDoesNotCompile2() => DoesNotCompile("int main(int c){}", "Invalid parameter");
[Fact, NoVerify]
public void VarArgMainDoesNotCompile2() => DoesNotCompile<WipException>(
"int main(int argc, char *argv[], ...){}",
"Variable arguments for the main function aren't supported.");
Expand Down Expand Up @@ -114,24 +115,24 @@ public Task ReturnWithoutArgument() => DoTest(@"void console_read()
return;
}");

[Fact]
[Fact, NoVerify]
public void IncorrectReturnTypeDoesNotCompile() => DoesNotCompile(@"int foo(void);
void foo(void) {}", "Incorrect return type");

[Fact]
[Fact, NoVerify]
public void IncorrectParameterTypeDoesNotCompile() => DoesNotCompile(@"int foo(int bar);
int foo(char *x) {}", "Incorrect type for parameter x");

[Fact]
[Fact, NoVerify]
public void IncorrectParameterCountDoesNotCompile() => DoesNotCompile(@"int foo(int bar, int baz);
int foo(int bar) {}", "Incorrect parameter count");

[Fact]
[Fact, NoVerify]
public void IncorrectOverrideCliImport() => DoesNotCompile(@"__cli_import(""System.Console::Read"")
int console_read(void);
int console_read(void) { return 0; }", "Function console_read already defined as immutable.");

[Fact]
[Fact, NoVerify]
public void DifferentCliImport() => DoesNotCompile(@"__cli_import(""System.Console::Beep"")
void console_beep(void);
__cli_import(""System.Console::Clear"")
Expand Down Expand Up @@ -180,14 +181,14 @@ void console_read()
{
}");

[Fact]
[Fact, NoVerify]
public void ExplicitVarargDeclarationShouldHaveExplicitDefinition() => DoesNotCompile(@"void console_read(int x, ...);

void console_read(int x)
{
}", "Function console_read declared with varargs but defined without varargs.");

[Fact]
[Fact, NoVerify]
public void ExplicitVarargDefinitionShouldHaveExplicitDeclaration() => DoesNotCompile(@"void console_read(int x);

void console_read(int x, ...)
Expand All @@ -208,11 +209,11 @@ public Task CanHaveTwoFunctionDeclarationsWithDifferentParameterNames() => DoTes

int console_read(int __argc) { return 0; }");

[Fact]
[Fact, NoVerify]
public void DoubleDefinition() => DoesNotCompile(@"int console_read() { return 1; }
int console_read() { return 2; }", "Double definition of function console_read.");

[Fact]
[Fact, NoVerify]
public void NoDefinition() => DoesNotCompile(@"int foo(void);
int main() { return foo(); }", "Function foo not defined.");

Expand Down Expand Up @@ -327,7 +328,7 @@ public Task ImplicitReturnAllowedForMain() => DoTest(@"int main()
int unused = 0;
}");

[Fact]
[Fact, NoVerify]
public void ImplicitReturnDisallowedNonMain() => DoesNotCompile(@"int foo()
{
int unused;
Expand Down Expand Up @@ -378,7 +379,7 @@ public void ValidPointerWithIntSubtractionTest() => DoTest(@"int main() {
return 1;
}");

[Fact]
[Fact, NoVerify]
public void PointerSubtractionWithTypeMismatchTest() => DoesNotCompile(@"typedef struct {
int a;
} bar;
Expand Down Expand Up @@ -465,7 +466,7 @@ int main()
return fooptr(123);
}");

[Fact]
[Fact, NoVerify]
public void NonFunctionPointerCallTest() => DoesNotCompile(@"int foo(int a) { return a; }

int main()
Expand Down
4 changes: 2 additions & 2 deletions Cesium.CodeGen.Tests/CodeGenNetInteropTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using Cesium.Compiler;
using Cesium.Test.Framework;
using Cesium.TestFramework;
using Xunit.Abstractions;

namespace Cesium.CodeGen.Tests;
Expand Down Expand Up @@ -40,7 +40,7 @@ private async Task VerifyAssemblyRuns(byte[] assemblyContentToRun, string refere
var runtimeConfigPath = Path.ChangeExtension(assemblyPath, ".runtimeconfig.json");

await File.WriteAllBytesAsync(assemblyPath, assemblyContentToRun);
await File.WriteAllTextAsync(runtimeConfigPath, RuntimeConfig.EmitNet7());
await File.WriteAllTextAsync(runtimeConfigPath, RuntimeConfig.EmitNet8());

DeployReferenceAssembly(CSharpCompilationUtil.CesiumRuntimeLibraryPath);
DeployReferenceAssembly(referencePath);
Expand Down
15 changes: 8 additions & 7 deletions Cesium.CodeGen.Tests/CodeGenPointersTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Cesium.TestFramework;
using JetBrains.Annotations;

namespace Cesium.CodeGen.Tests;
Expand Down Expand Up @@ -43,12 +44,12 @@ private static Task DoTest(string source)
[Fact]
public Task PointerToConstPointer() => DoTest("void foo (int *const *x) { int y = *x[1]; }");

[Fact]
[Fact, NoVerify]
public void CannotMultiplyPointerTypes() => DoesNotCompile(
"void foo (int *x) { x = 1*x; }",
"Operator Multiply is not supported for value/pointer operands");

[Fact]
[Fact, NoVerify]
public void CannotAddPointerTypes() => DoesNotCompile(
"void foo (int *x) { x = x +x; }",
"Operator Add is not supported for pointer/pointer operands");
Expand Down Expand Up @@ -79,31 +80,31 @@ public Task CanUseBuiltinOffsetOfOnDeepMembers() => DoTest(
"typedef struct { int x; } a; typedef struct { a a; } b; int m() { return &__builtin_offsetof_instance((b*)0).a.x; }"
);

[Fact]
[Fact, NoVerify]
public void CannotUseBuiltinOffsetOfOnInvalidMembers() => DoesNotCompile(
"typedef struct { int x; } a; int m() { return &__builtin_offsetof_instance((a*)0).y; }",
"\"a\" has no member named \"y\""
);

[Fact]
[Fact, NoVerify]
public void CannotUseBuiltinOffsetOfOnPlainType() => DoesNotCompile(
"int m() { return &__builtin_offsetof_instance((int*)0).x; }",
"__builtin_offsetof_instance: type \"PrimitiveType { Kind = Int }\" is not a struct type."
);

[Fact]
[Fact, NoVerify]
public void CannotUseBuiltinOffsetOfOnPointerType() => DoesNotCompile(
"typedef struct { int x; } a; int m() { return &__builtin_offsetof_instance((a**)0).x; }",
"__builtin_offsetof_instance: type \"PointerType { Base = Cesium.CodeGen.Ir.Types.StructType, TypeKind = Pointer }\" is not a struct type."
);

[Fact]
[Fact, NoVerify]
public void CannotUseBuiltinOffsetOfOnUndeclaredType() => DoesNotCompile(
"int m() { return &__builtin_offsetof_instance((undeclared*) 0).x; }",
"Cannot resolve type undeclared"
);

[Fact]
[Fact, NoVerify]
public void CannotUseBuiltinOffsetOfOnUndeclaredTag() => DoesNotCompile(
"int m() { return &__builtin_offsetof_instance((struct undeclared*) 0).x; }",
"__builtin_offsetof_instance: struct type \"undeclared\" has no members - is it declared?"
Expand Down
3 changes: 2 additions & 1 deletion Cesium.CodeGen.Tests/CodeGenSwitchTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Cesium.TestFramework;
using JetBrains.Annotations;

namespace Cesium.CodeGen.Tests;
Expand Down Expand Up @@ -37,7 +38,7 @@ public Task ConstEval() => DoTest(@"int main()
return 1;
}");

[Fact]
[Fact, NoVerify]
public void NonConstEval() => DoesNotCompile(@"int main()
{
int x = 0;
Expand Down
2 changes: 1 addition & 1 deletion Cesium.CodeGen.Tests/CodeGenTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Cesium.CodeGen.Contexts;
using Cesium.Core;
using Cesium.Parser;
using Cesium.Test.Framework;
using Cesium.TestFramework;
using JetBrains.Annotations;
using Mono.Cecil;
using Mono.Cecil.Cil;
Expand Down
Loading
Loading