go test coverprofile cannot find package - go

When I try the following
go test -coverprofile=coverage.out
I get this coverage.out:
mode: set
_/Users/gert/Desktop/httx/auth.go:10.66,11.54 1 0
_/Users/gert/Desktop/httx/auth.go:11.54,13.89 2 0
_/Users/gert/Desktop/httx/auth.go:17.3,17.11 1 0
_/Users/gert/Desktop/httx/auth.go:13.89,16.4 2 0
_/Users/gert/Desktop/httx/auth.go:22.42,25.2 2 0
...
But when I then do
go tool cover -func=coverage.out
coverage.out doesn't seem to be correctly formatted?
cover: can't find "auth.go": cannot find package "_/Users/gert/Desktop/httx/" in any of:
/usr/local/Cellar/go/1.7.1/libexec/src/_/Users/gert/Desktop/httx (from $GOROOT)
/Users/gert/go/src/_/Users/gert/Desktop/httx (from $GOPATH)
EDIT: Note that go test -cover works.
PASS
coverage: 29.7% of statements
ok _/Users/gert/Desktop/httx 0.015s

Your package /Users/gert/Desktop/httx/ is outside of your $GOPATH which is /Users/gert/go. Move the httx package somewhere under your $GOPATH and it will work fine. You could move it to /Users/gert/go/src/httx or probably something like /Users/gert/go/src/github.com/your-github-name/httx (assuming you use GitHub).

see use relative path
change coverage path to ./ :
sed -i "s/_$(pwd|sed 's/\//\\\//g')/./g" coverage.out

Related

AsyncAPI: Only generate payload

Is it possible to skip generation of specific files using asyncapi-generator?
I am using the Go generator but I only need the payload.go. Right now it always generates all files:
handlers.go payloads.go publishers.go router.go server.go subscribers.go
The command I am using is:
$ docker run --rm -it \
-v ${PWD}/asyncapi.yaml:/app/asyncapi.yml \
-v ${PWD}/output:/app/output \
asyncapi/generator -o /app/output /app/asyncapi.yml #asyncapi/go-watermill-template --force-write
You cannot selectively generate only selected files yet. I encourage you to join the related discussion on GitHub
From what I understand is that you are interested only in models generation. So maybe you should just use directly the Modelina tool that is used there in go-watermill-template.
Modelina is already integrated with AsyncAPI CLI and you can do asyncapi generate models golang asyncapi.yml

Run ansible-lint through subdirectories within a gitlab role

I am trying to add a validation step to a gitlab repo holding a single ansible role (with no playbook).
The structure of the role looks like :
.gitlab-ci.yml
tasks/
templates/
files/
vars/
handlers/
With the gitlab-ci looking like :
stages:
- lint
job-lint:
image:
name: cytopia/ansible-lint:latest
entrypoint: ["/bin/sh", "-c"]
stage: lint
script:
- ansible-lint --version
- ansible-lint . -x 106 tasks/*.yml
I need to skip the naming rule, thus ignoring rule 106.
Otherwise, I would like all files at the root repo to be checked. Since there is no playbook, lint has to be given the files that need to be checked... or at least, that is what I understoodd : I may have this point wrong. But anyway, if I give no name, lint does return ok but actually performs no check.
My problem is that I don't know how to tell him to check all the yaml in a recursive way, or even within a subdirectory. The above code returns an error :
ansible-lint: error: unrecognized arguments: tasks/deploy.yml tasks/localhost.yml tasks/main.yml tasks/managedata.yml tasks/psqlconf.yml
Any idea on how to check all the files from a subdirectory or through the whole role?
PS : I am using cytopia image for ansible-lint, but I have no problem using another, provided it's hosted on dockerhub.
You should certainly be able to pass multiple YAML files as arguments to ansible-lint. I have version 4.1.1a0, and I'm able to use it like this, for example:
anisble-lint -x 106 roles/*/tasks/*.yml
I notice that you seem to have placed a . before your -x 106; that looks like an error. It doesn't look like ansible-lint will accept a directory name as an argument (it doesn't cause it to fail; it just doesn't accomplish anything).
I've tried this both with a locally installed ansible-lint and using the cytopia/ansible-lint image, which appears to perform identically:
docker run --rm -v $PWD:/src -w /src cytopia/ansible-lint -x 106 roles/*/tasks/*.yml
If you want to check all the yaml files, you can use find with exec option, something like this:
find ./ -not -name ".gitlab-ci.yml" -name "*.yml" | xargs ansible-lint -x 106
However ansible-lint -x 106 ./ should work, are you sure that your role really has errors? I've tested it both on ansible-galaxy init generated roles (with meta and all that stuff) and roles which were containing only tasks directory, and it worked every time.
EDIT: I tried creating an error in existing role, replacing "present" with "latest" in package install task
$ ansible-galaxy install geerlingguy.nfs
$ cd ~/.ansible/roles/geerlingguy.nfs
$ sed -i "s/present/latest/g" tasks/setup-RedHat.yml
$ ansible-lint ./
Examining tasks/main.yml of type tasks
Examining tasks/setup-Debian.yml of type tasks
Examining tasks/setup-RedHat.yml of type tasks
Examining handlers/main.yml of type handlers
Examining meta/main.yml of type meta
[403] Package installs should not use latest
tasks/setup-RedHat.yml:2
Task/Handler: Ensure NFS utilities are installed.
and it actually worked, so you may want to run a verbose output to see if actually works, maybe individual yaml file rules are different from whole roles.
When i ran my find-based check i got a lot of extra [204] Lines should be no longer than 160 chars

Go Coverage over multiple package and Gitlab Coverage Badge

I'm trying to display an accurate coverage badge for my gitlab project.
Thing is I have several packages, in gitlab-ci.yml, I run
go test $(go list ./... | grep -v /vendor/) -v -coverprofile .testCoverage.txt
and my output is something like that:
$ go test -coverprofile=coverage.txt -covermode=atomic ./...
ok gitlab.com/[MASKED]/pam 10.333s coverage: 17.2% of statements
ok gitlab.com/[MASKED]/pam/acquisition 0.004s coverage: 57.7% of statements
ok gitlab.com/[MASKED]/pam/acquisition/api 0.005s coverage: 72.1% of statements
ok gitlab.com/[MASKED]/pam/acquisition/ftp 24.936s coverage: 73.1% of statements
ok gitlab.com/[MASKED]/pam/repartition 0.004s coverage: 90.1% of statements
And my Test coverage parsing regex in Gitlab is:
^coverage:\s(\d+(?:\.\d+)?%)
If I check the .testCoverage, I get a lot of lines like that:
gitlab.com/[MASKED]/pam/repartition/repartition.go:54.33,56.5 1 1
So, it gives me a result of 90.1% when it is only the coverage of the last package.
How should I do it ?
According to this answer,
I just needed another command:
go tool cover -func profile.cov
That will give you the result:
✗ go tool cover -func profile.cov
gitlab.com/[MASKED]/pam/acquisition/acquisition.go:17: FetchAll 0.0%
gitlab.com/[MASKED]/pam/acquisition/acquisition.go:32: TransformData 100.0%
gitlab.com/[MASKED]/pam/acquisition/acquisition_mocks.go:13: FetchMeters 0.0%
gitlab.com/[MASKED]/pam/repartition/repartition.go:102: GroupMetersByOperation 100.0%
gitlab.com/[MASKED]/pam/repartition/repartition.go:111: SetProrataRedistributed 71.4%
total: (statements) 68.7%
In gitlab, you can change the regex:
^coverage:\s(\d+(?:\.\d+)?%)
By
\(statements\)(?:\s+)?(\d+(?:\.\d+)?%)
Now, if you have mocks, coverage will include them, so you must remove them following this answer:
go test . -coverprofile profile.cov.tmp
cat profile.cov.tmp | grep -v "_mocks.go" > cover.out
tool cover -func profile.cov
Off course, all your mocks should be in files with suffix : _mocks.go
And it should work.
Hope it helps others!

How to pretty print a matrix in Octave?

I want to create a pretty printed table from a matrix (or column vector).
For Matlab there are several available functions that can do this (such as printmat, array2table, and table), but for Octave I cannot find any.
So instead of:
>> a = rand(3,2)*10;
>> round(a)
ans =
2 10
1 3
2 1
I would like to see:
>> a = rand(3,2)*10;
>> pretty_print(round(a))
THIS THAT
R1 2 10
R2 1 3
R3 2 1
How can I produce a pretty printed table from a matrix?
(Any available package to do so?)
UPDATE
After trying to follow the extremely obtuse package installation instruction from Octave Wiki, I kept getting the error pkg: failed to read package 'econometrics-1.1.1.tar.gz': Couldn't resolve host name. Apparently the windows version isn't able to use the direct installation command (as given on their Wiki). The only way I managed to get it, was by first downloading the package manually into the current working directory of Octave. (See pwd output.) Only then did the install command work.
pkg install econometrics-1.1.1.tar.gz
pkg load econometrics
Yes, there is a prettyprint function in the econometrics package. Once the package is installed and loaded, you can use it like this:
>> a = rand(3,2)*10;
>> prettyprint(round(a),['R1';'R2';'R3'],['THIS';'THAT'])
THIS THAT
R1 2.000 3.000
R2 3.000 4.000
R3 10.000 3.000

VCD dump (VHDL simulation with vcs )

I need help in simulating VHDL code with VCS. What are options available to dump vcd file with vcs for vhdl code .I have tried all the options, which i found on internet. None seems to be working, or i am not doing it in a correct way . A detailed answer would be helpful
Commands tried till now:
vcs test_top -R +vcs+vcdpluson -debug_pp
vcs test_top -R +vcs+vcdpluson -debug_pp -vcd test.vcd
vcs test_top -R +vcs+vcdpluson+vcd_file test.vcd -debug_pp
vcs test_top -V -R +vcs+vcdpluson -debug_pp
I think you need to run the simv command as described in this on page 3.

Resources