Skip to content

Dotty #5

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI
on: [push, pull_request]
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
java: [11, 16]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: olafurpg/setup-scala@v11
with:
java-version: "adopt@1.${{ matrix.java }}"
- uses: coursier/cache-action@v5
- name: Test
run: |
#run: sbt clean coverage test
sbt test
rm -rf "$HOME/.ivy2/local" || true
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.sbt -name "*.lock" -delete || true
upload_coverage:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: olafurpg/setup-scala@v11
- run: sbt coverageReport codacyCoverage
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ atlassian-ide-plugin.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties

.bloop/
.metals/
.bsp/
.vscode/
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

64 changes: 29 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Scala Expect [![license](http://img.shields.io/:license-MIT-blue.svg)](LICENSE)
[![Scaladoc](http://javadoc-badge.appspot.com/work.martins.simon/scala-expect_2.12.svg?label=scaladoc&style=plastic&maxAge=604800)](https://lasering.github.io/scala-expect/latest/api/work/martins/simon/expect/index.html)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/work.martins.simon/scala-expect_2.12/badge.svg?maxAge=604800)](https://maven-badges.herokuapp.com/maven-central/work.martins.simon/scala-expect_2.12)
[![Scaladoc](https://javadoc.io/badge2/work.martins.simon/scala-expect_3.1/javadoc.svg)](https://lasering.github.io/scala-expect/latest/api/work/martins/simon/expect/index.html)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/work.martins.simon/scala-expect_3.1/badge.svg?maxAge=604800)](https://maven-badges.herokuapp.com/maven-central/work.martins.simon/scala-expect_3.1)

[![Build Status](https://travis-ci.org/Lasering/scala-expect.svg?branch=master&style=plastic&maxAge=604800)](https://travis-ci.org/Lasering/scala-expect)
[![Codacy Badge](https://api.codacy.com/project/badge/coverage/74ba0150f4034c8294e66f6b97a2f69f)](https://www.codacy.com/app/IST-DSI/scala-expect)
[![Codacy Badge](https://api.codacy.com/project/badge/grade/74ba0150f4034c8294e66f6b97a2f69f)](https://www.codacy.com/app/IST-DSI/scala-expect)
[![example workflow](https://github.com/Lasering/scala-expect/actions/workflows/ci.yml/badge.svg)](https://github.com/Lasering/scala-expect/actions)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/156e74a155e64789a241ebb25c227598)](https://www.codacy.com/app/IST-DSI/scala-expect)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/156e74a155e64789a241ebb25c227598)](https://www.codacy.com/gh/Lasering/scala-expect/dashboard)
[![BCH compliance](https://bettercodehub.com/edge/badge/Lasering/scala-expect)](https://bettercodehub.com/results/Lasering/scala-expect)

A Scala implementation of a very small subset of the widely known TCL expect.
Expand All @@ -17,14 +17,13 @@ libraryDependencies += "work.martins.simon" %% "scala-expect" % "6.0.0"
```

## Core
#### [Documentation](../../wiki/Core)
#### Advantages
* Closer to metal / basis for the other flavors.
* Immutable and therefore thread-safe.
* Most errors will be caught at compile time (eg. you won't be able to use a `SendWithRegex` inside a `StringWhen`).
* Most errors will be caught at compile time (eg. you won't be able to use a `Send` with regex inside a `When` matching strings).

#### Disadvantages
* Verbose syntax.
* Pesky commas and parenthesis everywhere.
* Can't cleanly add expect blocks/whens/actions based on a condition.

#### Example
Expand All @@ -34,35 +33,31 @@ import scala.concurrent.ExecutionContext.Implicits.global

val e = new Expect("bc -i", defaultValue = 5)(
ExpectBlock(
StringWhen("For details type `warranty'.")(
Sendln("1 + 2")
)
When("For details type `warranty'.")(
Sendln("1 + 2"),
),
),
ExpectBlock(
RegexWhen("""\n(\d+)\n""".r)(
SendlnWithRegex { m =>
When("""\n(\d+)\n""".r)(
Sendln { m =>
val previousAnswer = m.group(1)
println(s"Got $previousAnswer")
s"$previousAnswer + 3"
}
)
},
),
),
ExpectBlock(
RegexWhen("""\n(\d+)\n""".r)(
ReturningWithRegex(_.group(1).toInt)
)
)
When("""\n(\d+)\n""".r)(
Returning(_.group(1).toInt),
),
),
)
e.run() //Returns 6 inside a Future[Int]
```

## Fluent
#### [Documentation](../../wiki/Fluent)
#### Advantages
* Less verbose syntax:
* StringWhen, RegexWhen, etc is just `when`.
* Returning, ReturningWithRegex, etc is just `returning`.
* Less commas and parenthesis.
* Fewer commas and parenthesis.
* Most errors will be caught at compile time.
* Easy to add expect blocks/whens/actions based on a condition.
* Easy to refactor the creation of expects.
Expand All @@ -71,7 +66,7 @@ e.run() //Returns 6 inside a Future[Int]
#### Disadvantages
* Some overhead since the fluent expect is just a builder for a core expect.
* Mutable - the fluent expect has to maintain a state of the objects that have been built.
* IDE's will easily mess the custom indentation.
* Reformatting code in IDE's will mess the custom indentation.

#### Example
```scala
Expand All @@ -89,24 +84,22 @@ val e = new Expect("bc -i", defaultValue = 5) {
println(s"Got $previousAnswer")
s"$previousAnswer + 3"
}
//This is a shortcut. It works just like the previous expect block.
expect("""\n(\d+)\n""".r)
.returning(_.group(1).toInt)
expect
.when("""\n(\d+)\n""".r)
.returning(_.group(1).toInt)
}
e.run() //Returns 6 inside a Future[Int]
```

## DSL
#### [Documentation](../../wiki/DSL)
#### Advantages
* Code will be indented in blocks so IDE's won't mess the indentation.
* Syntax more close to the TCL expect.
* Easy to add expect blocks/whens/actions based on a condition.
* Easy to refactor the creation of expects.

#### Disadvantages
* Most errors will only be caught at runtime as opposed to compile time.
* More overhead than the fluent expect since it's just a wrapper arround fluent expect.
* More overhead than the fluent expect since it's just a wrapper around fluent expect.
* Mutable - it uses a fluent expect as the backing expect and a mutable stack to keep track of the current context.

#### Example
Expand All @@ -129,13 +122,14 @@ val e = new Expect("bc -i", defaultValue = 5) {
}
}
}
//This is a shortcut. It works just like the previous expect block.
expect("""\n(\d+)\n""".r) {
returning(_.group(1).toInt)
expect {
when("""\n(\d+)\n""".r) {
returning(_.group(1).toInt)
}
}
}
e.run() //Returns 6 inside a Future[Int]
```

## License
Scala Expect is open source and available under the [MIT license](LICENSE).
Scala Expect is open source and available under the [MIT license](LICENSE).
98 changes: 37 additions & 61 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,43 @@ name := "scala-expect"
//==== Compile Options =================================================================================================
//======================================================================================================================
javacOptions ++= Seq("-Xlint", "-encoding", "UTF-8", "-Dfile.encoding=utf-8")
scalaVersion := "2.13.0-M5"
crossScalaVersions := Seq(scalaVersion.value, "2.12.8")

scalaVersion := "3.1.1"
scalacOptions ++= Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:implicitConversions", // Explicitly enables the implicit conversions feature
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xfuture", // Turn on future language features.
"-Xsource:2.14", // Treat compiler input as Scala source for the specified version.
"-Xmigration:2.14.0", // Warn about constructs whose behavior may have changed since version.
"-Xlint", // Enables every warning. scalac -Xlint:help for a list and explanation
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-value-discard", // Warn when non-Unit expression results are unused.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused. TODO this seams to not be working in 2.13
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ybackend-parallelism", "4", // Maximum worker threads for backend
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => Seq(
"-Xexperimental", // Enable experimental extensions.
"-Xsource:2.13", // Treat compiler input as Scala source for the specified version.
"-Xmigration:2.13.0", // Warn about constructs whose behavior may have changed since version.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
)
case _ => Nil
})
//"-explain", // Explain errors in more detail.
//"-explain-types", // Explain type errors in more detail.
"-indent", // Allow significant indentation.
"-new-syntax", // Require `then` and `do` in control expressions.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:future", // better-monadic-for
"-language:implicitConversions", // Allow implicit conversions
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-Werror", // Fail the compilation if there are any warnings.
"-source:future",
"-Xsemanticdb", // Store information in SemanticDB.
"-Ycook-comments", // Cook the comments (type check `@usecase`, etc.)
//"-Ysafe-init", // Ensure safe initialization of objects
"-Yshow-suppressed-errors", // Also show follow-on errors and warnings that are normally suppressed.
// Compile code with classes specific to the given version of the Java platform available on the classpath and emit bytecode for this version.
//"-release", "16",
//"-project-url", git.remoteRepo.value,
)

// These lines ensure that in sbt console or sbt test:console the -Ywarn* and the -Xfatal-warning are not bothersome.
// https://stackoverflow.com/questions/26940253/in-sbt-how-do-you-override-scalacoptions-for-console-in-all-configurations
scalacOptions in (Compile, console) ~= (_ filterNot { option =>
option.startsWith("-Ywarn") || option == "-Xfatal-warnings"
})
scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value
Test / scalacOptions += "-Wconf:msg=is not declared `infix`:s,msg=is declared 'open':s"

// These lines ensure that in sbt console or sbt test:console the -Werror is not bothersome.
Compile / console / scalacOptions ~= (_.filterNot(_.startsWith("-Werror")))
Test / console / scalacOptions := (Compile / console / scalacOptions).value

//======================================================================================================================
//==== Dependencies ====================================================================================================
//======================================================================================================================
val silencerVersion = "1.3.0"
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.3.3",
"com.zaxxer" % "nuprocess" % "1.2.4",
"ch.qos.logback" % "logback-classic" % "1.2.3" % Test,
"org.scalatest" %% "scalatest" % "3.0.6-SNAP5" % Test,
compilerPlugin("com.github.ghik" %% "silencer-plugin" % silencerVersion),
"com.github.ghik" %% "silencer-lib" % silencerVersion % Compile
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("com.typesafe.scala-logging" %% "scala-logging" % "3.9.1")
case Some((2, 12)) => Seq("com.typesafe.scala-logging" %% "scala-logging" % "3.9.0")
case _ => Nil
})
"com.typesafe" % "config" % "1.4.1",
"com.zaxxer" % "nuprocess" % "2.0.2",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
"ch.qos.logback" % "logback-classic" % "1.2.10" % Test,
"org.scalatest" %% "scalatest" % "3.2.11" % Test,
)

// Needed for scoverage snapshot
resolvers += Opts.resolver.sonatypeSnapshots
Expand All @@ -77,22 +54,22 @@ git.useGitDescribe := true
latestReleasedVersion := git.gitDescribedVersion.value.getOrElse("0.1.0")

autoAPIMappings := true //Tell scaladoc to look for API documentation of managed dependencies in their metadata.
scalacOptions in (Compile, doc) ++= Seq(
Compile / doc / scalacOptions ++= Seq(
"-diagrams", // Create inheritance diagrams for classes, traits and packages.
"-groups", // Group similar functions together (based on the @group annotation)
"-implicits", // Document members inherited by implicit conversions.
"-doc-title", name.value.capitalize,
"-doc-version", latestReleasedVersion.value,
"-doc-source-url", s"${homepage.value.get}/tree/v${latestReleasedVersion.value}€{FILE_PATH}.scala",
"-sourcepath", (baseDirectory in ThisBuild).value.getAbsolutePath
"-sourcepath", baseDirectory.value.getAbsolutePath
)
//Define the base URL for the Scaladocs for your library. This will enable clients of your library to automatically
//link against the API documentation using autoAPIMappings.
apiURL := Some(url(s"${homepage.value.get}/${latestReleasedVersion.value}/api/"))

enablePlugins(GhpagesPlugin)
siteSubdirName in SiteScaladoc := s"api/${version.value}"
envVars in ghpagesPushSite := Map("SBT_GHPAGES_COMMIT_MESSAGE" -> s"Add Scaladocs for version ${latestReleasedVersion.value}")
SiteScaladoc / siteSubdirName := s"api/${version.value}"
ghpagesPushSite / envVars := Map("SBT_GHPAGES_COMMIT_MESSAGE" -> s"Add Scaladocs for version ${latestReleasedVersion.value}")
git.remoteRepo := s"[email protected]:Lasering/${name.value}.git"

//======================================================================================================================
Expand All @@ -111,13 +88,12 @@ developers += Developer("Lasering", "Simão Martins", "", url("https://github.co
dependencyUpdatesFailBuild := true

coverageFailOnMinimum := true
coverageMinimum := 90
coverageMinimumStmtTotal := 90
coverageMinimumBranchTotal := 90

releaseCrossBuild := true
releasePublishArtifactsAction := PgpKeys.publishSigned.value

import ReleaseTransformations._
import xerial.sbt.Sonatype.SonatypeCommand
releaseProcess := Seq[ReleaseStep](
releaseStepTask(dependencyUpdates),
checkSnapshotDependencies,
Expand All @@ -129,7 +105,7 @@ releaseProcess := Seq[ReleaseStep](
tagRelease,
releaseStepTask(ghpagesPushSite),
publishArtifacts,
releaseStepCommand(SonatypeCommand.sonatypeReleaseAll),
releaseStepCommand("sonatypeReleaseAll"),
pushChanges,
setNextVersion
)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.2.7
sbt.version = 1.6.2
18 changes: 7 additions & 11 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
logLevel := Level.Warn

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.9")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0-M5")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "2.112")

addCompilerPlugin("io.tryp" % "splain" % "0.3.4" cross CrossVersion.patch)
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.1.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.0-M4")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "3.0.3")
3 changes: 0 additions & 3 deletions src/main/scala/work/martins/simon/expect/EndOfFile.scala

This file was deleted.

This file was deleted.

Loading