Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Conversation

@zhouhao3
Copy link

Signed-off-by: zhouhao [email protected]

@zhouhao3
Copy link
Author

ping @opencontainers/image-tools-maintainers

Makefile Outdated
.PHONY: .gofmt .gotest

PACKAGES = $(shell go list ./... | grep -v /vendor/)
test: .gofmt .gotest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would format be part of testing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to do fmt detection for the format, so I think it belongs to test, and I can also add gofmt commands in the makefile to make formatting adjustments.

Makefile Outdated
test: .gofmt .gotest

.gofmt:
OUT=$$(go fmt $(PACKAGES)); if test -n "$${OUT}"; then echo "$${OUT}" && exit 1; fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use gofmt -s -d. The output as you have it won't be very useful.

@zhouhao3 zhouhao3 changed the title Makefile: add gofmt to test Makefile: add gofmt and govet to test Aug 4, 2017
Makefile Outdated
test: .gofmt .govet .gotest

.gofmt:
OUT=$$(go fmt $(PACKAGES)); if test -n "$${OUT}"; then echo "$${OUT}" && exit 1; fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still isn't using gofmt -d -s. Please use the correct command.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the method you mentioned, but gofmt only supports absolute paths. My idea is to use pwd to get the absolute path of image-tools, but I don't know how to remove the vendor next .
Do you have any advice?

Copy link

@Mashimiao Mashimiao Aug 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about the following?

FILES = $(shell find ./ -name *.go | grep -v vendor)
OUT=$$(gofmt -s -d $(FILES)); if test -n "$${OUT}"; then echo "$${OUT}" && exit 1; fi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good, thanks.

@zhouhao3 zhouhao3 force-pushed the makefile-test-fix branch 2 times, most recently from c49a241 to c720509 Compare August 14, 2017 09:16
@zhouhao3
Copy link
Author

ping @coolljt0725 @stevvooe

@zhouhao3
Copy link
Author

@xiekeyang @stevvooe @coolljt0725 PTAL

@zhouhao3
Copy link
Author

reping @opencontainers/image-tools-maintainers

@zhouhao3
Copy link
Author

@zhouhao3
Copy link
Author

Bump

@zhouhao3
Copy link
Author

Makefile Outdated

UTDIRS = ./image/...
.gotest:
go test -v -race -cover $(UTDIRS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why go test only cover UTDIRS = ./image/... ? the old way is to cover $(shell go list ./... | grep -v /vendor/)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? github.com/opencontainers/image-tools/cmd/oci-image-tool [no test files]
ok github.com/opencontainers/image-tools/image 1.120s coverage: 56.5% of statements
? github.com/opencontainers/image-tools/version [no test files]

Because only the image has the test file, this can improve efficiency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think it's better to keep the old way, because we can't make sure we will not add test file in other dir in future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, updated.

@coolljt0725
Copy link
Member

with this patch and I run make test, I can see

OUT=$(gofmt -s -d ./image/image_test.go ./image/descriptor.go ./image/config.go ./image/manifest_test.go ./image/index.go ./image/autodetect.go ./image/project.go ./image/layout.go ./image/doc.go ./image/manifest.go ./image/image.go ./image/walker.go ./cmd/oci-image-tool/create.go ./cmd/oci-image-tool/main.go ./cmd/oci-image-tool/unpack.go ./cmd/oci-image-tool/validate.go ./version/version.go); if test -n "${OUT}"; then echo "${OUT}" && exit 1; fi

Is this a expected output?

@zhouhao3
Copy link
Author

Is this a expected output?

Yes.The purpose is to detect all the .go file.

@coolljt0725
Copy link
Member

IMO, we can just output the gofmt warning if there is and output nothing if there is no format warning

@zhouhao3
Copy link
Author

I think it should be output, just like test, the process should be displayed.

@Mashimiao
Copy link

Mashimiao commented Nov 10, 2017

LGTM

Approved with PullApprove

1 similar comment
@stevvooe
Copy link
Contributor

stevvooe commented Nov 23, 2017

LGTM

Approved with PullApprove

@stevvooe stevvooe merged commit 5926358 into opencontainers:master Nov 23, 2017
@zhouhao3 zhouhao3 deleted the makefile-test-fix branch November 23, 2017 01:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants