chore: update tests
This commit is contained in:
+1
-29
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
const samplePath = "../testdata/sample.go"
|
const samplePath = "../testdata/sample.go"
|
||||||
|
|
||||||
// TestE2E_CrossLanguage гоняет сериализацию в обе стороны: Go → C# / C# → Go / Go → TS / TS → Go.
|
// TestE2E_CrossLanguage
|
||||||
func TestE2E_CrossLanguage(t *testing.T) {
|
func TestE2E_CrossLanguage(t *testing.T) {
|
||||||
schema, err := parser.ParseSchemaFile(samplePath)
|
schema, err := parser.ParseSchemaFile(samplePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -41,7 +41,6 @@ func TestE2E_CrossLanguage(t *testing.T) {
|
|||||||
{"EnvelopeMessage", "EnvelopeMessage", 0},
|
{"EnvelopeMessage", "EnvelopeMessage", 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
// C# tests (if dotnet is available)
|
|
||||||
if _, err := exec.LookPath("dotnet"); err == nil {
|
if _, err := exec.LookPath("dotnet"); err == nil {
|
||||||
csSrc, err := generator.GenerateCSharpSchema(schema, "Ragono.Messages")
|
csSrc, err := generator.GenerateCSharpSchema(schema, "Ragono.Messages")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -65,7 +64,6 @@ func TestE2E_CrossLanguage(t *testing.T) {
|
|||||||
t.Log("dotnet not found, skipping C# cross-language e2e tests")
|
t.Log("dotnet not found, skipping C# cross-language e2e tests")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeScript tests (if node and tsx are available)
|
|
||||||
if _, err := exec.LookPath("node"); err == nil {
|
if _, err := exec.LookPath("node"); err == nil {
|
||||||
tsSrc, err := generator.GenerateTypeScriptSchema(schema, "Arpack.Messages")
|
tsSrc, err := generator.GenerateTypeScriptSchema(schema, "Arpack.Messages")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,20 +88,16 @@ func TestE2E_CrossLanguage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Build helpers ---
|
|
||||||
|
|
||||||
func buildGoHarness(t *testing.T, generatedSrc []byte) string {
|
func buildGoHarness(t *testing.T, generatedSrc []byte) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
// Читаем sample.go и меняем package на main
|
|
||||||
sampleSrc, err := os.ReadFile(samplePath)
|
sampleSrc, err := os.ReadFile(samplePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("read sample: %v", err)
|
t.Fatalf("read sample: %v", err)
|
||||||
}
|
}
|
||||||
sampleSrc = bytes.Replace(sampleSrc, []byte("package messages"), []byte("package main"), 1)
|
sampleSrc = bytes.Replace(sampleSrc, []byte("package messages"), []byte("package main"), 1)
|
||||||
|
|
||||||
// Generated код уже имеет package main (мы передали "main" в GenerateGo)
|
|
||||||
write(t, filepath.Join(dir, "messages.go"), sampleSrc)
|
write(t, filepath.Join(dir, "messages.go"), sampleSrc)
|
||||||
write(t, filepath.Join(dir, "messages_arpack.go"), generatedSrc)
|
write(t, filepath.Join(dir, "messages_arpack.go"), generatedSrc)
|
||||||
write(t, filepath.Join(dir, "main.go"), []byte(goHarnessSource))
|
write(t, filepath.Join(dir, "main.go"), []byte(goHarnessSource))
|
||||||
@@ -129,33 +123,22 @@ func buildTSHarness(t *testing.T, generatedSrc []byte) string {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
// Create src directory
|
|
||||||
srcDir := filepath.Join(dir, "src")
|
srcDir := filepath.Join(dir, "src")
|
||||||
if err := os.MkdirAll(srcDir, 0755); err != nil {
|
if err := os.MkdirAll(srcDir, 0755); err != nil {
|
||||||
t.Fatalf("mkdir %s: %v", srcDir, err)
|
t.Fatalf("mkdir %s: %v", srcDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write generated messages
|
|
||||||
write(t, filepath.Join(srcDir, "messages.gen.ts"), generatedSrc)
|
write(t, filepath.Join(srcDir, "messages.gen.ts"), generatedSrc)
|
||||||
|
|
||||||
// Write harness
|
|
||||||
write(t, filepath.Join(srcDir, "harness.ts"), []byte(tsHarnessSource))
|
write(t, filepath.Join(srcDir, "harness.ts"), []byte(tsHarnessSource))
|
||||||
|
|
||||||
// Write package.json
|
|
||||||
write(t, filepath.Join(dir, "package.json"), []byte(tsPackageSource))
|
write(t, filepath.Join(dir, "package.json"), []byte(tsPackageSource))
|
||||||
|
|
||||||
// Write tsconfig.json
|
|
||||||
write(t, filepath.Join(dir, "tsconfig.json"), []byte(tsConfigSource))
|
write(t, filepath.Join(dir, "tsconfig.json"), []byte(tsConfigSource))
|
||||||
|
|
||||||
// Install dependencies and build
|
|
||||||
mustRun(t, dir, "npm", "install")
|
mustRun(t, dir, "npm", "install")
|
||||||
mustRun(t, dir, "npx", "tsc")
|
mustRun(t, dir, "npx", "tsc")
|
||||||
|
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Harness runners ---
|
|
||||||
|
|
||||||
func runHarness(t *testing.T, dir, lang, op, typ, hexInput string) string {
|
func runHarness(t *testing.T, dir, lang, op, typ, hexInput string) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
@@ -187,9 +170,6 @@ func runHarness(t *testing.T, dir, lang, op, typ, hexInput string) string {
|
|||||||
return strings.TrimSpace(string(out))
|
return strings.TrimSpace(string(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Output verification ---
|
|
||||||
|
|
||||||
// checkOutput парсит key=value вывод и сравнивает с ожидаемыми значениями.
|
|
||||||
func checkOutput(t *testing.T, typ, output string, epsilon float64) {
|
func checkOutput(t *testing.T, typ, output string, epsilon float64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
t.Logf("output for %s:\n%s", typ, output)
|
t.Logf("output for %s:\n%s", typ, output)
|
||||||
@@ -283,8 +263,6 @@ func assertStr(t *testing.T, kv map[string]string, key, want string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Utilities ---
|
|
||||||
|
|
||||||
func write(t *testing.T, path string, data []byte) {
|
func write(t *testing.T, path string, data []byte) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if err := os.WriteFile(path, data, 0644); err != nil {
|
if err := os.WriteFile(path, data, 0644); err != nil {
|
||||||
@@ -301,8 +279,6 @@ func mustRun(t *testing.T, dir string, name string, args ...string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Go harness source ---
|
|
||||||
|
|
||||||
const goHarnessSource = `package main
|
const goHarnessSource = `package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -398,8 +374,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
// --- C# harness source ---
|
|
||||||
|
|
||||||
const csHarnessSource = `using System;
|
const csHarnessSource = `using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -581,8 +555,6 @@ var csProjSource = `<Project Sdk="Microsoft.NET.Sdk">
|
|||||||
</Project>
|
</Project>
|
||||||
`
|
`
|
||||||
|
|
||||||
// --- TypeScript harness source ---
|
|
||||||
|
|
||||||
const tsPackageSource = `{
|
const tsPackageSource = `{
|
||||||
"name": "arpack-e2e-harness",
|
"name": "arpack-e2e-harness",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user