Skip to content

Commit a09605a

Browse files
committed
fix(csharp): satisfy generator lint checks
1 parent a9bf1ab commit a09605a

4 files changed

Lines changed: 400 additions & 186 deletions

File tree

internal/csharpgen/compile_test.go

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func TestGeneratedContractsCompile(t *testing.T) {
2525
t.Skip("dotnet SDK not found; generated C# compile validation requires dotnet")
2626
}
2727

28-
workingDir, err := os.Getwd()
29-
if err != nil {
30-
t.Fatalf("get working directory: %v", err)
28+
workingDir, workingDirErr := os.Getwd()
29+
if workingDirErr != nil {
30+
t.Fatalf("get working directory: %v", workingDirErr)
3131
}
3232
projectRoot := filepath.Join(workingDir, "..", "..")
3333
protoDir := filepath.Join(workingDir, "testdata", "proto")
@@ -46,10 +46,13 @@ func TestGeneratedContractsCompile(t *testing.T) {
4646
assertCrossPackageOutput(t, outputDir)
4747
writeCompileProject(t, outputDir, tc.jsonLib)
4848

49-
cmd := exec.Command("dotnet", "build", "Compile.csproj", "--nologo", "--verbosity", "minimal", "--ignore-failed-sources")
49+
cmd := exec.Command(
50+
"dotnet", "build", "Compile.csproj",
51+
"--nologo", "--verbosity", "minimal", "--ignore-failed-sources",
52+
)
5053
cmd.Dir = outputDir
51-
if output, err := cmd.CombinedOutput(); err != nil {
52-
t.Fatalf("generated %s contracts do not compile: %v\n%s", tc.jsonLib, err, output)
54+
if output, buildErr := cmd.CombinedOutput(); buildErr != nil {
55+
t.Fatalf("generated %s contracts do not compile: %v\n%s", tc.jsonLib, buildErr, output)
5356
}
5457
})
5558
}
@@ -93,9 +96,9 @@ func TestGeneratedWireFormattingIsInvariant(t *testing.T) {
9396
t.Skip("dotnet SDK not found; generated C# runtime validation requires dotnet")
9497
}
9598

96-
workingDir, err := os.Getwd()
97-
if err != nil {
98-
t.Fatalf("get working directory: %v", err)
99+
workingDir, workingDirErr := os.Getwd()
100+
if workingDirErr != nil {
101+
t.Fatalf("get working directory: %v", workingDirErr)
99102
}
100103
projectRoot := filepath.Join(workingDir, "..", "..")
101104
protoDir := filepath.Join(workingDir, "testdata", "proto")
@@ -111,20 +114,29 @@ func TestGeneratedWireFormattingIsInvariant(t *testing.T) {
111114
}
112115
cmd := exec.Command("protoc", args...)
113116
cmd.Dir = protoDir
114-
if output, err := cmd.CombinedOutput(); err != nil {
115-
t.Fatalf("protoc generation: %v\n%s", err, output)
117+
if output, protocErr := cmd.CombinedOutput(); protocErr != nil {
118+
t.Fatalf("protoc generation: %v\n%s", protocErr, output)
116119
}
117120
writeCompileProject(t, outputDir, "system_text_json")
118121
writeWireFormattingProgram(t, outputDir)
119122
cmd = exec.Command("dotnet", "restore", "Compile.csproj", "--nologo", "--ignore-failed-sources")
120123
cmd.Dir = outputDir
121-
if output, err := cmd.CombinedOutput(); err != nil {
122-
t.Fatalf("restore generated invariant wire-formatting runtime test: %v\n%s", err, output)
124+
if output, restoreErr := cmd.CombinedOutput(); restoreErr != nil {
125+
t.Fatalf("restore generated invariant wire-formatting runtime test: %v\n%s", restoreErr, output)
123126
}
124-
cmd = exec.Command("dotnet", "run", "--project", "Compile.csproj", "--no-restore", "--nologo", "--verbosity", "minimal")
127+
cmd = exec.Command(
128+
"dotnet",
129+
"run",
130+
"--project",
131+
"Compile.csproj",
132+
"--no-restore",
133+
"--nologo",
134+
"--verbosity",
135+
"minimal",
136+
)
125137
cmd.Dir = outputDir
126-
if output, err := cmd.CombinedOutput(); err != nil {
127-
t.Fatalf("generated invariant wire-formatting runtime test failed: %v\n%s", err, output)
138+
if output, runErr := cmd.CombinedOutput(); runErr != nil {
139+
t.Fatalf("generated invariant wire-formatting runtime test failed: %v\n%s", runErr, output)
128140
}
129141
}
130142

@@ -179,13 +191,20 @@ func writeCompileProject(t *testing.T, outputDir, jsonLib string) {
179191
func writeWireFormattingProgram(t *testing.T, outputDir string) {
180192
t.Helper()
181193
projectPath := filepath.Join(outputDir, "Compile.csproj")
182-
project, err := os.ReadFile(projectPath)
183-
if err != nil {
184-
t.Fatalf("read runtime compile project: %v", err)
194+
project, readErr := os.ReadFile(projectPath)
195+
if readErr != nil {
196+
t.Fatalf("read runtime compile project: %v", readErr)
185197
}
186-
project = bytes.Replace(project, []byte("<TargetFramework>net8.0</TargetFramework>"), []byte("<TargetFramework>net8.0</TargetFramework>\n <OutputType>Exe</OutputType>\n <UseAppHost>false</UseAppHost>"), 1)
187-
if err := os.WriteFile(projectPath, project, 0o644); err != nil {
188-
t.Fatalf("set runtime compile project output type: %v", err)
198+
project = bytes.Replace(
199+
project,
200+
[]byte("<TargetFramework>net8.0</TargetFramework>"),
201+
[]byte(
202+
"<TargetFramework>net8.0</TargetFramework>\n <OutputType>Exe</OutputType>\n <UseAppHost>false</UseAppHost>",
203+
),
204+
1,
205+
)
206+
if writeErr := os.WriteFile(projectPath, project, 0o644); writeErr != nil {
207+
t.Fatalf("set runtime compile project output type: %v", writeErr)
189208
}
190209
const program = `using System;
191210
using System.Globalization;
@@ -235,7 +254,11 @@ static class Program
235254
}
236255
}
237256
`
238-
if err := os.WriteFile(filepath.Join(outputDir, "Program.cs"), []byte(program), 0o644); err != nil {
239-
t.Fatalf("write invariant wire-formatting program: %v", err)
257+
if writeErr := os.WriteFile(
258+
filepath.Join(outputDir, "Program.cs"),
259+
[]byte(program),
260+
0o644,
261+
); writeErr != nil {
262+
t.Fatalf("write invariant wire-formatting program: %v", writeErr)
240263
}
241264
}

0 commit comments

Comments
 (0)