Skip to content

Commit

Permalink
Cover code generation with tests
Browse files Browse the repository at this point in the history
Add test coverage of code generation program.
  • Loading branch information
w0rp committed Sep 10, 2023
1 parent d968e8e commit d61e8fa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/cmd/generatecode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ func createFile(wg *sync.WaitGroup, path string, cb func(*os.File)) {
}()
}

func main() {
type filesToCreate struct {
tupleFilename string
zipFilename string
}

func createFiles(toCreate filesToCreate) {
tupleNames = map[int]string{
1: "Unit",
2: "Pair",
Expand Down Expand Up @@ -343,8 +348,15 @@ func main() {

var wg sync.WaitGroup

createFile(&wg, "tuple.go", writeTupleFile)
createFile(&wg, "zip.go", writeZipFile)
createFile(&wg, toCreate.tupleFilename, writeTupleFile)
createFile(&wg, toCreate.zipFilename, writeZipFile)

wg.Wait()
}

func main() {
createFiles(filesToCreate{
tupleFilename: "tuple.go",
zipFilename: "zip.go",
})
}
24 changes: 24 additions & 0 deletions internal/cmd/generatecode/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"os"
"testing"
)

func TestCacheB(t *testing.T) {
t.Parallel()

dirName, err := os.MkdirTemp("", "")

if err != nil {
t.Fatal(err)
}

defer os.RemoveAll(dirName)

// Run the code to generate files and ensure it doesn't blow up.
createFiles(filesToCreate{
tupleFilename: dirName + "/tuple.go",
zipFilename: dirName + "/zip.go",
})
}

0 comments on commit d61e8fa

Please sign in to comment.