Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump github.com/stretchr/testify from 1.8.1 to 1.8.3 #26

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ If you wish to work on QuickFIX/Go itself, you will need [Docker](https://docs.d
* Click the pop-up to re-open the project in the Dev Container
* This opens the project in a docker container pre-configured with everything you need

### Build and Test
### Build and Run Unit Tests

The default make target runs [go vet](https://godoc.org/golang.org/x/tools/cmd/vet) and unit tests.

Expand Down Expand Up @@ -137,13 +137,13 @@ QuickFIX/Go acceptance tests depend on ruby in path, if you are using the dev co
To run acceptance tests,

```sh
# generate code locally
# run the generator located in the cmd/ directory and outputs the suite of static FIX packages for every version into the gen/ directory
make generate

# build acceptance test rig
make build-test-srv

# run acceptance tests
# run acceptance test suite against the generated packages
make accept
```

Expand Down
10 changes: 10 additions & 0 deletions cmd/generate-fix/generate-fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ func main() {
log.Fatalf("Error Parsing %v: %v", dataDictPath, err)
}
specs = append(specs, spec)
fmt.Println("found spec at " + dataDictPath)
}

internal.BuildGlobalFieldTypes(specs)

internal.NewBar()
waitGroup.Add(1)
go genTags()
waitGroup.Add(1)
Expand Down Expand Up @@ -186,9 +188,17 @@ func main() {
}()

var h internal.ErrorHandler
var idx int
for err := range errors {
if idx == 0 {
internal.FinishBar()
idx++
}
h.Handle(err)
}
if idx == 0 {
internal.FinishBar()
}

os.Exit(h.ReturnCode)
}
90 changes: 90 additions & 0 deletions cmd/generate-fix/internal/bar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package internal

import (
"fmt"
"unicode"
)

var (
bar Bar
)

// Bar
type Bar struct {
percent int64 // progress percentage
cur int64 // current progress
total int64
rate string // the actual progress bar to be printed
graph string // the fill value for progress bar
}

func NewBar() {
bar.cur = 0
bar.total = 1
if bar.graph == "" {
bar.graph = "#"
}
bar.percent = bar.getPercent()
for i := 0; i < int(bar.percent); i += 2 {
bar.rate += bar.graph // initial progress position
}
}

func (bar *Bar) getPercent() int64 {
return int64((float32(bar.cur) / float32(bar.total)) * 100)
}

func addToBar(n int64) {
bar.total = bar.total + n
}

func printBar(cur int64, str string) {
bar.cur = bar.cur + cur
last := bar.percent
bar.percent = bar.getPercent()
if bar.percent != last && bar.percent%2 == 0 {
bar.rate += bar.graph
}
// [%-50s]
// bar.rate,
erase := "\r "
max := len(erase)
out := fmt.Sprintf("\r\u001b[1m %3d%% %s/%s \033[0m writing %s.. ", bar.percent, fmtByteCount(bar.cur), fmtByteCount(bar.total), str)
fmt.Print(erase)
fmt.Print(trunc(out, max))

}

func FinishBar() {
fmt.Println()
fmt.Println("finished")
}

func trunc(text string, maxLen int) string {
lastSpaceIx := maxLen
len := 0
for i, r := range text {
if unicode.IsSpace(r) {
lastSpaceIx = i
}
len++
if len > maxLen {
return text[:lastSpaceIx] + ".."
}
}
// If here, string is shorter or equal to maxLen
return text
}

func fmtByteCount(b int64) string {
const unit = 1000
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp])
}
18 changes: 14 additions & 4 deletions cmd/generate-fix/internal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (h *ErrorHandler) Handle(err error) {
}
}

func write(filePath string, fset *token.FileSet, f *ast.File) error {
func write(filePath string, fset *token.FileSet, f *ast.File, size int) error {
if parentdir := path.Dir(filePath); parentdir != "." {
if err := os.MkdirAll(parentdir, os.ModePerm); err != nil {
return err
Expand All @@ -59,9 +59,19 @@ func write(filePath string, fset *token.FileSet, f *ast.File) error {
}

ast.SortImports(fset, f)
addToBar(int64(size))
err = (&printer.Config{Mode: printerMode, Tabwidth: tabWidth}).Fprint(file, fset, f)
_ = file.Close()
return err
closeErr := file.Close()
printBar(int64(size), filePath)

if err != nil {
fmt.Println(err)
return err
}
if closeErr != nil {
return closeErr
}
return nil
}

//WriteFile parses the generated code in fileOut and writes the code out to filePath.
Expand All @@ -75,7 +85,7 @@ func WriteFile(filePath, fileOut string) error {
}

//write out the file regardless of parseFile errors
if err := write(filePath, fset, f); err != nil {
if err := write(filePath, fset, f, len(fileOut)); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/generate-fix/internal/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ func quickfixValueType(quickfixType string) (goType string, err error) {
goType = "string"
case "FIXBoolean":
goType = "bool"
case "FIXInt":
goType = "int"
case "FIXUInt":
goType = "uint"
case "FIXUTCTimestamp":
goType = "time.Time"
case "FIXFloat":
Expand Down Expand Up @@ -240,7 +240,7 @@ func quickfixType(field *datadictionary.FieldType) (quickfixType string, err err
case "SEQNUM":
fallthrough
case "INT":
quickfixType = "FIXInt"
quickfixType = "FIXUInt"

case "UTCTIMESTAMP":
quickfixType = "FIXUTCTimestamp"
Expand Down
4 changes: 2 additions & 2 deletions cmd/generate-fix/internal/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ func (f {{ .Name }}Field) Value() ({{ quickfixValueType $base_type }}) {
return f.String() }
{{- else if eq $base_type "FIXBoolean" -}}
return f.Bool() }
{{- else if eq $base_type "FIXInt" -}}
return f.Int() }
{{- else if eq $base_type "FIXUInt" -}}
return f.UInt() }
{{- else if eq $base_type "FIXUTCTimestamp" -}}
return f.Time }
{{- else if eq $base_type "FIXFloat" -}}
Expand Down
18 changes: 9 additions & 9 deletions field_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ func (m FieldMap) GetBool(tag Tag) (bool, MessageRejectError) {
return bool(val), nil
}

// GetInt is a GetField wrapper for int fields.
func (m FieldMap) GetInt(tag Tag) (int, MessageRejectError) {
// GetUInt is a GetField wrapper for int fields.
func (m FieldMap) GetUInt(tag Tag) (uint, MessageRejectError) {
bytes, err := m.GetBytes(tag)
if err != nil {
return 0, err
}

var val FIXInt
var val FIXUInt
if val.Read(bytes) != nil {
err = IncorrectDataFormatForValue(tag)
}

return int(val), err
return val.UInt(), err
}

// GetTime is a GetField wrapper for utc timestamp fields.
Expand Down Expand Up @@ -216,9 +216,9 @@ func (m *FieldMap) SetBool(tag Tag, value bool) *FieldMap {
return m.SetField(tag, FIXBoolean(value))
}

// SetInt is a SetField wrapper for int fields.
func (m *FieldMap) SetInt(tag Tag, value int) *FieldMap {
v := FIXInt(value)
// SetUInt is a SetField wrapper for uint fields.
func (m *FieldMap) SetUInt(tag Tag, value uint) *FieldMap {
v := FIXUInt(value)
return m.SetBytes(tag, v.Write())
}

Expand Down Expand Up @@ -335,11 +335,11 @@ func (m FieldMap) total() int {
return total
}

func (m FieldMap) length() int {
func (m FieldMap) length() uint {
m.rwLock.RLock()
defer m.rwLock.RUnlock()

length := 0
var length uint
for _, fields := range m.tagLookup {
for _, tv := range fields {
switch tv.tag {
Expand Down
14 changes: 7 additions & 7 deletions field_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func TestFieldMap_Length(t *testing.T) {
fMap.SetField(1, FIXString("hello"))
fMap.SetField(2, FIXString("world"))
fMap.SetField(8, FIXString("FIX.4.4"))
fMap.SetField(9, FIXInt(100))
fMap.SetField(9, FIXUInt(100))
fMap.SetField(10, FIXString("100"))
assert.Equal(t, 16, fMap.length(), "Length should include all fields but beginString, bodyLength, and checkSum")
assert.EqualValues(t, 16, fMap.length(), "Length should include all fields but beginString, bodyLength, and checkSum")
}

func TestFieldMap_Total(t *testing.T) {
Expand All @@ -85,7 +85,7 @@ func TestFieldMap_Total(t *testing.T) {
fMap.SetField(1, FIXString("hello"))
fMap.SetField(2, FIXString("world"))
fMap.SetField(8, FIXString("FIX.4.4"))
fMap.SetField(Tag(9), FIXInt(100))
fMap.SetField(Tag(9), FIXUInt(100))
fMap.SetField(10, FIXString("100"))

assert.Equal(t, 2116, fMap.total(), "Total should includes all fields but checkSum")
Expand All @@ -96,17 +96,17 @@ func TestFieldMap_TypedSetAndGet(t *testing.T) {
fMap.init()

fMap.SetString(1, "hello")
fMap.SetInt(2, 256)
fMap.SetUInt(2, 256)

s, err := fMap.GetString(1)
assert.Nil(t, err)
assert.Equal(t, "hello", s)

i, err := fMap.GetInt(2)
i, err := fMap.GetUInt(2)
assert.Nil(t, err)
assert.Equal(t, 256, i)
assert.EqualValues(t, 256, i)

_, err = fMap.GetInt(1)
_, err = fMap.GetUInt(1)
assert.NotNil(t, err, "Type mismatch should occur error")

s, err = fMap.GetString(2)
Expand Down
Loading