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

Replace print commands without final newline #6

Open
tehsphinx opened this issue Jan 3, 2020 · 6 comments
Open

Replace print commands without final newline #6

tehsphinx opened this issue Jan 3, 2020 · 6 comments
Labels
x:action/fix Fix an issue x:knowledge/elementary Little Exercism knowledge required x:module/test-runner Work on Test Runners x:size/medium Medium amount of work x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises)

Comments

@tehsphinx
Copy link
Member

tehsphinx commented Jan 3, 2020

The commands print, fmt.Print, fmt.Printf and maybe others currently destroy the output of go test --json as they have no final newline.

We should report that to be fixed in go test but for the time being we will replace these commands in students solutions with println / fmt.Println.

My current suggestion would be to add some sed commands to the test runner before executing the tests. This could also be done using the AST library to manipulate the AST if someone wants to dig into that.

Here the replace table I'd recommend to avoid having to remove/add imports:

  • print -> println
  • fmt.Print -> fmt.Println
  • fmt.Printf(...) -> fmt.Println(fmt.Sprintf(...))
@junedev junedev added x:action/fix Fix an issue x:knowledge/elementary Little Exercism knowledge required x:module/test-runner Work on Test Runners x:size/medium Medium amount of work x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises) labels Oct 6, 2021
@mhutter
Copy link

mhutter commented Oct 27, 2021

Upstream issue: golang/go#26325

@junedev
Copy link
Member

junedev commented Oct 27, 2021

@mhutter Thanks a lot for finding the correct issues in the Go repo!

@jmrunkle
Copy link
Contributor

jmrunkle commented Dec 6, 2021

@junedev - is this something we still want to do?

@junedev
Copy link
Member

junedev commented Dec 6, 2021

Imo not a very high priority but in general yes. There is no solution of the uptream issue in sight so the problem described here still exists.

@junedev
Copy link
Member

junedev commented Feb 9, 2022

I am pondering some edge cases of the replacement logic mentioned above.

  • print would also be included in fmt.Sprintf which we don't want to change, even print( is also part of fmt.Sprint so to do this correctly we would also need something like "no character before the print( as condition as well
  • to rewrite something like fmt.Printf("%s)", x) correctly, we would need to know which bracket is the closing bracket of the function call which is hard to tell, maybe we could try to find the string after the opening bracket and add a line break there instead of replacing the whole expression

@TheFranconianCoder
Copy link

This seems to be fixed with go 1.20 for --short --json. Still a problem with -v --json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:action/fix Fix an issue x:knowledge/elementary Little Exercism knowledge required x:module/test-runner Work on Test Runners x:size/medium Medium amount of work x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises)
Projects
None yet
Development

No branches or pull requests

5 participants