Skip to content

Commit

Permalink
Test refactoring, utilities (#459)
Browse files Browse the repository at this point in the history
* Factored out BCL refs

* Update TestUtilities.cs

* BCL and compiling code tests mostly rewritten with utils

* E2e almost done

* Scripting fixed

* Update CodeCompletionTests.cs

* Factored out and simplified completion and signature service tests

* Update FlowAnalysisTests.cs

* Update LocalFunctionsTests.cs

* Update OverloadingTests.cs

* More work

* Update TypeCheckingTests.cs

* Update SyntaxHighlighterTests.cs

* More

* Compiles

* Update TestUtilities.cs

* Update TestUtilities.cs

* Update TestUtilities.cs

* All fixed

* Final fix

* Compiles again

* Smartened up completion

* Update DracoLanguageServer.cs

* Cleanup

* Fix
  • Loading branch information
LPeter1997 authored Aug 31, 2024
1 parent e63ad2f commit 24b9b33
Show file tree
Hide file tree
Showing 32 changed files with 1,373 additions and 1,643 deletions.
227 changes: 105 additions & 122 deletions src/Draco.Compiler.Tests/EndToEnd/BclUsageTests.cs

Large diffs are not rendered by default.

405 changes: 241 additions & 164 deletions src/Draco.Compiler.Tests/EndToEnd/CompilingCodeTests.cs

Large diffs are not rendered by default.

114 changes: 0 additions & 114 deletions src/Draco.Compiler.Tests/EndToEnd/EndToEndTestsBase.cs

This file was deleted.

15 changes: 4 additions & 11 deletions src/Draco.Compiler.Tests/EndToEnd/Issue139Tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Collections.Immutable;
using Draco.Compiler.Api;
using Draco.Compiler.Api.Syntax;
using Draco.Compiler.Internal.Declarations;
using static Draco.Compiler.Tests.TestUtilities;

namespace Draco.Compiler.Tests.EndToEnd;

Expand Down Expand Up @@ -201,14 +199,9 @@ func foo(): ImmutableArray { }
[Theory]
public void DoesNotCrash(string source)
{
var syntaxTree = SyntaxTree.Parse(source);
var compilation = Compilation.Create(
syntaxTrees: [syntaxTree],
metadataReferences: Basic.Reference.Assemblies.Net80.ReferenceInfos.All
.Select(r => MetadataReference.FromPeStream(new MemoryStream(r.ImageBytes)))
.ToImmutableArray());
_ = compilation.Diagnostics.ToList();
compilation.Emit(peStream: new MemoryStream());
var peStream = new MemoryStream();
var compilation = CreateCompilation(source);
_ = compilation.Emit(peStream);
}

[Fact]
Expand Down
7 changes: 4 additions & 3 deletions src/Draco.Compiler.Tests/EndToEnd/MetadataTests.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using static Draco.Compiler.Tests.TestUtilities;

namespace Draco.Compiler.Tests.EndToEnd;

public sealed class MetadataTests : EndToEndTestsBase
public sealed class MetadataTests
{
[Fact]
public void TestReferencedAssemblyVersion()
{
using var assemblyBytes = CompileRaw("""
using var assemblyBytes = CompileToMemory(CreateCompilation("""
import System.Console;
func main() {
WriteLine();
}
""");
"""));

using var peReader = new PEReader(assemblyBytes);
var metadataReader = peReader.GetMetadataReader();
Expand Down
12 changes: 4 additions & 8 deletions src/Draco.Compiler.Tests/Scripting/ReplSessionTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using Draco.Compiler.Api;
using Draco.Compiler.Api.Scripting;
using static Basic.Reference.Assemblies.Net80;
using static Draco.Compiler.Tests.TestUtilities;

namespace Draco.Compiler.Tests.Scripting;

public sealed class ReplSessionTests
{
private static IEnumerable<MetadataReference> BclReferences => ReferenceInfos.All
.Select(r => MetadataReference.FromPeStream(new MemoryStream(r.ImageBytes)));

[InlineData("", null)]
[InlineData("// hello", null)]
[InlineData("1 + 2", 3)]
Expand All @@ -19,7 +15,7 @@ public sealed class ReplSessionTests
[Theory]
public void BasicExpressions(string input, object? output)
{
var replSession = new ReplSession([.. BclReferences]);
var replSession = new ReplSession(BclReferences);

var result = replSession.Evaluate(input);

Expand All @@ -31,7 +27,7 @@ public void BasicExpressions(string input, object? output)
[Theory]
public void InvalidEntries(string input)
{
var replSession = new ReplSession([.. BclReferences]);
var replSession = new ReplSession(BclReferences);

var result = replSession.Evaluate(input);

Expand Down Expand Up @@ -92,7 +88,7 @@ private static void AssertSequence(params (string Code, object? Value)[] pairs)

private static IEnumerable<ExecutionResult<object?>> ExecuteSequence(IEnumerable<string> inputs)
{
var replSession = new ReplSession([.. BclReferences]);
var replSession = new ReplSession(BclReferences);

var ms = new MemoryStream();
var reader = new StreamReader(ms);
Expand Down
12 changes: 3 additions & 9 deletions src/Draco.Compiler.Tests/Scripting/ScriptTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Immutable;
using Draco.Compiler.Api;
using Draco.Compiler.Api.Scripting;
using static Draco.Compiler.Tests.TestUtilities;

namespace Draco.Compiler.Tests.Scripting;

Expand All @@ -15,10 +14,7 @@ public void BasicAssignmentAndAddition()
var y = 4;
x + y
""",
// TODO: We could factor out BCL refs into some global, we repeat this LINQ a lot in tests
metadataReferences: Basic.Reference.Assemblies.Net80.ReferenceInfos.All
.Select(r => MetadataReference.FromPeStream(new MemoryStream(r.ImageBytes)))
.ToImmutableArray());
metadataReferences: BclReferences);

// Act
var result = script.Execute();
Expand All @@ -35,9 +31,7 @@ public void SyntaxErrorInScript()
var script = Script.Create<int>("""
var x = ;
""",
metadataReferences: Basic.Reference.Assemblies.Net80.ReferenceInfos.All
.Select(r => MetadataReference.FromPeStream(new MemoryStream(r.ImageBytes)))
.ToImmutableArray());
metadataReferences: BclReferences);

// Act
var result = script.Execute();
Expand Down
Loading

0 comments on commit 24b9b33

Please sign in to comment.