Skip to content

Commit

Permalink
Avoid creating files when the test-cases run.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skx committed Jul 28, 2024
1 parent 6ce11fe commit fdf3971
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cpm/cpm_bdos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 4 additions & 0 deletions cpm/cpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package main

import (
"os"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fdf3971

Please sign in to comment.