Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update coverage tool #105

Merged
merged 1 commit into from
May 11, 2024
Merged

Update coverage tool #105

merged 1 commit into from
May 11, 2024

Conversation

xhd2015
Copy link
Owner

@xhd2015 xhd2015 commented May 11, 2024

No description provided.

@xhd2015 xhd2015 force-pushed the update-coverage-tool branch 2 times, most recently from bceecf1 to 13df832 Compare May 11, 2024 06:37
@xhd2015 xhd2015 force-pushed the update-coverage-tool branch from 13df832 to 241ff81 Compare May 11, 2024 06:50
@xhd2015 xhd2015 merged commit 960c3c4 into master May 11, 2024
1 check passed
Copy link
Contributor

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

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

@xhd2015 my humble review to your project

@@ -19,6 +19,10 @@ func Main(args []string) {
fmt.Print(strings.TrimPrefix(help, "\n"))
return
}
if cmd != "merge" && cmd != "compact" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a switch here would be more visible, and make sense I think as you will keep adding commands

switch (cmd) {

case "help":
          fmt.Print(strings.TrimPrefix(help, "\n"))
          return

case "merge", "compact":
          // everything is fine

default:
           fmt.Fprintf(os.Stderr, "unrecognized cmd: %s\n", cmd)
           os.Exit(1)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not even sure this code is needed as there is another switch after parsing flags

Copy link
Contributor

Choose a reason for hiding this comment

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

This help command detection here should/should be combined with flagHelp, BTW

}
// if mode == "" {
// mode = covMode
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this code commented and forgotten? Or left behind?

I'm asking just in case, as it looks strange

Copy link
Owner Author

Choose a reason for hiding this comment

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

I forgot to delete them, they were intensionally commented out

mode = "set"
}
mergedCov := coverage.Format(mode, res)
// if mode == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question, here

default:
fmt.Fprintf(os.Stderr, "unrecognized cmd: %s\n", cmd)
os.Exit(1)
}
}

func mergeCover(files []string, outFile string, excludePrefix []string) error {
var mode string
// var mode string
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually when not needed, line is removed not commented

@@ -19,6 +19,10 @@ func Main(args []string) {
fmt.Print(strings.TrimPrefix(help, "\n"))
return
}
if cmd != "merge" && cmd != "compact" {
fmt.Fprintf(os.Stderr, "unrecognized cmd: %s\n", cmd)
return
Copy link
Contributor

Choose a reason for hiding this comment

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

No os.Exit(1) here?

@@ -19,6 +19,10 @@ func Main(args []string) {
fmt.Print(strings.TrimPrefix(help, "\n"))
return
}
if cmd != "merge" && cmd != "compact" {
fmt.Fprintf(os.Stderr, "unrecognized cmd: %s\n", cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

No os. Exit(1) here?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good point

fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
trace.Main(args)
Copy link
Contributor

Choose a reason for hiding this comment

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

May I suggest something?

Here and in previous code, you moved the os.Exit(1) inside the code, it's a bad pattern for me.

The code becomes almost impossible to test, because of the exit.

Maybe you made the change to be consistent with other part of code but I would have suggested to keep the error.

Why did you change ?

Also, this pattern leads to errors as os.Exit(1) can be forgotten

Copy link
Contributor

Choose a reason for hiding this comment

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

I can help in refactoring it, and suggest you something if you agree.

You may accept it or not, but I would like to show what I have in mind.

One question, do you plan to support other exit codes than 1?

Copy link
Contributor

Choose a reason for hiding this comment

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

@xhd2015 please let me know

@xhd2015 xhd2015 deleted the update-coverage-tool branch May 11, 2024 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants