|
| 1 | +// Copyright 2025 Emin Salih Açıkgöz |
| 2 | +// SPDX-License-Identifier: gpl3-or-later |
| 3 | + |
| 4 | +package makefile |
| 5 | + |
| 6 | +import ( |
| 7 | + "scbake/internal/types" |
| 8 | + "scbake/pkg/tasks" |
| 9 | + "testing" |
| 10 | +) |
| 11 | + |
| 12 | +// TestGetTasks_Makefile validates the generation of the smart Makefile. |
| 13 | +// Logical Validation: The file must be named "Makefile" and occupy the |
| 14 | +// base priority of the Build System band for deterministic execution. |
| 15 | +func TestGetTasks_Makefile(t *testing.T) { |
| 16 | + handler := &Handler{} |
| 17 | + |
| 18 | + plan, err := handler.GetTasks("") |
| 19 | + if err != nil { |
| 20 | + t.Fatalf("Failed to get tasks: %v", err) |
| 21 | + } |
| 22 | + |
| 23 | + if len(plan) != 1 { |
| 24 | + t.Fatalf("Expected exactly 1 task, got %d", len(plan)) |
| 25 | + } |
| 26 | + |
| 27 | + task, ok := plan[0].(*tasks.CreateTemplateTask) |
| 28 | + if !ok { |
| 29 | + t.Fatal("Task type mismatch: expected *tasks.CreateTemplateTask") |
| 30 | + } |
| 31 | + |
| 32 | + // 1. Assert Deterministic Priority |
| 33 | + // Logic: This task must start at the exact base of the Build System band (1400). |
| 34 | + expectedPrio := int(types.PrioBuildSystem) |
| 35 | + if task.TaskPrio != expectedPrio { |
| 36 | + t.Errorf("Priority mismatch: expected first slot in band (%d), got %d", expectedPrio, task.TaskPrio) |
| 37 | + } |
| 38 | + |
| 39 | + // 2. Assert Exact Template Path and Output |
| 40 | + if task.TemplatePath != "makefile.tpl" { |
| 41 | + t.Errorf("Wrong template path: expected 'makefile.tpl', got '%s'", task.TemplatePath) |
| 42 | + } |
| 43 | + if task.OutputPath != "Makefile" { |
| 44 | + t.Errorf("Wrong output filename: expected 'Makefile', got '%s'", task.OutputPath) |
| 45 | + } |
| 46 | + |
| 47 | + // 3. Verify TemplateFS accessibility |
| 48 | + if _, err := task.TemplateFS.ReadFile(task.TemplatePath); err != nil { |
| 49 | + t.Errorf("Task TemplateFS is invalid or template is missing: %v", err) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +// TestMakefile_TemplateExists verifies the embedded template is bundled correctly. |
| 54 | +func TestMakefile_TemplateExists(t *testing.T) { |
| 55 | + handler := &Handler{} |
| 56 | + plan, _ := handler.GetTasks("") |
| 57 | + task := plan[0].(*tasks.CreateTemplateTask) |
| 58 | + |
| 59 | + _, err := templates.ReadFile(task.TemplatePath) |
| 60 | + if err != nil { |
| 61 | + t.Errorf("Embedded template '%s' is missing from binary: %v", task.TemplatePath, err) |
| 62 | + } |
| 63 | +} |
0 commit comments