Skip to content

Commit

Permalink
tests: Create new test project for Google.Api.Generator.Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jskeet committed Sep 1, 2022
1 parent cea304a commit 3db8cb0
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 13 deletions.
10 changes: 8 additions & 2 deletions Generator.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Api.Generator", "Google.Api.Generator\Google.Api.Generator.csproj", "{C28A3B50-A61C-488C-9E2A-82A5C38C8B6B}"
EndProject
Expand All @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Api.Generator.Rest.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Api.Generator.Testing", "Google.Api.Generator.Testing\Google.Api.Generator.Testing.csproj", "{7B7E19A1-38E8-460A-BC86-90FC9AADC483}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Api.Generator.Utils.Tests", "Google.Api.Generator.Utils.Tests\Google.Api.Generator.Utils.Tests.csproj", "{98EC3797-5ED8-4364-832A-E147CAF4F3F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -45,6 +47,10 @@ Global
{7B7E19A1-38E8-460A-BC86-90FC9AADC483}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B7E19A1-38E8-460A-BC86-90FC9AADC483}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B7E19A1-38E8-460A-BC86-90FC9AADC483}.Release|Any CPU.Build.0 = Release|Any CPU
{98EC3797-5ED8-4364-832A-E147CAF4F3F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98EC3797-5ED8-4364-832A-E147CAF4F3F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98EC3797-5ED8-4364-832A-E147CAF4F3F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98EC3797-5ED8-4364-832A-E147CAF4F3F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
32 changes: 32 additions & 0 deletions Google.Api.Generator.Testing/PathUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.IO;

namespace Google.Api.Generator.Testing
{
public static class PathUtils
{
public static string GetRepoRoot()
{
var rootPath = Environment.CurrentDirectory;
while (!new DirectoryInfo(Path.Combine(rootPath, ".git")).Exists)
{
rootPath = Path.GetFullPath(Path.Combine(rootPath, ".."));
}
return rootPath;
}
}
}
8 changes: 2 additions & 6 deletions Google.Api.Generator.Tests/Invoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Google.Api.Generator.Testing;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -34,12 +35,7 @@ public class WithPath : IDisposable

static Invoker()
{
var rootPath = Environment.CurrentDirectory;
while (!rootPath.EndsWith("Google.Api.Generator.Tests"))
{
rootPath = Path.GetFullPath(Path.Combine(rootPath, ".."));
}
RootDir = Path.GetFullPath(Path.Combine(rootPath, ".."));
RootDir = PathUtils.GetRepoRoot();
GeneratorDir = Path.Combine(RootDir, "Google.Api.Generator");
GeneratorTestsDir = Path.Combine(RootDir, "Google.Api.Generator.Tests");
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// into multiple source files, and/or multiple tests.

// TEST_SOURCE_START
using Google.Api.Generator.Utils.Formatting;
using Google.Api.Generator.Testing;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System;
Expand All @@ -39,7 +39,7 @@
using Xunit;
using sys = System;

namespace Google.Api.Generator.Tests
namespace Google.Api.Generator.Utils.Formatting.Tests
{
[Description("ClassDescription")]
public class WhitespaceFormatterTest
Expand Down Expand Up @@ -344,8 +344,11 @@ public override SyntaxToken VisitToken(SyntaxToken token)
}
}

private static string ThisFilename([CallerFilePath] string filePath = null) =>
Path.Combine(Invoker.GeneratorTestsDir, Path.GetFileName(filePath));
private static string ThisFilename([CallerFilePath] string filePath = null)
{
var utilTestDir = Path.Combine(PathUtils.GetRepoRoot(), "Google.Api.Generator.Utils.Tests");
return Path.Combine(utilTestDir, "Formatting", Path.GetFileName(filePath));
}

[Fact]
public void ThisSourceFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using Xunit;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

namespace Google.Api.Generator.Tests
namespace Google.Api.Generator.Utils.Formatting.Tests
{
public class XmlDocSplitterTest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Api.Gax.Testing" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Google.Api.Generator.Testing\Google.Api.Generator.Testing.csproj" />
<ProjectReference Include="..\Google.Api.Generator.Utils\Google.Api.Generator.Utils.csproj" />
</ItemGroup>

</Project>

0 comments on commit 3db8cb0

Please sign in to comment.