From fdf39717f8c37d3594a42a3b9a80ffc80986776f Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sun, 28 Jul 2024 18:43:55 +0300 Subject: [PATCH] Avoid creating files when the test-cases run. Previously we created cpm/printer.log and samples/FOO when the test-cases ran - we should cleanup generated files to avoid dirtying our git-status. --- cpm/cpm_bdos_test.go | 13 +++++++++++-- cpm/cpm_test.go | 4 ++++ main_test.go | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cpm/cpm_bdos_test.go b/cpm/cpm_bdos_test.go index 5f6985d..a25a940 100644 --- a/cpm/cpm_bdos_test.go +++ b/cpm/cpm_bdos_test.go @@ -587,8 +587,17 @@ func TestIOByte(t *testing.T) { // increase our coverage. func TestBDOSCoverage(t *testing.T) { - // Create a new helper - c, err := New() + // Create a printer-output file + file, err := os.CreateTemp("", "tst-*.prn") + if err != nil { + t.Fatalf("failed to create temporary file") + } + defer os.Remove(file.Name()) + + // Create a new helper - redirect the printer log because + // we'll be invoking BdosSysCallPrinterWrite + c, err := New(WithPrinterPath(file.Name())) + if err != nil { t.Fatalf("failed to create CPM") } diff --git a/cpm/cpm_test.go b/cpm/cpm_test.go index f8b14a4..ad20794 100644 --- a/cpm/cpm_test.go +++ b/cpm/cpm_test.go @@ -151,6 +151,10 @@ func TestPrinterOutput(t *testing.T) { t.Fatalf("failed to create CPM") } + if obj.prnPath != file.Name() { + t.Fatalf("unexpected filename for printer log") + } + // Now output some characters err = obj.prnC('s') if err != nil { diff --git a/main_test.go b/main_test.go index 7e8f082..f9ac300 100644 --- a/main_test.go +++ b/main_test.go @@ -3,6 +3,8 @@ package main import ( + "os" + "path/filepath" "strings" "testing" @@ -80,6 +82,9 @@ func TestReadWriteRand(t *testing.T) { if err != nil && err != cpm.ErrHalt { t.Fatalf("failed to run: %s", err) } + + // Remove the generated file + os.Remove(filepath.Join("samples", "FOO")) } // TestCompleteLighthouse plays our Lighthouse game, to completion.