Refactor build and topdata path resolution through project config

This commit is contained in:
2026-04-24 19:11:10 +02:00
parent d880661599
commit 831d3b47da
11 changed files with 431 additions and 64 deletions
+92
View File
@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"slices"
"strings"
"testing"
)
@@ -83,6 +84,67 @@ func TestTopDataAssetsDirReturnsEmptyForNoConfig(t *testing.T) {
}
}
func TestModuleArchivePathUsesConfiguredBuildDirAndResRef(t *testing.T) {
root := t.TempDir()
mkdirAll(t, filepath.Join(root, "output"))
proj := &Project{
Root: root,
Config: Config{
Module: ModuleConfig{Name: "Test", ResRef: "testmod"},
Paths: PathConfig{Build: "output"},
},
}
got := proj.ModuleArchivePath()
want := filepath.Join(root, "output", "testmod.mod")
if got != want {
t.Fatalf("expected %s, got %s", want, got)
}
}
func TestHAKPathsUseConfiguredBuildDir(t *testing.T) {
root := t.TempDir()
mkdirAll(t, filepath.Join(root, "output"))
proj := &Project{
Root: root,
Config: Config{
Paths: PathConfig{Build: "output"},
},
}
if got, want := proj.HAKManifestPath(), filepath.Join(root, "output", "haks.json"); got != want {
t.Fatalf("expected manifest path %s, got %s", want, got)
}
if got, want := proj.HAKArchivePath("core_01"), filepath.Join(root, "output", "core_01.hak"); got != want {
t.Fatalf("expected hak path %s, got %s", want, got)
}
}
func TestTopDataPackagePathsUseConfiguredNamesAndBuildDir(t *testing.T) {
root := t.TempDir()
mkdirAll(t, filepath.Join(root, "output"))
proj := &Project{
Root: root,
Config: Config{
Paths: PathConfig{Build: "output"},
TopData: TopDataConfig{
PackageHAK: "custom_top.hak",
PackageTLK: "custom_dialog.tlk",
},
},
}
if got, want := proj.TopDataPackageHAKPath(), filepath.Join(root, "output", "custom_top.hak"); got != want {
t.Fatalf("expected top hak path %s, got %s", want, got)
}
if got, want := proj.TopDataPackageTLKPath(), filepath.Join(root, "output", "custom_dialog.tlk"); got != want {
t.Fatalf("expected top tlk path %s, got %s", want, got)
}
}
func TestValidateLayoutAllowsMissingAssetsDir(t *testing.T) {
root := t.TempDir()
mkdirAll(t, filepath.Join(root, "src"))
@@ -104,6 +166,36 @@ func TestValidateLayoutAllowsMissingAssetsDir(t *testing.T) {
}
}
func TestValidateLayoutRejectsInvalidTopDataPackageOutputNames(t *testing.T) {
root := t.TempDir()
mkdirAll(t, filepath.Join(root, "src"))
mkdirAll(t, filepath.Join(root, "build"))
proj := &Project{
Root: root,
Config: Config{
Module: ModuleConfig{Name: "Test", ResRef: "test"},
Paths: PathConfig{Source: "src", Build: "build"},
TopData: TopDataConfig{
Source: "topdata",
PackageHAK: "nested/custom_top.hak",
PackageTLK: "custom_dialog.txt",
},
},
}
err := proj.ValidateLayout()
if err == nil {
t.Fatal("expected topdata output validation error")
}
if !strings.Contains(err.Error(), "topdata.package_hak") {
t.Fatalf("expected package_hak validation error, got %v", err)
}
if !strings.Contains(err.Error(), "topdata.package_tlk") {
t.Fatalf("expected package_tlk validation error, got %v", err)
}
}
func TestScanAllowsMissingAssetsDir(t *testing.T) {
root := t.TempDir()
mkdirAll(t, filepath.Join(root, "src"))