FAQ
I am trying to write a testing script, but I am running into a problem with
import cycles

In the file ransuq_test.go , the file header looks like

---
package ransuq_test

import (
     "testing"

     "ransuq"
     "ransuq/settings"
)
---

When I try "go test ransuq", I get the error
brendan:~/Documents/mygo/src$ go test ransuq
# ransuq
ransuq/ransuq_test.go:6: import "ransuq/settings": package depends on
"ransuq" (import cycle)

"ransuq/settings" does indeed depend on ransuq, but I don't see how I've
introduced an import cycle. Compiling "ransuq" on its own works fine, as
does compiling ransuq/settings, so the cycle must be introduced here. I
don't see how that's possible though, given that the build tool should be
compiling this as a new package (Test files that declare a package with the
suffix "_test" will be compiled as a separate package, and then linked and
run with the main test binary.). This is the only test file in the package.

I tried to write a minimal example, but it exhibited the expected behavior
(no import cycles). Is it possible there is a bug and I should work harder
to find a minimal example, or am I misunderstanding something?

Thanks.

--
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

  • Rodrigo Kochenburger at Mar 24, 2014 at 9:27 pm
    The test should be in the same package, only the file name has the "_test"
    suffix. The compiler won't include the *_test.go files, only when executing
    through go test in which case they are compiled and linked properly in the
    *same* package.

    package ransuq

    import (
         "testing"
         "ransuq/settings"
    )


    - RK

    On Mon, Mar 24, 2014 at 2:23 PM, Brendan Tracey wrote:

    I am trying to write a testing script, but I am running into a problem
    with import cycles

    In the file ransuq_test.go , the file header looks like

    ---
    package ransuq_test

    import (
    "testing"

    "ransuq"
    "ransuq/settings"
    )
    ---

    When I try "go test ransuq", I get the error
    brendan:~/Documents/mygo/src$ go test ransuq
    # ransuq
    ransuq/ransuq_test.go:6: import "ransuq/settings": package depends on
    "ransuq" (import cycle)

    "ransuq/settings" does indeed depend on ransuq, but I don't see how I've
    introduced an import cycle. Compiling "ransuq" on its own works fine, as
    does compiling ransuq/settings, so the cycle must be introduced here. I
    don't see how that's possible though, given that the build tool should be
    compiling this as a new package (Test files that declare a package with the
    suffix "_test" will be compiled as a separate package, and then linked and
    run with the main test binary.). This is the only test file in the package.

    I tried to write a minimal example, but it exhibited the expected behavior
    (no import cycles). Is it possible there is a bug and I should work harder
    to find a minimal example, or am I misunderstanding something?

    Thanks.

    --
    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.
    --
    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.
  • Brendan Tracey at Mar 24, 2014 at 9:31 pm
    The file in question is in the same package path as the ransuq package, and has the name ransuq_test.go. As I quoted, I believe the go tool should be compiling this file as a different package.
    On Mar 24, 2014, at 2:27 PM, Rodrigo Kochenburger wrote:

    The test should be in the same package, only the file name has the "_test" suffix. The compiler won't include the *_test.go files, only when executing through go test in which case they are compiled and linked properly in the *same* package.

    package ransuq

    import (
    "testing"
    "ransuq/settings"
    )


    - RK


    On Mon, Mar 24, 2014 at 2:23 PM, Brendan Tracey wrote:
    I am trying to write a testing script, but I am running into a problem with import cycles

    In the file ransuq_test.go , the file header looks like

    ---
    package ransuq_test

    import (
    "testing"

    "ransuq"
    "ransuq/settings"
    )
    ---

    When I try "go test ransuq", I get the error
    brendan:~/Documents/mygo/src$ go test ransuq
    # ransuq
    ransuq/ransuq_test.go:6: import "ransuq/settings": package depends on "ransuq" (import cycle)

    "ransuq/settings" does indeed depend on ransuq, but I don't see how I've introduced an import cycle. Compiling "ransuq" on its own works fine, as does compiling ransuq/settings, so the cycle must be introduced here. I don't see how that's possible though, given that the build tool should be compiling this as a new package (Test files that declare a package with the suffix "_test" will be compiled as a separate package, and then linked and run with the main test binary.). This is the only test file in the package.

    I tried to write a minimal example, but it exhibited the expected behavior (no import cycles). Is it possible there is a bug and I should work harder to find a minimal example, or am I misunderstanding something?

    Thanks.

    --
    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.
    --
    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.
  • Francesc Campoy Flores at Mar 24, 2014 at 9:35 pm
    Does that mean you have two different packages in a single directory?

    On Mon, Mar 24, 2014 at 2:31 PM, Brendan Tracey wrote:

    The file in question is in the same package path as the ransuq package,
    and has the name ransuq_test.go. As I quoted, I believe the go tool should
    be compiling this file as a different package.

    On Mar 24, 2014, at 2:27 PM, Rodrigo Kochenburger wrote:

    The test should be in the same package, only the file name has the "_test"
    suffix. The compiler won't include the *_test.go files, only when executing
    through go test in which case they are compiled and linked properly in the
    *same* package.

    package ransuq

    import (
    "testing"
    "ransuq/settings"
    )


    - RK

    On Mon, Mar 24, 2014 at 2:23 PM, Brendan Tracey wrote:

    I am trying to write a testing script, but I am running into a problem
    with import cycles

    In the file ransuq_test.go , the file header looks like

    ---
    package ransuq_test

    import (
    "testing"

    "ransuq"
    "ransuq/settings"
    )
    ---

    When I try "go test ransuq", I get the error
    brendan:~/Documents/mygo/src$ go test ransuq
    # ransuq
    ransuq/ransuq_test.go:6: import "ransuq/settings": package depends on
    "ransuq" (import cycle)

    "ransuq/settings" does indeed depend on ransuq, but I don't see how I've
    introduced an import cycle. Compiling "ransuq" on its own works fine, as
    does compiling ransuq/settings, so the cycle must be introduced here. I
    don't see how that's possible though, given that the build tool should be
    compiling this as a new package (Test files that declare a package with the
    suffix "_test" will be compiled as a separate package, and then linked and
    run with the main test binary.). This is the only test file in the package.

    I tried to write a minimal example, but it exhibited the expected
    behavior (no import cycles). Is it possible there is a bug and I should
    work harder to find a minimal example, or am I misunderstanding something?

    Thanks.

    --
    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.

    --
    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.


    --
    --
    Francesc Campoy
    http://twitter.com/francesc

    --
    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.
  • Rodrigo Kochenburger at Mar 24, 2014 at 9:39 pm
    You're telling the compiler to compile it with a different package name
    (ransuq_test). Like I said, your package declaration on your test file
    should be just ransuq and you don't need to import ransuq since it's the
    same package.

    - RK


    On Mon, Mar 24, 2014 at 2:35 PM, Francesc Campoy Flores
    wrote:
    Does that mean you have two different packages in a single directory?

    On Mon, Mar 24, 2014 at 2:31 PM, Brendan Tracey wrote:

    The file in question is in the same package path as the ransuq package,
    and has the name ransuq_test.go. As I quoted, I believe the go tool should
    be compiling this file as a different package.

    On Mar 24, 2014, at 2:27 PM, Rodrigo Kochenburger <divoxx@gmail.com>
    wrote:

    The test should be in the same package, only the file name has the
    "_test" suffix. The compiler won't include the *_test.go files, only when
    executing through go test in which case they are compiled and linked
    properly in the *same* package.

    package ransuq

    import (
    "testing"
    "ransuq/settings"
    )


    - RK


    On Mon, Mar 24, 2014 at 2:23 PM, Brendan Tracey <tracey.brendan@gmail.com
    wrote:
    I am trying to write a testing script, but I am running into a problem
    with import cycles

    In the file ransuq_test.go , the file header looks like

    ---
    package ransuq_test

    import (
    "testing"

    "ransuq"
    "ransuq/settings"
    )
    ---

    When I try "go test ransuq", I get the error
    brendan:~/Documents/mygo/src$ go test ransuq
    # ransuq
    ransuq/ransuq_test.go:6: import "ransuq/settings": package depends on
    "ransuq" (import cycle)

    "ransuq/settings" does indeed depend on ransuq, but I don't see how I've
    introduced an import cycle. Compiling "ransuq" on its own works fine, as
    does compiling ransuq/settings, so the cycle must be introduced here. I
    don't see how that's possible though, given that the build tool should be
    compiling this as a new package (Test files that declare a package with the
    suffix "_test" will be compiled as a separate package, and then linked and
    run with the main test binary.). This is the only test file in the package.

    I tried to write a minimal example, but it exhibited the expected
    behavior (no import cycles). Is it possible there is a bug and I should
    work harder to find a minimal example, or am I misunderstanding something?

    Thanks.

    --
    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.

    --
    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.


    --
    --
    Francesc Campoy
    http://twitter.com/francesc
    --
    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.
  • Brendan Tracey at Mar 24, 2014 at 9:52 pm
    Why is this different from, say, strconv

    http://golang.org/src/pkg/strconv/strconv_test.go

    Or, take a different example

    Contents of Testing/importcycle/subpackage/subpackage.go

    --
    package subpackage

    import "Testing/importcycle"

    var String = "Sub" + importcycle.String
    --

    Contents of Testing/importcycle/importcycle.go
    --
    package importcycle

    func ReturnString(s string) string {
      return s
    }

    var String = "string"
    --

    Contents of Testing/importcycle/importcycle_test.go
    --
    package importcycle_test

    import (
      "Testing/importcycle"
      "Testing/importcycle/subpackage"

      "testing"
    )

    func TestPrint(t *testing.T) {
      str := importcycle.ReturnString(subpackage.String)
      if str != subpackage.String {
       t.Errorf("string mismatch")
      }
    }
    --

    the command "go test Testing/importcycle " reports that all tests have passed.

    These files have the same "problems" as my initial question. "importcycle" and "importcycle_test" packages are both present in Testing/importcycle, and they have the same relative DAG.

    On Mar 24, 2014, at 2:39 PM, Rodrigo Kochenburger wrote:

    You're telling the compiler to compile it with a different package name (ransuq_test). Like I said, your package declaration on your test file should be just ransuq and you don't need to import ransuq since it's the same package.

    - RK


    On Mon, Mar 24, 2014 at 2:35 PM, Francesc Campoy Flores wrote:
    Does that mean you have two different packages in a single directory?


    On Mon, Mar 24, 2014 at 2:31 PM, Brendan Tracey wrote:
    The file in question is in the same package path as the ransuq package, and has the name ransuq_test.go. As I quoted, I believe the go tool should be compiling this file as a different package.
    On Mar 24, 2014, at 2:27 PM, Rodrigo Kochenburger wrote:

    The test should be in the same package, only the file name has the "_test" suffix. The compiler won't include the *_test.go files, only when executing through go test in which case they are compiled and linked properly in the *same* package.

    package ransuq

    import (
    "testing"
    "ransuq/settings"
    )


    - RK


    On Mon, Mar 24, 2014 at 2:23 PM, Brendan Tracey wrote:
    I am trying to write a testing script, but I am running into a problem with import cycles

    In the file ransuq_test.go , the file header looks like

    ---
    package ransuq_test

    import (
    "testing"

    "ransuq"
    "ransuq/settings"
    )
    ---

    When I try "go test ransuq", I get the error
    brendan:~/Documents/mygo/src$ go test ransuq
    # ransuq
    ransuq/ransuq_test.go:6: import "ransuq/settings": package depends on "ransuq" (import cycle)

    "ransuq/settings" does indeed depend on ransuq, but I don't see how I've introduced an import cycle. Compiling "ransuq" on its own works fine, as does compiling ransuq/settings, so the cycle must be introduced here. I don't see how that's possible though, given that the build tool should be compiling this as a new package (Test files that declare a package with the suffix "_test" will be compiled as a separate package, and then linked and run with the main test binary.). This is the only test file in the package.

    I tried to write a minimal example, but it exhibited the expected behavior (no import cycles). Is it possible there is a bug and I should work harder to find a minimal example, or am I misunderstanding something?

    Thanks.

    --
    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.

    --
    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.



    --
    --
    Francesc Campoy
    http://twitter.com/francesc
    --
    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.
  • Dan Kortschak at Mar 24, 2014 at 9:51 pm
    Using the _test suffix in the package name allows black box testing. This should work, though without more information there may/must be something else that is causing the problem.

    Brendan, can you compile another package that imports ransuq and ransuq/config (why are they separate packages BTW?).
    On 25/03/2014, at 7:58 AM, "Rodrigo Kochenburger" wrote:

    The test should be in the same package, only the file name has the "_test" suffix. The compiler won't include the *_test.go files, only when executing through go test in which case they are compiled and linked properly in the *same* package.
    --
    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.
  • Brendan Tracey at Mar 24, 2014 at 10:07 pm
    I'm not sure what I changed, but the problem seems to have disappeared, and is now working as expected. I'll keep trying to reproduce the case before, but at least it's working now... Sorry everyone.
    On Mar 24, 2014, at 2:50 PM, Dan Kortschak wrote:

    Using the _test suffix in the package name allows black box testing. This should work, though without more information there may/must be something else that is causing the problem.

    Brendan, can you compile another package that imports ransuq and ransuq/config (why are they separate packages BTW?).
    On 25/03/2014, at 7:58 AM, "Rodrigo Kochenburger" wrote:

    The test should be in the same package, only the file name has the "_test" suffix. The compiler won't include the *_test.go files, only when executing through go test in which case they are compiled and linked properly in the *same* package.
    --
    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
postedMar 24, '14 at 9:23p
activeMar 24, '14 at 10:07p
posts8
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase