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

Additional testing for reflectx package #215

Merged
merged 1 commit into from
May 24, 2016

Conversation

jjeffery
Copy link
Contributor

This PR does not change the functionality of the reflectx package -- it just contains additional tests. I'm thinking of submitting a PR in future, and I figured one good way to get more familiar with the workings would be to write some tests for the untested bits.

Before and after coverage stats are listed below. You can see that we have gone from 83% coverage to 99.3%.

Coverage would be 100%, except for one stubborn little line in methodName(). Test coverage on that line would either require modifying reflect.go or somehow tricking the runtime into thinking a PC value was not valid. I didn't want to modify reflect.go in this PR, and fiddling with the runtime seemed a little obsessive for one little line of code, so it stays untested for now.

Before

$ go test -coverprofile coverage.txt && go tool cover -func coverage.txt
PASS
coverage: 83.0% of statements
ok      github.com/jmoiron/sqlx/reflectx        0.026s
github.com\jmoiron\sqlx\reflectx\reflect.go:39:         GetByPath               100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:45:         GetByTraversal          75.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:73:         NewMapper               100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:83:         NewMapperTagFunc        100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:95:         NewMapperFunc           100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:105:        TypeMap                 100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:118:        FieldMap                100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:133:        FieldByName             100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:148:        FieldsByName            0.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:168:        TraversalsByName        90.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:186:        FieldByIndexes          87.5%
github.com\jmoiron\sqlx\reflectx\reflect.go:204:        FieldByIndexesReadOnly  0.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:212:        Deref                   100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:227:        mustBe                  66.7%
github.com\jmoiron\sqlx\reflectx\reflect.go:235:        methodName              0.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:251:        apnd                    100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:262:        getMapping              97.0%
total:                                                  (statements)            83.0%

After:

$ go test -coverprofile coverage.txt && go tool cover -func coverage.txt
PASS
coverage: 99.3% of statements
ok      github.com/jmoiron/sqlx/reflectx        0.025s
github.com\jmoiron\sqlx\reflectx\reflect.go:39:         GetByPath               100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:45:         GetByTraversal          100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:73:         NewMapper               100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:83:         NewMapperTagFunc        100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:95:         NewMapperFunc           100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:105:        TypeMap                 100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:118:        FieldMap                100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:133:        FieldByName             100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:148:        FieldsByName            100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:168:        TraversalsByName        100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:186:        FieldByIndexes          100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:204:        FieldByIndexesReadOnly  100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:212:        Deref                   100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:227:        mustBe                  100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:235:        methodName              80.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:251:        apnd                    100.0%
github.com\jmoiron\sqlx\reflectx\reflect.go:262:        getMapping              100.0%
total:                                                  (statements)            99.3%

@jmoiron jmoiron merged commit a7f971f into jmoiron:master May 24, 2016
@jjeffery jjeffery deleted the reflectx-tests branch May 24, 2016 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants