Skip to content

Commit

Permalink
Simplify separator string generator; seed rng in main.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcaciuc committed Feb 28, 2022
1 parent e56ac6f commit f7d578a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
7 changes: 7 additions & 0 deletions cmd/grill/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import (
"fmt"
"io"
"log"
"math/rand"
"os"
"time"

"github.com/echlebek/grill/internal/grill"
)

const grillVersion = "dev"

func init() {
// Seed rng for test separator string generator.
rand.Seed(time.Now().UnixNano())
}

func main() {
os.Exit(Main(os.Args[1:], os.Stdout, os.Stderr))
}
Expand Down
18 changes: 8 additions & 10 deletions internal/grill/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grill
import (
"bufio"
"bytes"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -226,15 +227,12 @@ func (suite *TestSuite) Run(ctx TestContext) error {
return nil
}

const digits = "0123456789"

// makeTestBreak generates a randomized line used to separate output of
// individual commands in a suite. Randomized element is added to reduce
// the change of the string occurring in the test output itself.
// makeTestBreak generates a line used to separate output of
// individual commands in a suite. Randomized element is used
// to create a string which can be reasonably expected not to
// occur in the test output itself.
func makeTestBreak() string {
b := make([]byte, 8)
for i := range b {
b[i] = digits[rand.Intn(len(digits))]
}
return "GRILL" + string(b) + ":"
b := make([]byte, 4)
rand.Read(b)
return "GRILL" + hex.EncodeToString(b) + ":"
}

0 comments on commit f7d578a

Please sign in to comment.