-
-
Notifications
You must be signed in to change notification settings - Fork 9
Scala 3 support #55
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
Merged
ErikSchierboom
merged 3 commits into
exercism:main
from
grzegorz-bielski:scala3-support
Aug 14, 2024
Merged
Scala 3 support #55
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| version = "3.8.2" | ||
| align.preset = most | ||
| maxColumn = 160 | ||
| trailingCommas = always | ||
| continuationIndent.callSite = 2 | ||
| continuationIndent.defnSite = 2 | ||
| runner.dialect = scala3 | ||
| rewrite.scala3.convertToNewSyntax = yes | ||
| rewrite.scala3.removeOptionalBraces = yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,15 @@ | ||
| import sbt._ | ||
|
|
||
| object Dependencies { | ||
| val monocleVersion = "2.0.0" | ||
| lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.2.19" | ||
| lazy val scalaCheck = "org.scalatestplus" %% "scalacheck-1-18" % "3.2.19.0" | ||
|
|
||
| lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.2.10" | ||
| lazy val scalaCheck = "org.scalatestplus" %% "scalacheck-1-15" % "3.2.9.0" | ||
| val monocleVersion = "3.2.0" | ||
|
|
||
| lazy val monocle = Seq( | ||
| "com.github.julien-truffaut" %% "monocle-core" % monocleVersion, | ||
| "com.github.julien-truffaut" %% "monocle-macro" % monocleVersion | ||
| "dev.optics" %% "monocle-core" % monocleVersion, | ||
| "dev.optics" %% "monocle-macro" % monocleVersion | ||
| ) | ||
|
|
||
| lazy val json = "org.json" % "json" % "20220320" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| sbt.version=1.5.7 | ||
| sbt.version=1.10.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0") | ||
| addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.2.0") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,80 +1,93 @@ | ||
| import org.json.{JSONArray, JSONObject, XML} | ||
|
|
||
| import java.io.{File, FileFilter, FileWriter} | ||
| import scala.io.Source | ||
|
|
||
| object Application extends App { | ||
| require(args.length == 3, s"Invalid number of arguments. Expected: <build-log-file-path> <test-results-folder-path> <results-json-file-path>, got: ${args.mkString("", ", ", "")}") | ||
| val buildLogFilePath = args(0) | ||
| val testResultsFolderPath = args(1) | ||
| val resultsJsonFilePath = args(2) | ||
|
|
||
| val testResultsFolder = new File(testResultsFolderPath) | ||
| if (!testResultsFolder.isDirectory) { | ||
| throw new RuntimeException(s"Expected $testResultsFolderPath to be a folder") | ||
| } | ||
| val testResultFiles = testResultsFolder.listFiles(new FileFilter() { | ||
| override def accept(file: File): Boolean = file.getName.matches("TEST-.*\\.xml") | ||
| }).toList | ||
| writeResultsJSON(buildLogFilePath, testResultFiles, resultsJsonFilePath) | ||
| object Application: | ||
| @main | ||
| def run( | ||
| buildLogFilePath: String, | ||
| testResultsFolderPath: String, | ||
| resultsJsonFilePath: String, | ||
| ): Unit = | ||
| val testResultsFolder = new File(testResultsFolderPath) | ||
| if !testResultsFolder.isDirectory then | ||
| throw new RuntimeException( | ||
| s"Expected $testResultsFolderPath to be a folder", | ||
| ) | ||
| val testResultFiles = testResultsFolder | ||
| .listFiles( | ||
| new FileFilter(): | ||
| override def accept(file: File): Boolean = | ||
| file.getName.matches("TEST-.*\\.xml"), | ||
| ) | ||
| .toList | ||
| writeResultsJSON(buildLogFilePath, testResultFiles, resultsJsonFilePath) | ||
|
|
||
| def writeResultsJSON(buildLogFilePath: String, testResultsFiles: List[File], resultsJsonFilePath: String): Unit = { | ||
| val resultsJsonFile = new File(resultsJsonFilePath) | ||
| def writeResultsJSON( | ||
| buildLogFilePath: String, | ||
| testResultsFiles: List[File], | ||
| resultsJsonFilePath: String, | ||
| ): Unit = | ||
| val resultsJsonFile = new File(resultsJsonFilePath) | ||
| val resultsJsonFileWriter = new FileWriter(resultsJsonFile) | ||
|
|
||
| val json = toExercismJSON(buildLogFilePath, testResultsFiles) | ||
| json.write(resultsJsonFileWriter) | ||
| resultsJsonFileWriter.close() | ||
| } | ||
|
|
||
| def getTestSuiteObject(testResultsFile: File): JSONObject = { | ||
| def getTestSuiteObject(testResultsFile: File): JSONObject = | ||
| val bufferedSource = Source.fromFile(testResultsFile) | ||
| val xml = bufferedSource.mkString | ||
| val xml = bufferedSource.mkString | ||
| bufferedSource.close | ||
| XML.toJSONObject(xml).getJSONObject("testsuite") | ||
| } | ||
|
|
||
| // log, not xml | ||
| def findErrorsInLog(buildLogFilePath: String): String = { | ||
| def findErrorsInLog(buildLogFilePath: String): String = | ||
| val fileSource = Source.fromFile(buildLogFilePath) | ||
| val rawContent = fileSource.mkString | ||
| fileSource.close | ||
| if (rawContent.contains("error: ")) rawContent else "" | ||
| } | ||
| if rawContent.contains("Error: ") then rawContent else "" | ||
|
|
||
| def toTestCaseJSON(testCase: JSONObject): JSONObject = { | ||
| def toTestCaseJSON(testCase: JSONObject): JSONObject = | ||
| val fail = testCase.optJSONObject("failure") | ||
| new JSONObject() | ||
| .put("name", testCase.get("name").toString) | ||
| .put("status", if (fail != null) "fail" else "pass") | ||
| .put("message", if (fail != null) fail.getString("message") else JSONObject.NULL) | ||
| .put("status", if fail != null then "fail" else "pass") | ||
| .put( | ||
| "message", | ||
| if fail != null then fail.getString("message") else JSONObject.NULL, | ||
| ) | ||
| .put("output", JSONObject.NULL) | ||
| .put("test_code", JSONObject.NULL) | ||
| } | ||
|
|
||
| def toExercismJSON(buildLogFilePath: String, testResultsFiles: List[File]): JSONObject = { | ||
| val baseObject = new JSONObject().put("version", 2) | ||
| def toExercismJSON( | ||
| buildLogFilePath: String, | ||
| testResultsFiles: List[File], | ||
| ): JSONObject = | ||
| val baseObject = new JSONObject().put("version", 2) | ||
| val errorMessage = findErrorsInLog(buildLogFilePath) | ||
| if (errorMessage.nonEmpty) { | ||
| println("errorMessage" -> errorMessage) | ||
| if errorMessage.nonEmpty then | ||
| baseObject | ||
| .put("status", "error") | ||
| .put("message", errorMessage) | ||
| } else { | ||
| val (failuresCount, testCases) = testResultsFiles.map(getTestSuiteObject) | ||
| else | ||
| val (failuresCount, testCases) = testResultsFiles | ||
| .map(getTestSuiteObject) | ||
| .filter(testSuite => testSuite.has("testcase")) | ||
| .map(testSuite => { | ||
| val failuresCount = testSuite.getInt("failures") | ||
| val testcase = testSuite.get("testcase") | ||
| val testCases: Array[JSONObject] = testcase match { | ||
| case arr: JSONArray => (0 until arr.length).map(idx => toTestCaseJSON(arr.getJSONObject(idx))).toArray | ||
| .map(testSuite => | ||
| val failuresCount = testSuite.getInt("failures") | ||
| val testcase = testSuite.get("testcase") | ||
| val testCases: Array[JSONObject] = testcase match | ||
| case arr: JSONArray => | ||
| (0 until arr.length) | ||
| .map(idx => toTestCaseJSON(arr.getJSONObject(idx))) | ||
| .toArray | ||
| case obj: JSONObject => Array(toTestCaseJSON(obj)) | ||
| } | ||
| (failuresCount, testCases) | ||
| }).reduce((a, b) => (a._1 + b._1, Array.concat(a._2, b._2))) | ||
| (failuresCount, testCases), | ||
| ) | ||
| .reduce((a, b) => (a._1 + b._1, Array.concat(a._2, b._2))) | ||
| baseObject | ||
| .put("status", if (failuresCount > 0) "fail" else "pass") | ||
| .put("status", if failuresCount > 0 then "fail" else "pass") | ||
| .put("message", JSONObject.NULL) | ||
| .put("tests", testCases) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {"message":"/solution/src/test/scala/ExampleEmptyFileTest.scala:8: error: not found: value Leap\n Leap.leapYear(2015) should be (false)\n ^\n/solution/src/test/scala/ExampleEmptyFileTest.scala:13: error: not found: value Leap\n Leap.leapYear(1996) should be (true)\n ^\n/solution/src/test/scala/ExampleEmptyFileTest.scala:18: error: not found: value Leap\n Leap.leapYear(2100) should be (false)\n ^\n/solution/src/test/scala/ExampleEmptyFileTest.scala:23: error: not found: value Leap\n Leap.leapYear(2000) should be (true)\n ^\n4 errors\n","version":2,"status":"error"} | ||
| {"message":"\u001b[31m\u001b[31m-- [E006] Not Found Error: /solution/src/test/scala/ExampleEmptyFileTest.scala:8:4 \u001b[0m\u001b[0m\n\u001b[31m8 |\u001b[0m Leap.leapYear(\u001b[31m2015\u001b[0m) should be (\u001b[31mfalse\u001b[0m)\n\u001b[31m\u001b[31m |\u001b[0m ^^^^\u001b[0m\n\u001b[31m |\u001b[0m Not found: Leap - did you mean trap?\n\u001b[31m |\u001b[0m\n\u001b[31m |\u001b[0m longer explanation available when compiling with `-explain`\n\u001b[31m\u001b[31m-- [E006] Not Found Error: /solution/src/test/scala/ExampleEmptyFileTest.scala:13:4 \u001b[0m\u001b[0m\n\u001b[31m13 |\u001b[0m Leap.leapYear(\u001b[31m1996\u001b[0m) should be (\u001b[31mtrue\u001b[0m)\n\u001b[31m\u001b[31m |\u001b[0m ^^^^\u001b[0m\n\u001b[31m |\u001b[0m Not found: Leap - did you mean trap?\n\u001b[31m |\u001b[0m\n\u001b[31m |\u001b[0m longer explanation available when compiling with `-explain`\n\u001b[31m\u001b[31m-- [E006] Not Found Error: /solution/src/test/scala/ExampleEmptyFileTest.scala:18:4 \u001b[0m\u001b[0m\n\u001b[31m18 |\u001b[0m Leap.leapYear(\u001b[31m2100\u001b[0m) should be (\u001b[31mfalse\u001b[0m)\n\u001b[31m\u001b[31m |\u001b[0m ^^^^\u001b[0m\n\u001b[31m |\u001b[0m Not found: Leap - did you mean trap?\n\u001b[31m |\u001b[0m\n\u001b[31m |\u001b[0m longer explanation available when compiling with `-explain`\n\u001b[31m\u001b[31m-- [E006] Not Found Error: /solution/src/test/scala/ExampleEmptyFileTest.scala:23:4 \u001b[0m\u001b[0m\n\u001b[31m23 |\u001b[0m Leap.leapYear(\u001b[31m2000\u001b[0m) should be (\u001b[31mtrue\u001b[0m)\n\u001b[31m\u001b[31m |\u001b[0m ^^^^\u001b[0m\n\u001b[31m |\u001b[0m Not found: Leap - did you mean trap?\n\u001b[31m |\u001b[0m\n\u001b[31m |\u001b[0m longer explanation available when compiling with `-explain`\n\u001b[33m\u001b[33m-- Warning: /solution/src/test/scala/ExampleEmptyFileTest.scala:8:24 -------\u001b[0m\u001b[0m\n\u001b[33m8 |\u001b[0m Leap.leapYear(\u001b[31m2015\u001b[0m) should be (\u001b[31mfalse\u001b[0m)\n\u001b[33m\u001b[33m |\u001b[0m ^^^^^^\u001b[0m\n\u001b[33m |\u001b[0mAlphanumeric method should is not declared \u001b[33minfix\u001b[0m; it should not be used as infix operator.\n\u001b[33m |\u001b[0mInstead, use method syntax .should(...) or backticked identifier `should`.\n\u001b[33m |\u001b[0mThe latter can be rewritten automatically under -rewrite -source 3.4-migration.\n\u001b[33m\u001b[33m-- Warning: /solution/src/test/scala/ExampleEmptyFileTest.scala:13:24 ------\u001b[0m\u001b[0m\n\u001b[33m13 |\u001b[0m Leap.leapYear(\u001b[31m1996\u001b[0m) should be (\u001b[31mtrue\u001b[0m)\n\u001b[33m\u001b[33m |\u001b[0m ^^^^^^\u001b[0m\n\u001b[33m |\u001b[0mAlphanumeric method should is not declared \u001b[33minfix\u001b[0m; it should not be used as infix operator.\n\u001b[33m |\u001b[0mInstead, use method syntax .should(...) or backticked identifier `should`.\n\u001b[33m |\u001b[0mThe latter can be rewritten automatically under -rewrite -source 3.4-migration.\n\u001b[33m\u001b[33m-- Warning: /solution/src/test/scala/ExampleEmptyFileTest.scala:18:24 ------\u001b[0m\u001b[0m\n\u001b[33m18 |\u001b[0m Leap.leapYear(\u001b[31m2100\u001b[0m) should be (\u001b[31mfalse\u001b[0m)\n\u001b[33m\u001b[33m |\u001b[0m ^^^^^^\u001b[0m\n\u001b[33m |\u001b[0mAlphanumeric method should is not declared \u001b[33minfix\u001b[0m; it should not be used as infix operator.\n\u001b[33m |\u001b[0mInstead, use method syntax .should(...) or backticked identifier `should`.\n\u001b[33m |\u001b[0mThe latter can be rewritten automatically under -rewrite -source 3.4-migration.\n\u001b[33m\u001b[33m-- Warning: /solution/src/test/scala/ExampleEmptyFileTest.scala:23:24 ------\u001b[0m\u001b[0m\n\u001b[33m23 |\u001b[0m Leap.leapYear(\u001b[31m2000\u001b[0m) should be (\u001b[31mtrue\u001b[0m)\n\u001b[33m\u001b[33m |\u001b[0m ^^^^^^\u001b[0m\n\u001b[33m |\u001b[0mAlphanumeric method should is not declared \u001b[33minfix\u001b[0m; it should not be used as infix operator.\n\u001b[33m |\u001b[0mInstead, use method syntax .should(...) or backticked identifier `should`.\n\u001b[33m |\u001b[0mThe latter can be rewritten automatically under -rewrite -source 3.4-migration.\n4 warnings found\n4 errors found\n","version":2,"status":"error"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1 @@ | ||
| { | ||
| "tests": [ | ||
| { | ||
| "output": null, | ||
| "name": "two-one", | ||
| "test_code": null, | ||
| "message": null, | ||
| "status": "pass" | ||
| }, | ||
| { | ||
| "output": null, | ||
| "name": "one-one", | ||
| "test_code": null, | ||
| "message": null, | ||
| "status": "pass" | ||
| }, | ||
| { | ||
| "output": null, | ||
| "name": "one-two", | ||
| "test_code": null, | ||
| "message": null, | ||
| "status": "pass" | ||
| } | ||
| ], | ||
| "message": null, | ||
| "version": 2, | ||
| "status": "pass" | ||
| } | ||
| {"tests":[{"output":null,"name":"one-one","test_code":null,"message":null,"status":"pass"},{"output":null,"name":"two-one","test_code":null,"message":null,"status":"pass"},{"output":null,"name":"one-two","test_code":null,"message":null,"status":"pass"}],"message":null,"version":2,"status":"pass"} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.