Compare commits

...

64 Commits

Author SHA1 Message Date
Emily Bache
69f2361ab5
Merge pull request #659 from RalfComtesse/scala_and_texttest
Scala and texttest
2025-10-08 13:15:18 +00:00
Ralf Comtesse
95fe7d55ff approvaltests/gildedrose.approved.txt removed 2025-10-06 16:52:03 +02:00
Ralf Comtesse
96623040a5 approvaltests/gildedrose.approved.txt removed 2025-10-06 16:38:00 +02:00
Ralf Comtesse
f5242736c7 setup approval tests with golden master using scalatest 2025-10-06 16:37:03 +02:00
Ralf Comtesse
1aa971f885 approvaltests/gildedrose.approved.txt removed 2025-10-06 16:26:26 +02:00
Ralf Comtesse
1ddc66a98a setup approval tests with golden master using scalatest 2025-10-06 16:24:36 +02:00
Ralf Comtesse
24a86e2df1 cleaned up texttest_rig.py 2025-10-06 16:24:36 +02:00
Ralf Comtesse
e838a75365 suppressed sbt specific output 2025-10-06 15:51:58 +02:00
Ralf Comtesse
e8a80b8034 removed approvaltests directory 2025-10-06 15:36:24 +02:00
Ralf Comtesse
f8262a4396 setup approval tests with golden master using scalatest 2025-10-06 15:33:29 +02:00
Ralf Comtesse
24c992acb7 cleaned up texttest_rig.py 2025-10-06 15:33:26 +02:00
Ralf Comtesse
f00df0e4ae added .bloop and vscode directories for scala to .gitignore 2025-10-06 15:33:01 +02:00
Ralf Comtesse
d745f6452a * converted Java TextestFixture to scala 2025-10-06 15:33:01 +02:00
Ralf Comtesse
86a7bbaf6d updated .gitignore 2025-10-06 15:33:01 +02:00
Ralf Comtesse
f2da40423d removed old approvaltest directory 2025-10-06 12:19:41 +02:00
Ralf Comtesse
f3e62e2bbb merged with origin 2025-10-06 12:06:57 +02:00
Ralf Comtesse
0a08d92b95 removed unnecessary comment markers at line ends in TexttestFixture.scala 2025-10-06 12:06:28 +02:00
Ralf Comtesse
23dba8c86a setup approval tests with golden master using scalatest 2025-10-06 12:06:28 +02:00
Ralf Comtesse
c31a479ecb removed extra, unnecessary run in texttest_rig.py 2025-10-06 12:06:28 +02:00
Ralf Comtesse
144bb63912 cleaned up texttest_rig.py 2025-10-06 12:06:28 +02:00
Ralf Comtesse
cf00776b11 added .bloop and vscode directories for scala to .gitignore 2025-10-06 12:06:28 +02:00
Ralf Comtesse
46d0586658 * converted Java TextestFixture to scala 2025-10-06 12:06:28 +02:00
Ralf Comtesse
3655d5edc7 cleaned up texttest/config.gr 2025-10-06 10:34:40 +02:00
Ralf Comtesse
0fadc91051 removed approvaltest directory 2025-10-06 10:27:03 +02:00
Ralf Comtesse
96ced26ea0 Merge remote-tracking branch 'origin/scala_and_texttest' into scala_and_texttest
# Conflicts:
#	scala/.gitignore
#	scala/README.md
#	scala/src/test/scala/com/gildedrose/GildedRoseApprovalTest.scala
#	scala/src/test/scala/com/gildedrose/TexttestFixture.scala
2025-10-06 10:18:28 +02:00
Ralf Comtesse
c0d94a3f4b housekeeping 2025-10-06 10:13:53 +02:00
Ralf Comtesse
38c63d80f4 Updated README.txt 2025-10-06 10:03:15 +02:00
Ralf Comtesse
639c709c99 Housekeeping 2025-10-06 08:22:51 +02:00
Ralf Comtesse
5ed38a6ae3 removed example output from approval tests 2025-10-05 21:18:06 +02:00
Ralf Comtesse
2b32087843 before cleanup without java tests 2025-10-05 21:16:47 +02:00
Ralf Comtesse
2e0e557c6e * ignored old approval test
* added sbt-jupiter-interface
2025-10-04 21:19:41 +02:00
Ralf Comtesse
9456bfce1f all approval tests running with the java approval test framework 2025-10-01 08:31:06 +02:00
Ralf Comtesse
36acc45c3e dependencies added to sbt to compile GildedRoseApprovalTest.java 2025-10-01 07:32:09 +02:00
Ralf Comtesse
c27ad4786c cleaned up stdout.gr 2025-09-29 22:16:04 +02:00
Ralf Comtesse
9ef3cf93f2 cleaned up config.gr 2025-09-29 22:16:04 +02:00
Ralf Comtesse
217732ba8f added template with the result of the first run of the approval tests 2025-09-29 22:16:04 +02:00
Ralf Comtesse
511d34b48e removed obsolete .gitignore in projects directory 2025-09-29 22:16:04 +02:00
Ralf Comtesse
cd89faa9c0 added approvaltests/gildedrose.approved.txt.bak as template for approval file 2025-09-29 22:16:04 +02:00
Ralf Comtesse
fd027c4187 updated README.md for scala 2025-09-29 22:16:04 +02:00
Ralf Comtesse
a4b2b94a63 clean-up of texttest/config.gr 2025-09-29 22:16:04 +02:00
Ralf Comtesse
acfb870700 removed unnecessary comment markers at line ends in TexttestFixture.scala 2025-09-29 22:16:04 +02:00
Ralf Comtesse
f392c528dc setup approval tests with golden master using scalatest 2025-09-29 22:16:04 +02:00
Ralf Comtesse
86bcfd62a7 removed extra, unnecessary run in texttest_rig.py 2025-09-29 22:16:04 +02:00
Ralf Comtesse
c3692a1e82 cleaned up texttest_rig.py 2025-09-29 22:16:04 +02:00
Ralf Comtesse
4f621844ba added .bloop and vscode directories for scala to .gitignore 2025-09-29 22:16:04 +02:00
Ralf Comtesse
c9919d1a1b * converted Java TextestFixture to scala 2025-09-29 22:16:04 +02:00
Ralf Comtesse
5b88a3d78b * bumped sbt version to 1.10.10
*  bumped scala version to 3.7.3
2025-09-29 22:16:04 +02:00
Ralf Comtesse
618e6df491 added .bsp to .gitignore 2025-09-29 22:16:04 +02:00
Ralf Comtesse
e102f17c4b cleaned up stdout.gr 2025-09-29 21:01:15 +02:00
Ralf Comtesse
d61900953d cleaned up config.gr 2025-09-29 20:56:05 +02:00
Ralf Comtesse
dab7625ea0 added template with the result of the first run of the approval tests 2025-09-29 20:47:25 +02:00
Ralf Comtesse
2e4a1d1553 removed obsolete .gitignore in projects directory 2025-09-29 07:52:12 +02:00
Ralf Comtesse
f21abadd44 added approvaltests/gildedrose.approved.txt.bak as template for approval file 2025-09-28 14:46:48 +02:00
Ralf Comtesse
1035cfdc30 updated README.md for scala 2025-09-28 14:45:58 +02:00
Ralf Comtesse
84c024e13d clean-up of texttest/config.gr 2025-09-28 14:45:13 +02:00
Ralf Comtesse
db3b9ef3da removed unnecessary comment markers at line ends in TexttestFixture.scala 2025-09-28 10:49:02 +02:00
Ralf Comtesse
ced0cf4c31 setup approval tests with golden master using scalatest 2025-09-27 12:54:04 +02:00
Ralf Comtesse
5904431bde removed extra, unnecessary run in texttest_rig.py 2025-09-26 21:14:05 +02:00
Ralf Comtesse
3083e909b6 cleaned up texttest_rig.py 2025-09-26 20:06:13 +02:00
Ralf Comtesse
7aae423d53 added .bloop and vscode directories for scala to .gitignore 2025-09-26 19:47:35 +02:00
Ralf Comtesse
179990c1b1 * converted Java TextestFixture to scala 2025-09-26 17:55:02 +02:00
Ralf Comtesse
eb8c92055f * bumped sbt version to 1.10.10
*  bumped scala version to 3.7.3
2025-09-26 17:32:52 +02:00
Ralf Comtesse
fb0c7b1331 Merge branch 'main' into scala_and_texttext 2025-09-26 17:30:38 +02:00
Ralf Comtesse
2685188ec8 added .bsp to .gitignore 2025-09-26 17:23:32 +02:00
13 changed files with 156 additions and 25 deletions

13
scala/.gitignore vendored
View File

@ -1,4 +1,5 @@
/bin/
lib/
# OSX Finder
.DS_Store
@ -6,6 +7,17 @@
# IntelliJ
.idea
*.iml
.bsp
.bloop
#vscode
.vscode
.metals
.scala-build
metals.sbt
# Eclipse
.worksheet
@ -17,3 +29,4 @@
.classpath
target/
approvaltests/gildedrose.testresult.txt

View File

@ -20,3 +20,26 @@ sbt "run 10"
``` cmd
sbt test
```
## Run approval tests
The approval test can be found in the src/test/scala/GildedRoseApprovalTest.scala. It uses the approval test framework from https://github.com/approvals/ApprovalTests.Java.
The initial run will be a failing test and suggests an output to accept as the first approved version. Each subsequent run of the test will succeed until the output from the test changes.
To approve a new version, simply accept some or all diffs between the existing approved files and the newly generated output.
Approval tests are part of the test suite triggered by "sbt test".
``` cmd
sbt test
```
## Run texttest version of approval tests
To run the texttest version, first edit the texttest configuration file. It contains to sections for scala that need to be uncommented.
* the executable and interpreter lines to run texttest_rig.py to trigger an sbt run
* the four lines in the run_dependent_text section to ignore sbt's info and success lines in the output.
Be aware that running the texttest version is somewhat slow since starting sbt takes some time.

View File

@ -1,11 +1,15 @@
val scala3Version = "3.6.4"
val scala3Version = "3.7.3"
lazy val root = project
.in(file("."))
.settings(
name := "GildedRose",
version := "1.0",
scalaVersion := scala3Version,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.19" % "test"
name := "GildedRose",
version := "1.0",
scalaVersion := scala3Version,
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"com.approvaltests" % "approvaltests" % "25.4.3" % Test,
"com.github.sbt.junit" % "jupiter-interface" % "0.15.1" % Test
),
testOptions += Tests.Argument(TestFrameworks.JUnit)
)

View File

@ -1,2 +0,0 @@
project/
target/

View File

@ -1 +1 @@
sbt.version=1.10.10
sbt.version=1.11.6

View File

@ -0,0 +1 @@
addSbtPlugin("com.github.sbt.junit" % "sbt-jupiter-interface" % "0.15.1")

View File

@ -1,5 +1,5 @@
package com.gildedrose
class Item(val name: String, var sellIn: Int, var quality: Int) {
case class Item(name: String, var sellIn: Int, var quality: Int) {
}

View File

@ -3,16 +3,16 @@ package com.gildedrose
object Main {
def main(args: Array[String]): Unit = {
val items = Array[Item](
new Item("+5 Dexterity Vest", 10, 20),
new Item("Aged Brie", 2, 0),
new Item("Elixir of the Mongoose", 5, 7),
new Item("Sulfuras, Hand of Ragnaros", 0, 80),
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
Item("+5 Dexterity Vest", 10, 20),
Item("Aged Brie", 2, 0),
Item("Elixir of the Mongoose", 5, 7),
Item("Sulfuras, Hand of Ragnaros", 0, 80),
Item("Sulfuras, Hand of Ragnaros", -1, 80),
Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
// this conjured item does not work properly yet
new Item("Conjured Mana Cake", 3, 6)
Item("Conjured Mana Cake", 3, 6)
)
val app = new GildedRose(items)

View File

@ -0,0 +1,38 @@
package com.gildedrose
import org.approvaltests.Approvals
import org.approvaltests.reporters.DiffReporter
import org.approvaltests.reporters.UseReporter
import org.junit.jupiter.api.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.PrintStream
@UseReporter(Array(classOf[DiffReporter]))
class GildedRoseApprovalTest {
@Test
def foo(): Unit = {
val items: Array[Item] = Array(Item("foo", 0, 0))
val app: GildedRose = new GildedRose(items)
app.updateQuality()
Approvals.verifyAll("Items", items)
}
@Test
def thirtyDays(): Unit = {
val fakeoutput: ByteArrayOutputStream = new ByteArrayOutputStream()
System.setOut(new PrintStream(fakeoutput))
System.setIn(new ByteArrayInputStream("a\n".getBytes()))
val args: Array[String] = Array("30")
TexttestFixture.main(args)
val output: String = fakeoutput.toString()
Approvals.verify(output)
}
}

View File

@ -4,10 +4,10 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class GildedRoseTest extends AnyFlatSpec with Matchers {
it should "foo" in {
val items = Array[Item](new Item("foo", 0, 0))
val app = new GildedRose(items)
app.updateQuality()
app.items(0).name should equal ("fixme")
}
it should "foo" in {
val items = Array[Item](Item("foo", 0, 0))
val app = new GildedRose(items)
app.updateQuality()
app.items(0).name should equal("fixme")
}
}

View File

@ -0,0 +1,34 @@
package com.gildedrose
object TexttestFixture {
def main(args: Array[String]): Unit = {
System.out.println("OMGHAI!")
val items = Array[Item](
Item("+5 Dexterity Vest", 10, 20),
Item("Aged Brie", 2, 0),
Item("Elixir of the Mongoose", 5, 7),
Item("Sulfuras, Hand of Ragnaros", 0, 80),
Item("Sulfuras, Hand of Ragnaros", -1, 80),
Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), // this conjured item does not work properly yet
Item("Conjured Mana Cake", 3, 6)
)
val app = new GildedRose(items)
var days = 2
if (args.nonEmpty) days = args(0).toInt + 1
for (i <- 0 until days) {
System.out.println("-------- day " + i + " --------")
System.out.println("name, sellIn, quality")
for (item <- items) {
System.out.println(s"${item.name}, ${item.sellIn}, ${item.quality}")
}
System.out.println()
app.updateQuality()
}
}
}

14
scala/texttest_rig.py Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env python
"""
This script uses sbt to execute the TexttestFixture.
It is designed to be used by TextTest and specified in the file 'texttests/config.gr' in this repo.
It is more convenient for TextTest to use since Gradle needs
several arguments in addition to the one the TextTest fixture needs.
"""
import os
import subprocess
import sys
args = " ".join(sys.argv[1:])
TEXTTEST_HOME = os.environ.get("TEXTTEST_HOME", os.getcwd())
subprocess.run(f"""(cd {TEXTTEST_HOME}/scala/; sbt -warn "Test / runMain com.gildedrose.TexttestFixture {args}") """, shell=True)

View File

@ -70,4 +70,10 @@ interpreter:ruby
# Settings for the Odin version
#executable:${TEXTTEST_HOME}/odin/gilded_rose<include your OS executable extension here>
# Settings for the scala version using sbt wrapped in a python script
# executable:${TEXTTEST_HOME}/scala/texttest_rig.py
# interpreter:python
filename_convention_scheme:standard