FAQ
I'm working with a test/assertion package that runs on top of `go test`.

Like go test, I'd like to assure tests are run per definition order. Right
now they're being reflected via their index value, and thus alphabetised.
This is messing up test order and breaking stuff.

Is checking the pointer address and sorting by uintptr guaranteed to
produce definition order?

Or is it possible that Go could allocate space non-linearly?

Thanks in advance - and happy New Year guys.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Keith Randall at Jan 3, 2016 at 12:47 am
    "go test" does not assure tests are run in definition order. If the
    current "go test" does that, it is not part of the specification and could
    change at any time.

    Sorting by address is not guaranteed to get you definition order either.
      (Again, it may in some Go versions, but is not guaranteed by the spec.)

    In fact, now that I think about it I'm not sure how "go test" ends up
    running them in definition order. Weird.

    Tests in general should not depend on the order in which they are executed.
      If they do, the tests are not independent and I would consider that a bug
    in itself. Of course, as the writer of a testing package you're at the
    mercy of the quality of the tests that your users write. But if the test
    order breaks their tests, I would report that to your user, not try to fix
    your framework.
    On Friday, January 1, 2016 at 7:09:50 PM UTC-8, Lee Benson wrote:

    I'm working with a test/assertion package that runs on top of `go test`.

    Like go test, I'd like to assure tests are run per definition order. Right
    now they're being reflected via their index value, and thus alphabetised.
    This is messing up test order and breaking stuff.

    Is checking the pointer address and sorting by uintptr guaranteed to
    produce definition order?

    Or is it possible that Go could allocate space non-linearly?

    Thanks in advance - and happy New Year guys.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Piers at Jan 3, 2016 at 12:32 pm
    It appears "go test" doesn't use reflection as such. It invokes a parse (
    go/parser.ParseFile <https://godoc.org/go/parser#ParseFile>) on the test
    files which returns a go/ast.File <https://godoc.org/go/ast#File> whose
    Decls member is a list of top-level declarations, in the order they appear.
    These are then filtered down to test function declarations and currently
    run in that order.

    See func (t *testFuncs) load(...) in cmd/go/test.go
    <https://golang.org/src/cmd/go/test.go>.


    On Sunday, 3 January 2016 00:47:26 UTC, keith....@gmail.com wrote:

    "go test" does not assure tests are run in definition order. If the
    current "go test" does that, it is not part of the specification and could
    change at any time.

    Sorting by address is not guaranteed to get you definition order either.
    (Again, it may in some Go versions, but is not guaranteed by the spec.)

    In fact, now that I think about it I'm not sure how "go test" ends up
    running them in definition order. Weird.

    Tests in general should not depend on the order in which they are
    executed. If they do, the tests are not independent and I would consider
    that a bug in itself. Of course, as the writer of a testing package you're
    at the mercy of the quality of the tests that your users write. But if the
    test order breaks their tests, I would report that to your user, not try to
    fix your framework.
    On Friday, January 1, 2016 at 7:09:50 PM UTC-8, Lee Benson wrote:

    I'm working with a test/assertion package that runs on top of `go test`.

    Like go test, I'd like to assure tests are run per definition order.
    Right now they're being reflected via their index value, and thus
    alphabetised. This is messing up test order and breaking stuff.

    Is checking the pointer address and sorting by uintptr guaranteed to
    produce definition order?

    Or is it possible that Go could allocate space non-linearly?

    Thanks in advance - and happy New Year guys.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ernesto Jiménez at Jan 4, 2016 at 4:32 pm
    Keith, Piers,

    FYI, `go test` actually sorts tests in that `load`
    function: `sort.Sort(byOrder(ex))`

    I'm guessing that rather than it being a guarantee it's just an arbitrary
    order because running tests in a random order might result in random
    failures when tests have side effects the interfere with each other. By
    setting an arbitrary order tests with side effects pass/fail consistently.
    Tests should still be isolated and avoid relying on run order and side
    effects from other tests.

    On Sunday, 3 January 2016 13:32:27 UTC+1, Piers wrote:

    It appears "go test" doesn't use reflection as such. It invokes a parse (
    go/parser.ParseFile <https://godoc.org/go/parser#ParseFile>) on the test
    files which returns a go/ast.File <https://godoc.org/go/ast#File> whose
    Decls member is a list of top-level declarations, in the order they appear.
    These are then filtered down to test function declarations and currently
    run in that order.

    See func (t *testFuncs) load(...) in cmd/go/test.go
    <https://golang.org/src/cmd/go/test.go>.


    On Sunday, 3 January 2016 00:47:26 UTC, keith....@gmail.com wrote:

    "go test" does not assure tests are run in definition order. If the
    current "go test" does that, it is not part of the specification and could
    change at any time.

    Sorting by address is not guaranteed to get you definition order either.
    (Again, it may in some Go versions, but is not guaranteed by the spec.)

    In fact, now that I think about it I'm not sure how "go test" ends up
    running them in definition order. Weird.

    Tests in general should not depend on the order in which they are
    executed. If they do, the tests are not independent and I would consider
    that a bug in itself. Of course, as the writer of a testing package you're
    at the mercy of the quality of the tests that your users write. But if the
    test order breaks their tests, I would report that to your user, not try to
    fix your framework.
    On Friday, January 1, 2016 at 7:09:50 PM UTC-8, Lee Benson wrote:

    I'm working with a test/assertion package that runs on top of `go test`.

    Like go test, I'd like to assure tests are run per definition order.
    Right now they're being reflected via their index value, and thus
    alphabetised. This is messing up test order and breaking stuff.

    Is checking the pointer address and sorting by uintptr guaranteed to
    produce definition order?

    Or is it possible that Go could allocate space non-linearly?

    Thanks in advance - and happy New Year guys.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Piers at Jan 4, 2016 at 4:53 pm
    From what I can see it's only sorting the "examples". (Making an assumption
    about what doc.Examples(f) does.)
    On Monday, 4 January 2016 16:32:42 UTC, Ernesto Jiménez wrote:

    Keith, Piers,

    FYI, `go test` actually sorts tests in that `load`
    function: `sort.Sort(byOrder(ex))`

    I'm guessing that rather than it being a guarantee it's just an arbitrary
    order because running tests in a random order might result in random
    failures when tests have side effects the interfere with each other. By
    setting an arbitrary order tests with side effects pass/fail consistently.
    Tests should still be isolated and avoid relying on run order and side
    effects from other tests.

    On Sunday, 3 January 2016 13:32:27 UTC+1, Piers wrote:

    It appears "go test" doesn't use reflection as such. It invokes a parse (
    go/parser.ParseFile <https://godoc.org/go/parser#ParseFile>) on the test
    files which returns a go/ast.File <https://godoc.org/go/ast#File> whose
    Decls member is a list of top-level declarations, in the order they appear.
    These are then filtered down to test function declarations and currently
    run in that order.

    See func (t *testFuncs) load(...) in cmd/go/test.go
    <https://golang.org/src/cmd/go/test.go>.


    On Sunday, 3 January 2016 00:47:26 UTC, keith....@gmail.com wrote:

    "go test" does not assure tests are run in definition order. If the
    current "go test" does that, it is not part of the specification and could
    change at any time.

    Sorting by address is not guaranteed to get you definition order either.
    (Again, it may in some Go versions, but is not guaranteed by the spec.)

    In fact, now that I think about it I'm not sure how "go test" ends up
    running them in definition order. Weird.

    Tests in general should not depend on the order in which they are
    executed. If they do, the tests are not independent and I would consider
    that a bug in itself. Of course, as the writer of a testing package you're
    at the mercy of the quality of the tests that your users write. But if the
    test order breaks their tests, I would report that to your user, not try to
    fix your framework.
    On Friday, January 1, 2016 at 7:09:50 PM UTC-8, Lee Benson wrote:

    I'm working with a test/assertion package that runs on top of `go test`.

    Like go test, I'd like to assure tests are run per definition order.
    Right now they're being reflected via their index value, and thus
    alphabetised. This is messing up test order and breaking stuff.

    Is checking the pointer address and sorting by uintptr guaranteed to
    produce definition order?

    Or is it possible that Go could allocate space non-linearly?

    Thanks in advance - and happy New Year guys.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 2, '16 at 3:09a
activeJan 4, '16 at 4:53p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase