Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-19 Thread Henry
Thanks. It does work. I suppose I had wrong assumptions on how the 
'internal' package works. I thought it is usable only by its immediate 
parent package. It turns out it is usable by any other packages that share 
the same parent as the internal package. 

Thanks again, everyone! :)

Henry

On Monday, December 19, 2016 at 1:31:03 PM UTC+7, Marian Kopriva wrote:

> What Dave suggested should work, in your example package1, package2, 
> package3 and package4 should be able to import testhelpers with `import 
> "project/internal/testhelpers"`
>
> On Sunday, December 18, 2016 at 2:48:41 PM UTC+1, Henry wrote:
>>
>> Where do you put this internal package in relation to the rest of the 
>> packages? Is it something like this:
>>
>> project/
>>package1/
>>package2/
>>package3/package4/
>>internal/testhelpers/
>>
>> I thought internal package would only be visible to its immediate parent? 
>> I want it to be usable across the packages. 
>>
>> 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Marian Kopriva
What Dave suggested should work, in your example package1, package2, 
package3 and package4 should be able to import testhelpers with `import 
"project/internal/testhelpers"`

On Sunday, December 18, 2016 at 2:48:41 PM UTC+1, Henry wrote:
>
> Where do you put this internal package in relation to the rest of the 
> packages? Is it something like this:
>
> project/
>package1/
>package2/
>package3/package4/
>internal/testhelpers/
>
> I thought internal package would only be visible to its immediate parent? 
> I want it to be usable across the packages. 
>
> 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Henry
The problem with putting my test utilities under  a single file, lets say 
util_test.go, is that the utilities are not usable across different packages 
within the same project. As far as I know, you cannot import test packages (eg. 
mypackage_test).

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Mark Mandel
Any reason not to have a `utils_test.go` file - and puts your utilities in
there? Seems like the simplest solution.

Then they only get included for your tests.

Using /internal for testing tools feels a bit strange to me IMHO.

Mark

On 18 December 2016 at 11:13, Matt Harden  wrote:

> An import of a path containing the element “internal” is disallowed if the
> importing code is outside the tree rooted at the parent of the “internal”
> directory.
>
> Note the use of the word "tree" in that sentence, as opposed to
> "directory".
>
> On Sun, Dec 18, 2016 at 5:48 AM Henry  wrote:
>
>> Where do you put this internal package in relation to the rest of the
>> packages? Is it something like this:
>>
>> project/
>>package1/
>>package2/
>>package3/package4/
>>internal/testhelpers/
>>
>> I thought internal package would only be visible to its immediate parent?
>> I want it to be usable across the packages.
>>
>> 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+unsubscr...@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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Matt Harden
An import of a path containing the element “internal” is disallowed if the
importing code is outside the tree rooted at the parent of the “internal”
directory.

Note the use of the word "tree" in that sentence, as opposed to "directory".

On Sun, Dec 18, 2016 at 5:48 AM Henry  wrote:

> Where do you put this internal package in relation to the rest of the
> packages? Is it something like this:
>
> project/
>package1/
>package2/
>package3/package4/
>internal/testhelpers/
>
> I thought internal package would only be visible to its immediate parent?
> I want it to be usable across the packages.
>
> 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+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Henry
Where do you put this internal package in relation to the rest of the packages? 
Is it something like this:

project/
   package1/
   package2/
   package3/package4/
   internal/testhelpers/

I thought internal package would only be visible to its immediate parent? I 
want it to be usable across the packages. 

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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Dave Cheney
Like Nigel suggested

project/
  internal/
 testhelper



On Sunday, 18 December 2016 21:45:25 UTC+11, Henry wrote:
>
> No. I meant something like this:
>
> project/
> -- package1
> -- package2
> -- package3
>
> Now there is a reusable test utility that is used by the tests in 
> package1, package2, and package3. So the question is where do I put the 
> test utility without exposing them as a part of the project's API? I don't 
> want the test utility to get compiled into the final binary as it is 
> supposed to be part of the test.
>
> On Sunday, December 18, 2016 at 5:30:20 PM UTC+7, Nigel Tao wrote:
>
>> On Sun, Dec 18, 2016 at 1:51 PM, Henry  wrote: 
>> > I have reusable test utilities in a project. They are used by various 
>> > packages in the project for testing purposes, and at the same time I 
>> don't 
>> > want to expose these utilities as public APIs. Since it is impossible 
>> to 
>> > import another test package in Go, I wonder what would be the best way 
>> to 
>> > package these utilities. 
>>
>> It sounds like you want an internal package. See 
>> https://golang.org/s/go14internal 
>>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Henry
No. I meant something like this:

project/
-- package1
-- package2
-- package3

Now there is a reusable test utility that is used by the tests in package1, 
package2, and package3. So the question is where do I put the test utility 
without exposing them as a part of the project's API? I don't want the test 
utility to get compiled into the final binary as it is supposed to be part 
of the test.

On Sunday, December 18, 2016 at 5:30:20 PM UTC+7, Nigel Tao wrote:

> On Sun, Dec 18, 2016 at 1:51 PM, Henry  > wrote: 
> > I have reusable test utilities in a project. They are used by various 
> > packages in the project for testing purposes, and at the same time I 
> don't 
> > want to expose these utilities as public APIs. Since it is impossible to 
> > import another test package in Go, I wonder what would be the best way 
> to 
> > package these utilities. 
>
> It sounds like you want an internal package. See 
> https://golang.org/s/go14internal 
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Nigel Tao
On Sun, Dec 18, 2016 at 1:51 PM, Henry  wrote:
> I have reusable test utilities in a project. They are used by various
> packages in the project for testing purposes, and at the same time I don't
> want to expose these utilities as public APIs. Since it is impossible to
> import another test package in Go, I wonder what would be the best way to
> package these utilities.

It sounds like you want an internal package. See
https://golang.org/s/go14internal

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.