From 797503620ccd812af51bf06d965382231a4d1659 Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Wed, 4 Sep 2024 13:31:37 +0200 Subject: [PATCH 1/9] Update the Scala CLI as an implementation of the `scala` command doc --- website/docs/reference/scala-command/index.md | 79 +++++++++++++++---- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/website/docs/reference/scala-command/index.md b/website/docs/reference/scala-command/index.md index 9358ff6da3..4c6055bf35 100644 --- a/website/docs/reference/scala-command/index.md +++ b/website/docs/reference/scala-command/index.md @@ -2,48 +2,93 @@ title: Scala CLI as scala --- -# Scala CLI as implementation for `scala` command +# Scala CLI as an implementation of the `scala` command -Scala CLI is designed to be a replacement for script that is currently installed as `scala`. Since Scala CLI is -feature-packed we do not want to expose all the features and options to the whole Scala public at the very start. Why is -that? +As of Scala 3.5.0, Scala CLI has become the official runner for the language, +replacing the old runner implementation under the `scala` script. -- We want to make sure that the options / commands are stable -- We do not want to overwhelm users with multiple options and commands -- We want to make sure that the commands we add to `scala` are stable so once we commited to supporting given option it - may be hard to remove it later +Since Scala CLI is quite feature-packed, we do not want to expose all the features and options to all the Scala users +from the very beginning. Why is that? + +- We want to make sure that the options / commands are stable. +- We do not want to overwhelm users with multiple options and commands. That is why we built in a mechanism to limit the commands, options, directives in Scala CLI by default. However, it's still possible to enable all features by explicitly passing the `--power` flag on the command line, or by setting it globally running: ```bash ignore -scala-cli config power true +scala config power true +``` + +Alternatively, it is also possible to rely on the `SCALA_CLI_POWER` environment variable to achieve the same: + +```bash ignore +export SCALA_CLI_POWER=true ``` To check which options, commands and directives are supported when running Scala CLI with limited functionalities, refer to [options](./cli-options.md), [commands](./commands.md) and [using directives](./directives.md), respectively. -## Testing Scala CLI as `scala` +## Installing Scala CLI as `scala` + +Refer to the [official instructions for installing Scala](https://www.scala-lang.org/download/). + +:::note +A given Scala version has a paired Scala CLI version which is used by the `scala` command installed alongside it, as per +the [official instructions](https://www.scala-lang.org/download/). +This means that even when installing the latest Scala version, its `scala` command may refer to an older Scala CLI +version. -There are two recommended ways to test and use Scala CLI: +To get the latest stable Scala CLI launcher, refer to the [separate +`scala-cli` installation instructions](../../../install). -- with brew: +Alternatively, you can use the `--cli-version` launcher option to specify the Scala CLI version to use. +This will run the JVM launcher of the specified Scala CLI version under the hood, so do keep in mind that it may be a +bit slower than a native launcher. +Also, the specified version (and potentially any of its dependencies, if they are not already installed) would be +downloaded if it's not available in the local cache, so it may require additional setup for isolated environments. ```bash ignore -brew install virtuslab/scala-experimental/scala +scala --cli-version 1.5.0 version +# Scala CLI version: 1.5.0 +# Scala version (default): 3.5.0 ``` -- with coursier: +If the bleeding edge is what you are after, you can use the nightly version this way. +Just keep in mind that there are no guarantees about the stability of nightly versions. ```bash ignore -cs setup -cs install scala-experimental ← this command will replace the default scala runner +scala --cli-version nightly version +# Scala CLI version: 1.5.0-17-g00e4c88c1-SNAPSHOT +# Scala version (default): 3.5.0 ``` -Alternatively, you can rename your `scala-cli` executable or alias it as `scala`. +::: ## Migrating from the old `scala` runner to Scala CLI If you have been using the old `scala` runner and want to migrate to Scala CLI, refer to [the migration guide](../../guides/introduction/old-runner-migration.md). + +## Using the old (deprecated) `scala` runner with Scala 3.5+ + +You can still use the (deprecated as of Scala 3.5.0) legacy runner with Scala 3.5+ installed. It is available under +the `scala_legacy` command. + +:::caution +Even though this enables usage of the old runner under a new alias, it is recommended to +migrate any existing scripts and automations to Scala CLI under either `scala` or `scala-cli`, as the `scala_legacy` +command may be dropped at some point in the future. +::: + +```bash ignore +scala_legacy +# [warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work. +# [warning] Please be sure to update to the Scala CLI launcher to use the new features. +# [warning] Check the Scala 3.5.0 release notes to troubleshoot your installation. +# Welcome to Scala 3.5.0 (17, Java OpenJDK 64-Bit Server VM). +# Type in expressions for evaluation. Or try :help. +# +# scala> +``` From e7a4c7e54d6e7aae70792f7736083f4da55dbb5e Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Wed, 4 Sep 2024 14:55:04 +0200 Subject: [PATCH 2/9] Explain how to specify the main class and add compiled classes to the classpath in the `scala` runner migration guide --- .../introduction/old-runner-migration.md | 74 ++++++++++++++++++- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/website/docs/guides/introduction/old-runner-migration.md b/website/docs/guides/introduction/old-runner-migration.md index bd84ccc722..3edb743422 100644 --- a/website/docs/guides/introduction/old-runner-migration.md +++ b/website/docs/guides/introduction/old-runner-migration.md @@ -19,10 +19,10 @@ If you merely want to get started with Scala CLI, you might want to first look at [the Getting started page](../../getting_started.md). ::: -## How to test Scala CLI as the new `scala` command? +## How to start using Scala CLI as the new `scala` command? -There is a dedicated `scala-experimental` distribution of Scala CLI, which can install it as `scala` on your machine. -For instructions on how to try it out, refer to [the relevant doc](../../reference/scala-command/index.md). +Refer to the [official instructions for installing Scala](https://www.scala-lang.org/download/). +Scala CLI is available as the `scala` command alongside the Scala distribution in Scala 3.5.0 and later. ## How has the passing of arguments been changed from the old `scala` runner to Scala CLI? @@ -381,3 +381,71 @@ println("Args: " + args.mkString(" ")) For more information about the `shebang` sub-command, refer to [the appropriate doc](../../commands/shebang.md). For more details on how to use Scala CLI in shebang scripts, refer to [the relevant guide](../scripting/shebang.md). + +## How to run a main class from compiled sources with Scala CLI? + +With the old `scala` runner, running a main class from compiled sources was as simple as passing the main class name +as an arg. The old runner would then assume the current working directory is to be added to the classpath and could +implicitly run any compiled class files it would find. + +```scala title=hello.scala +@main def hello = println("Hello") +``` + +This syntax has been dropped and is no longer supported with the new `scala` runner. +```bash ignore +scalac hello.scala +scala hello # NOTE: this syntax is not supported by Scala CLI +# Hello +``` + +With Scala CLI, all inputs have to be passed explicitly, so any compiled classes in the current working directory +would be ignored unless passed explicitly. +```bash ignore +scalac hello.scala +scala-cli run -cp . +# Hello +``` + +:::note +If only the classpath is passed with `-cp`, then the `run` sub-command can't be skipped, as otherwise Scala CLI +will default to the REPL (as there are no explicit source file inputs present). + +```bash ignore +scalac hello.scala +scala-cli -cp . +# Welcome to Scala 3.5.0 (17, Java OpenJDK 64-Bit Server VM). +# Type in expressions for evaluation. Or try :help. +# +# scala> +``` +::: + +It is possible to explicitly specify the main class to be run (for example, if there are multiple main classes +in the build). The `run` sub-command becomes optional then, as passing `-M` indicates the intention to run something. +```bash +scalac hello.scala +scala-cli -cp . -M hello +# Hello +``` + +:::note +If you want to compile your sources with a separate command, and then run them later, you can also do it +with the `compile` sub-command, rather than the `scalac` script. + +You don't have to specify the class files location, Scala CLI won't recompile them if they are up to date. +```bash ignore +scala-cli compile hello.scala +scala-cli hello.scala +# Hello +``` + +Alternatively, you can also specify the location for the compiled classes explicitly, and then add them +to the classpath, as you would with `scalac`. +```bash ignore +scala-cli compile hello.scala -d compiled_classes +scala-cli hello.scala +# Hello +``` +::: + From 4526da53fb2bc8d3b293fdb6ce7f62b25345d970 Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Wed, 4 Sep 2024 15:03:10 +0200 Subject: [PATCH 3/9] Explain `scala_legacy` in the old `scala` runner migration guide --- .../guides/introduction/old-runner-migration.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/website/docs/guides/introduction/old-runner-migration.md b/website/docs/guides/introduction/old-runner-migration.md index 3edb743422..7d2210f1df 100644 --- a/website/docs/guides/introduction/old-runner-migration.md +++ b/website/docs/guides/introduction/old-runner-migration.md @@ -24,6 +24,22 @@ at [the Getting started page](../../getting_started.md). Refer to the [official instructions for installing Scala](https://www.scala-lang.org/download/). Scala CLI is available as the `scala` command alongside the Scala distribution in Scala 3.5.0 and later. +## Can I still use the old `scala` runner with Scala 3.5+? + +Yes, even though its usage has been deprecated, it is still available under the `scala_legacy` command. +However, it is likely to be dropped in a future version. + +```bash ignore +scala_legacy +# [warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work. +# [warning] Please be sure to update to the Scala CLI launcher to use the new features. +# [warning] Check the Scala 3.5.0 release notes to troubleshoot your installation. +# Welcome to Scala 3.5.0 (17, Java OpenJDK 64-Bit Server VM). +# Type in expressions for evaluation. Or try :help. +# +# scala> +``` + ## How has the passing of arguments been changed from the old `scala` runner to Scala CLI? Let us take a closer look on how the old runner handled arguments when compared to Scala CLI. From 772f4d4102a0c273c507726e9dd1b43d60271d7e Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Fri, 6 Sep 2024 09:14:44 +0200 Subject: [PATCH 4/9] Use `scala` & `scala_legacy` in old runner migration guide; verify them with `docs-tests` --- build.sc | 20 ++++ .../src/main/scala/sclicheck/sclicheck.scala | 53 ++++++++-- project/deps.sc | 3 +- .../introduction/old-runner-migration.md | 97 ++++++++++--------- website/docs/reference/scala-command/index.md | 11 +-- 5 files changed, 123 insertions(+), 61 deletions(-) diff --git a/build.sc b/build.sc index 36936669af..29f92121c0 100644 --- a/build.sc +++ b/build.sc @@ -172,6 +172,26 @@ trait DocsTests extends CrossSbtModule with ScalaCliScalafixModule with HasTests } def forkEnv = super.forkEnv() ++ extraEnv() + def constantsFile = T.persistent { + val dir = T.dest / "constants" + val dest = dir / "Constants.scala" + val code = + s"""package sclicheck + | + |/** Build-time constants. Generated by mill. */ + |object Constants { + | def coursierOrg = "${Deps.coursier.dep.module.organization.value}" + | def coursierCliModule = "${Deps.coursierCli.dep.module.name.value}" + | def coursierCliVersion = "${Deps.Versions.coursierCli}" + | def defaultScalaVersion = "${Scala.defaultUser}" + |} + |""".stripMargin + if (!os.isFile(dest) || os.read(dest) != code) + os.write.over(dest, code, createFolders = true) + PathRef(dir) + } + def generatedSources = super.generatedSources() ++ Seq(constantsFile()) + object test extends ScalaCliTests with ScalaCliScalafixModule { def forkEnv = super.forkEnv() ++ extraEnv() ++ Seq( "SCALA_CLI_EXAMPLES" -> (os.pwd / "examples").toString, diff --git a/modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala b/modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala index b48cb42e02..4b2af2807f 100644 --- a/modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala +++ b/modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala @@ -187,15 +187,50 @@ def checkFile(file: os.Path, options: Options): Unit = val binDir = { val binDir0 = out / ".scala-cli" os.makeDir.all(binDir0) - val escapedCommand = options.scalaCliCommand - .map(arg => "\"" + arg.replace("\"", "\\\"") + "\"") - .mkString(" ") - val helperScript = - s"""#!/usr/bin/env bash - |exec $escapedCommand "$$@" - |""".stripMargin - os.write(binDir0 / "scala-cli", helperScript) - os.perms.set(binDir0 / "scala-cli", "rwxr-xr-x") + + def createHelperScript(command: Seq[String], scriptName: String): Unit = { + val escapedCommand = command + .map(arg => "\"" + arg.replace("\"", "\\\"") + "\"") + .mkString(" ") + val scriptCode = + s"""#!/usr/bin/env bash + |exec $escapedCommand "$$@" + |""".stripMargin + os.write(binDir0 / scriptName, scriptCode) + os.perms.set(binDir0 / scriptName, "rwxr-xr-x") + } + createHelperScript(options.scalaCliCommand, "scala-cli") + createHelperScript(options.scalaCliCommand, "scala") + val coursierCliDep = + s"${Constants.coursierOrg}:${Constants.coursierCliModule}:${Constants.coursierCliVersion}" + createHelperScript( + options.scalaCliCommand ++ Seq( + "run", + "--dep", + coursierCliDep, + "--", + "launch", + s"scala:${Constants.defaultScalaVersion}", + "-M", + "dotty.tools.MainGenericRunner", + "--" + ), + "scala_legacy" + ) + createHelperScript( + options.scalaCliCommand ++ Seq( + "run", + "--dep", + coursierCliDep, + "--", + "launch", + s"scala:${Constants.defaultScalaVersion}", + "-M", + "dotty.tools.dotc.Main", + "--" + ), + "scalac" + ) binDir0 } val extraEnv = { diff --git a/project/deps.sc b/project/deps.sc index 681076a4af..0647ea5691 100644 --- a/project/deps.sc +++ b/project/deps.sc @@ -145,7 +145,8 @@ object Deps { def caseApp = ivy"com.github.alexarchambault::case-app:2.1.0-M28" def collectionCompat = ivy"org.scala-lang.modules::scala-collection-compat:2.12.0" // Force using of 2.13 - is there a better way? - def coursier = ivy"io.get-coursier:coursier_2.13:${Versions.coursier}" + def coursier = ivy"io.get-coursier:coursier_2.13:${Versions.coursier}" + def coursierCli = ivy"io.get-coursier:coursier-cli_2.13:${Versions.coursierCli}" def coursierJvm = ivy"io.get-coursier:coursier-jvm_2.13:${Versions.coursier}" .exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_2.13")) def coursierLauncher = ivy"io.get-coursier:coursier-launcher_2.13:${Versions.coursier}" diff --git a/website/docs/guides/introduction/old-runner-migration.md b/website/docs/guides/introduction/old-runner-migration.md index 7d2210f1df..e118e5ad86 100644 --- a/website/docs/guides/introduction/old-runner-migration.md +++ b/website/docs/guides/introduction/old-runner-migration.md @@ -29,15 +29,12 @@ Scala CLI is available as the `scala` command alongside the Scala distribution i Yes, even though its usage has been deprecated, it is still available under the `scala_legacy` command. However, it is likely to be dropped in a future version. -```bash ignore -scala_legacy +```bash +scala_legacy -version # [warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work. # [warning] Please be sure to update to the Scala CLI launcher to use the new features. # [warning] Check the Scala 3.5.0 release notes to troubleshoot your installation. -# Welcome to Scala 3.5.0 (17, Java OpenJDK 64-Bit Server VM). -# Type in expressions for evaluation. Or try :help. -# -# scala> +# Scala code runner version 3.5.0 -- Copyright 2002-2024, LAMP/EPFL ``` ## How has the passing of arguments been changed from the old `scala` runner to Scala CLI? @@ -46,18 +43,22 @@ Let us take a closer look on how the old runner handled arguments when compared ### The old ways -In the old `scala` runner, the first argument was treated as the input source, while the second and following arguments +In the old runner, the first argument was treated as the input source, while the second and following arguments were considered program arguments. -```bash ignore -scala Source.scala programArg1 programArg2 +```scala title=Source.scala +@main def main(args: String*): Unit = println(args.mkString(" ")) +``` + +```bash +scala_legacy Source.scala programArg1 programArg2 ``` Since everything after the first argument had to be arbitrarily read as a program argument, regardless of format, all runner options had to be passed before the source input. -```bash ignore -scala -save script.sc programArg1 programArg2 +```bash +scala_legacy -save Source.scala programArg1 programArg2 ``` ### The ways of Scala CLI @@ -65,15 +66,19 @@ scala -save script.sc programArg1 programArg2 With Scala CLI's default way of handling arguments, inputs and program arguments have to be divided by `--`. There is no limit for the number of either. +```scala title=Source2.scala +def placeholder = println("Example extra source") +``` + ```bash ignore -scala-cli Source1.scala Source2.scala -- programArg1 programArg2 +scala Source.scala Source2.scala -- programArg1 programArg2 ``` Additionally, a Scala CLI sub-command can be passed before the inputs section. For example, to call the above example specifying the `run` sub-command explicitly, pass it like this: -```bash ignore -scala-cli run Source1.scala Source2.scala -- programArg1 programArg2 +```bash +scala run Source.scala Source2.scala -- programArg1 programArg2 ``` More on sub-commands can be found [here](../../commands/basics.md). @@ -81,20 +86,20 @@ More on sub-commands can be found [here](../../commands/basics.md). Runner options can be passed on whatever position in the inputs section (before `--`). For example, all the following examples are correct ways to specify the Scala version explicitly as `3.2` -```bash ignore -scala-cli -S 3.2 Source1.scala Source2.scala -- programArg1 programArg2 -scala-cli Source1.scala -S 3.2 Source2.scala -- programArg1 programArg2 -scala-cli Source1.scala Source2.scala -S 3.2 -- programArg1 programArg2 +```bash +scala -S 3.2 Source.scala Source2.scala -- programArg1 programArg2 +scala Source.scala -S 3.2 Source2.scala -- programArg1 programArg2 +scala Source.scala Source2.scala -S 3.2 -- programArg1 programArg2 ``` :::note The exception to this rule are the launcher options, like `--cli-version` or `--cli-scala-version`. Those have to be passed before the inputs section (before any source inputs). -For example, to explicitly specify the launcher should run Scala CLI `v0.1.20`, pass it like this: +For example, to explicitly specify the launcher should run Scala CLI `v1.5.0`, pass it like this: -```bash ignore -scala-cli --cli-version 0.1.20 Source1.scala Source2.scala -- programArg1 programArg2 +```bash +scala --cli-version 1.5.0 Source.scala Source2.scala -- programArg1 programArg2 ``` Also, if a Scala CLI sub-command is being passed explicitly, all launcher options have to be passed before the @@ -103,7 +108,7 @@ sub-command. For example, to call [the `package` sub-command](../../commands/package.md) using the nightly CLI version, do it like this: ```bash ignore -scala-cli --cli-version nightly package --help +scala --cli-version nightly package --help ``` ::: @@ -114,8 +119,8 @@ To provide better support for shebang scripts, Scala CLI has [a dedicated `shebang` sub-command](../../commands/shebang.md), which handles arguments similarly to the old `scala` script. -```bash ignore -scala-cli shebang Source.scala programArg1 programArg2 +```bash +scala shebang Source.scala programArg1 programArg2 ``` The purpose of the `shebang` sub-command is essentially to only be used in a shebang header (more @@ -231,12 +236,12 @@ object Main { -```bash ignore -scala Main.scala Hello world +```bash +scala_legacy Main.scala Hello world ``` ```bash -scala-cli Main.scala -- Hello world +scala Main.scala -- Hello world ``` ```text @@ -259,7 +264,7 @@ In other words, when explicitly declaring a main class when working with Scala C file. ```bash -scala-cli main-in-script.sc -- Hello world +scala main-in-script.sc -- Hello world # no output will be printed ``` @@ -280,7 +285,7 @@ However, it is supported by Scala CLI. ```bash -scala-cli script.sc -- Hello world +scala script.sc -- Hello world ``` ```text @@ -303,7 +308,7 @@ However, both the old Scala `3.x` runner as well as Scala CLI do not support it. ```bash fail -scala-cli script.scala -- Hello world +scala script.scala -- Hello world ``` ```text @@ -347,15 +352,15 @@ That is, all arguments starting with the second were treated as program args, ra This is in contrast with the Scala CLI default way of handling arguments, where inputs and program arguments have to be divided by `--`. -```bash ignore -scala-cli Source1.scala Source2.scala -- programArg1 programArg2 +```bash +scala Source.scala Source2.scala -- programArg1 programArg2 ``` To better support shebang scripts, Scala CLI has a dedicated `shebang` sub-command, which handles arguments similarly to the old `scala` script. -```bash ignore -scala-cli shebang Source.scala programArg1 programArg2 +```bash +scala shebang Source.scala programArg1 programArg2 ``` For more concrete examples on how to change the shebang header in your existing scripts, look below. @@ -409,17 +414,18 @@ implicitly run any compiled class files it would find. ``` This syntax has been dropped and is no longer supported with the new `scala` runner. -```bash ignore +```bash scalac hello.scala -scala hello # NOTE: this syntax is not supported by Scala CLI +scala_legacy hello # NOTE: this syntax is not supported by Scala CLI # Hello ``` With Scala CLI, all inputs have to be passed explicitly, so any compiled classes in the current working directory would be ignored unless passed explicitly. ```bash ignore +scala clean . scalac hello.scala -scala-cli run -cp . +scala run -cp . # Hello ``` @@ -428,8 +434,9 @@ If only the classpath is passed with `-cp`, then the `run` sub-command can't be will default to the REPL (as there are no explicit source file inputs present). ```bash ignore +scala clean . scalac hello.scala -scala-cli -cp . +scala -cp . # Welcome to Scala 3.5.0 (17, Java OpenJDK 64-Bit Server VM). # Type in expressions for evaluation. Or try :help. # @@ -440,8 +447,9 @@ scala-cli -cp . It is possible to explicitly specify the main class to be run (for example, if there are multiple main classes in the build). The `run` sub-command becomes optional then, as passing `-M` indicates the intention to run something. ```bash +scala clean . scalac hello.scala -scala-cli -cp . -M hello +scala -cp . -M hello # Hello ``` @@ -451,16 +459,17 @@ with the `compile` sub-command, rather than the `scalac` script. You don't have to specify the class files location, Scala CLI won't recompile them if they are up to date. ```bash ignore -scala-cli compile hello.scala -scala-cli hello.scala +scala clean hello.scala +scala compile hello.scala +scala hello.scala # Hello ``` Alternatively, you can also specify the location for the compiled classes explicitly, and then add them to the classpath, as you would with `scalac`. -```bash ignore -scala-cli compile hello.scala -d compiled_classes -scala-cli hello.scala +```bash +scala compile hello.scala -d compiled_classes +scala run -cp compiled_classes # Hello ``` ::: diff --git a/website/docs/reference/scala-command/index.md b/website/docs/reference/scala-command/index.md index 4c6055bf35..2e3f1fb1f8 100644 --- a/website/docs/reference/scala-command/index.md +++ b/website/docs/reference/scala-command/index.md @@ -49,7 +49,7 @@ bit slower than a native launcher. Also, the specified version (and potentially any of its dependencies, if they are not already installed) would be downloaded if it's not available in the local cache, so it may require additional setup for isolated environments. -```bash ignore +```bash scala --cli-version 1.5.0 version # Scala CLI version: 1.5.0 # Scala version (default): 3.5.0 @@ -82,13 +82,10 @@ migrate any existing scripts and automations to Scala CLI under either `scala` o command may be dropped at some point in the future. ::: -```bash ignore -scala_legacy +```bash +scala_legacy -version # [warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work. # [warning] Please be sure to update to the Scala CLI launcher to use the new features. # [warning] Check the Scala 3.5.0 release notes to troubleshoot your installation. -# Welcome to Scala 3.5.0 (17, Java OpenJDK 64-Bit Server VM). -# Type in expressions for evaluation. Or try :help. -# -# scala> +# Scala code runner version 3.5.0 -- Copyright 2002-2024, LAMP/EPFL ``` From 128c015bcf1dfbe6e3e9cfeba4c9b5a4cd22bc78 Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Fri, 6 Sep 2024 11:25:35 +0200 Subject: [PATCH 5/9] Add support for `sclicheck` to run bash snippets with clean context --- .../src/main/scala/sclicheck/sclicheck.scala | 26 ++++++++++++++----- .../introduction/old-runner-migration.md | 10 +++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala b/modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala index 4b2af2807f..60c5283ffd 100644 --- a/modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala +++ b/modules/docs-tests/src/main/scala/sclicheck/sclicheck.scala @@ -13,7 +13,7 @@ import scala.util.matching.Regex val SnippetBlock = """ *(`{2}`+)[^ ]+ title=([\w\d.\-/_]+) *""".r val CompileBlock = """ *(`{2}`+) *(\w+) +(compile|fail) *(?:title=([\w\d.\-/_]+))? *(power)? *""".r def compileBlockEnds(backticks: String) = s""" *$backticks *""".r -val BashCommand = """ *```bash *(fail|run-fail)? *""".r +val BashCommand = """ *```bash *(fail|run-fail)? *(clean)? *""".r val CheckBlock = """ *\<\!-- Expected(-regex)?: *""".r val CheckBlockEnd = """ *\--> *""".r val Clear = """ *