[go-nuts] Re: embedding files in tests

2021-06-03 Thread Manlio Perillo
Actually, if a file is embedded in the main package, go list will report it 
in the EmbedFiles field.
If a file is embedded in a test, the -test flag is required because the 
test binary is required.

Regards
Manlio

On Wednesday, June 2, 2021 at 5:56:42 PM UTC+2 peterGo wrote:

> "it seems a bug ... it should" Why?
>
> Why perform unnecessary disk directory I/O for a build to discover which 
> files satisfy the patterns for a test? Go tools are expected to be fast.
>
> Peter
>
> On Wednesday, June 2, 2021 at 5:49:41 AM UTC-4 manlio@gmail.com wrote:
>
>> Here is an example:  https://play.golang.org/p/ElnTtxHnF5I
>>
>> The output of `go list -json ./pkg` only reports `TestEmbedPatterns`.
>> The output of `go list -json -test ./pkg` reports TestEmbedFiles for the 
>> pkg package (it seems a bug, since it should also be reported without the 
>> -test flag).
>> The TestEmbedFiles is also present in the generated `pkg.test` package 
>> and the pkg [pkg.test] package.
>>
>> Thanks
>> Manlio
>>
>>
>> On Wednesday, June 2, 2021 at 4:23:32 AM UTC+2 nikolay.d...@gmail.com 
>> wrote:
>>
>>> I think the question is about `go:embed` directive in `_test.go` files 
>>> will be included in builds of non-test packages, right?
>>>
>>> Don't know for sure, but I think:
>>> - a) if you have `mypkg_test.go` and in it `package mypkg_test` then 
>>> `go:embed` will not get to your non test build as the package is different
>>> - b) if you have `mypkg_test.go` and in it `pakcage mypkg` then... less 
>>> clear. As above referenced in original docs `_test.go` will be excluded 
>>> from non test build regardless of package.
>>>
>>> My personal take, is to go:embed only in case a).
>>>
>>> Cheers,
>>> On Wednesday, June 2, 2021 at 8:09:20 AM UTC+8 peterGo wrote:
>>>
 On Tuesday, June 1, 2021 at 9:17:11 AM UTC-4 manlio@gmail.com 
 wrote:

> When a file is embedded in a test file, will the file be embedded only 
> in the test binary?
> The documentation says nothing about this case, but the data from go 
> list seems to confirm that the file is only embedded in the test binary.
>
> Thanks
> Manlio
>

 The documentation seems clear to me.

 Package testing
 https://golang.org/pkg/testing/

 To write a new test suite, create a file whose name ends _test.go that 
 contains the TestXxx functions as described here. Put the file in the same 
 package as the one being tested. The file will be excluded from regular 
 package builds but will be included when the "go test" command is run. 

 Peter

>>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6894ae4e-7a2b-411c-a86a-d1401b149ff3n%40googlegroups.com.


[go-nuts] Re: embedding files in tests

2021-06-02 Thread peterGo
"it seems a bug ... it should" Why?

Why perform unnecessary disk directory I/O for a build to discover which 
files satisfy the patterns for a test? Go tools are expected to be fast.

Peter

On Wednesday, June 2, 2021 at 5:49:41 AM UTC-4 manlio@gmail.com wrote:

> Here is an example:  https://play.golang.org/p/ElnTtxHnF5I
>
> The output of `go list -json ./pkg` only reports `TestEmbedPatterns`.
> The output of `go list -json -test ./pkg` reports TestEmbedFiles for the 
> pkg package (it seems a bug, since it should also be reported without the 
> -test flag).
> The TestEmbedFiles is also present in the generated `pkg.test` package and 
> the pkg [pkg.test] package.
>
> Thanks
> Manlio
>
>
> On Wednesday, June 2, 2021 at 4:23:32 AM UTC+2 nikolay.d...@gmail.com 
> wrote:
>
>> I think the question is about `go:embed` directive in `_test.go` files 
>> will be included in builds of non-test packages, right?
>>
>> Don't know for sure, but I think:
>> - a) if you have `mypkg_test.go` and in it `package mypkg_test` then 
>> `go:embed` will not get to your non test build as the package is different
>> - b) if you have `mypkg_test.go` and in it `pakcage mypkg` then... less 
>> clear. As above referenced in original docs `_test.go` will be excluded 
>> from non test build regardless of package.
>>
>> My personal take, is to go:embed only in case a).
>>
>> Cheers,
>> On Wednesday, June 2, 2021 at 8:09:20 AM UTC+8 peterGo wrote:
>>
>>> On Tuesday, June 1, 2021 at 9:17:11 AM UTC-4 manlio@gmail.com wrote:
>>>
 When a file is embedded in a test file, will the file be embedded only 
 in the test binary?
 The documentation says nothing about this case, but the data from go 
 list seems to confirm that the file is only embedded in the test binary.

 Thanks
 Manlio

>>>
>>> The documentation seems clear to me.
>>>
>>> Package testing
>>> https://golang.org/pkg/testing/
>>>
>>> To write a new test suite, create a file whose name ends _test.go that 
>>> contains the TestXxx functions as described here. Put the file in the same 
>>> package as the one being tested. The file will be excluded from regular 
>>> package builds but will be included when the "go test" command is run. 
>>>
>>> Peter
>>>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/30b171c0-e3c0-4ff5-a279-fd83b8ed81c9n%40googlegroups.com.


[go-nuts] Re: embedding files in tests

2021-06-02 Thread Manlio Perillo
Here is an example:  https://play.golang.org/p/ElnTtxHnF5I

The output of `go list -json ./pkg` only reports `TestEmbedPatterns`.
The output of `go list -json -test ./pkg` reports TestEmbedFiles for the 
pkg package (it seems a bug, since it should also be reported without the 
-test flag).
The TestEmbedFiles is also present in the generated `pkg.test` package and 
the pkg [pkg.test] package.

Thanks
Manlio


On Wednesday, June 2, 2021 at 4:23:32 AM UTC+2 nikolay.d...@gmail.com wrote:

> I think the question is about `go:embed` directive in `_test.go` files 
> will be included in builds of non-test packages, right?
>
> Don't know for sure, but I think:
> - a) if you have `mypkg_test.go` and in it `package mypkg_test` then 
> `go:embed` will not get to your non test build as the package is different
> - b) if you have `mypkg_test.go` and in it `pakcage mypkg` then... less 
> clear. As above referenced in original docs `_test.go` will be excluded 
> from non test build regardless of package.
>
> My personal take, is to go:embed only in case a).
>
> Cheers,
> On Wednesday, June 2, 2021 at 8:09:20 AM UTC+8 peterGo wrote:
>
>> On Tuesday, June 1, 2021 at 9:17:11 AM UTC-4 manlio@gmail.com wrote:
>>
>>> When a file is embedded in a test file, will the file be embedded only 
>>> in the test binary?
>>> The documentation says nothing about this case, but the data from go 
>>> list seems to confirm that the file is only embedded in the test binary.
>>>
>>> Thanks
>>> Manlio
>>>
>>
>> The documentation seems clear to me.
>>
>> Package testing
>> https://golang.org/pkg/testing/
>>
>> To write a new test suite, create a file whose name ends _test.go that 
>> contains the TestXxx functions as described here. Put the file in the same 
>> package as the one being tested. The file will be excluded from regular 
>> package builds but will be included when the "go test" command is run. 
>>
>> Peter
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d615df39-fb54-4012-8941-edcb1440862cn%40googlegroups.com.


[go-nuts] Re: embedding files in tests

2021-06-01 Thread Nikolay Dubina
I think the question is about `go:embed` directive in `_test.go` files will 
be included in builds of non-test packages, right?

Don't know for sure, but I think:
- a) if you have `mypkg_test.go` and in it `package mypkg_test` then 
`go:embed` will not get to your non test build as the package is different
- b) if you have `mypkg_test.go` and in it `pakcage mypkg` then... less 
clear. As above referenced in original docs `_test.go` will be excluded 
from non test build regardless of package.

My personal take, is to go:embed only in case a).

Cheers,
On Wednesday, June 2, 2021 at 8:09:20 AM UTC+8 peterGo wrote:

> On Tuesday, June 1, 2021 at 9:17:11 AM UTC-4 manlio@gmail.com wrote:
>
>> When a file is embedded in a test file, will the file be embedded only in 
>> the test binary?
>> The documentation says nothing about this case, but the data from go list 
>> seems to confirm that the file is only embedded in the test binary.
>>
>> Thanks
>> Manlio
>>
>
> The documentation seems clear to me.
>
> Package testing
> https://golang.org/pkg/testing/
>
> To write a new test suite, create a file whose name ends _test.go that 
> contains the TestXxx functions as described here. Put the file in the same 
> package as the one being tested. The file will be excluded from regular 
> package builds but will be included when the "go test" command is run. 
>
> Peter
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/de6c4d87-abf4-4ecc-bf99-63a5e24a1f8fn%40googlegroups.com.


[go-nuts] Re: embedding files in tests

2021-06-01 Thread peterGo
On Tuesday, June 1, 2021 at 9:17:11 AM UTC-4 manlio@gmail.com wrote:

> When a file is embedded in a test file, will the file be embedded only in 
> the test binary?
> The documentation says nothing about this case, but the data from go list 
> seems to confirm that the file is only embedded in the test binary.
>
> Thanks
> Manlio
>

The documentation seems clear to me.

Package testing
https://golang.org/pkg/testing/

To write a new test suite, create a file whose name ends _test.go that 
contains the TestXxx functions as described here. Put the file in the same 
package as the one being tested. The file will be excluded from regular 
package builds but will be included when the "go test" command is run. 

Peter

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/09209571-86eb-4392-8803-07b7bea05174n%40googlegroups.com.


[go-nuts] Re: embedding files in tests

2021-06-01 Thread jake...@gmail.com
I would strongly assume that the file is only embedded in the test binary. 
In fact it is hard to imagine a design where it would not be that way. 
If you really want to make sure, you could easily build two, identical 
binaries, that differ only in that a very large file is embedded in the 
test file for one, and compare sizes. 
On Tuesday, June 1, 2021 at 9:17:11 AM UTC-4 manlio@gmail.com wrote:

> When a file is embedded in a test file, will the file be embedded only in 
> the test binary?
> The documentation says nothing about this case, but the data from go list 
> seems to confirm that the file is only embedded in the test binary.
>
> Thanks
> Manlio
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f9f0df28-3319-43ee-a34a-d638a6008767n%40googlegroups.com.