-
Notifications
You must be signed in to change notification settings - Fork 121
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
Add more interactive install-home command #186
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7be5325
Add more interactive install-home command
lwronski d676940
Fix resolving bin dir path
lwronski bc1798e
Run install home test only in Linux/MacOs and CI
lwronski 5ae152c
Apply suggestions from code review
lwronski bca44c9
Scalafmt and fixes after review
lwronski c2ba5a1
Add Version command
lwronski f447d89
Add explicit types in version options
lwronski 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 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 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 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 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
12 changes: 12 additions & 0 deletions
12
modules/cli/src/main/scala/scala/cli/commands/Version.scala
This file contains 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,12 @@ | ||
package scala.cli.commands | ||
|
||
import caseapp._ | ||
|
||
import scala.build.internal.Constants | ||
|
||
object Version extends ScalaCommand[VersionOptions] { | ||
override def group = "Miscellaneous" | ||
def run(options: VersionOptions, args: RemainingArgs): Unit = { | ||
println(Constants.version) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
modules/cli/src/main/scala/scala/cli/commands/VersionOptions.scala
This file contains 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,11 @@ | ||
package scala.cli.commands | ||
|
||
import caseapp._ | ||
|
||
@HelpMessage("Print scala-cli version") | ||
final case class VersionOptions() | ||
|
||
object VersionOptions { | ||
implicit lazy val parser: Parser[VersionOptions] = Parser.derive | ||
implicit lazy val help: Help[RunOptions] = Help.derive | ||
} |
111 changes: 111 additions & 0 deletions
111
modules/integration/src/test/scala/scala/cli/integration/InstallHomeTests.scala
This file contains 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,111 @@ | ||
package scala.cli.integration | ||
|
||
import com.eed3si9n.expecty.Expecty.expect | ||
|
||
import scala.util.Properties | ||
|
||
class InstallHomeTests extends munit.FunSuite { | ||
|
||
val firstVersion = "0.0.1" | ||
val secondVersion = "0.0.2" | ||
val dummyScalaCliFirstName = "DummyScalaCli-1.scala" | ||
val dummyScalaCliSecondName = "DummyScalaCli-2.scala" | ||
val dummyScalaCliBinName = "scala-cli-dummy-test" | ||
val testInputs = TestInputs( | ||
Seq( | ||
os.rel / dummyScalaCliFirstName -> | ||
s""" | ||
|object DummyScalaCli extends App { | ||
| println(\"$firstVersion\") | ||
|}""".stripMargin, | ||
os.rel / dummyScalaCliSecondName -> | ||
s""" | ||
|object DummyScalaCli extends App { | ||
| println(\"$secondVersion\") | ||
|}""".stripMargin | ||
) | ||
) | ||
|
||
private def packageDummyScalaCli(root: os.Path, dummyScalaCliFileName: String, output: String) = { | ||
// format: off | ||
val cmd = Seq[os.Shellable]( | ||
TestUtil.cli, "package", dummyScalaCliFileName, "-o", output | ||
) | ||
// format: on | ||
os.proc(cmd).call( | ||
cwd = root, | ||
stdin = os.Inherit, | ||
stdout = os.Inherit | ||
) | ||
} | ||
|
||
private def installScalaCli( | ||
root: os.Path, | ||
binVersion: String, | ||
binDirPath: os.Path, | ||
force: Boolean | ||
) = { | ||
// format: off | ||
val cmdInstallVersion = Seq[os.Shellable]( | ||
TestUtil.cli, "install-home", | ||
"--env", | ||
"--scala-cli-binary-path", binVersion , | ||
"--binary-name", dummyScalaCliBinName, | ||
"--bin-dir", binDirPath | ||
) ++ (if(force) Seq[os.Shellable]("--force") else Seq.empty) | ||
// format: on | ||
os.proc(cmdInstallVersion).call( | ||
cwd = root, | ||
stdin = os.Inherit, | ||
stdout = os.Inherit | ||
) | ||
} | ||
|
||
def runInstallHome(): Unit = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very sophisticated test, took me some time that we build fake scala-cli executables that can print only version and juggle them. Maybe we could comment it (in at all) |
||
|
||
testInputs.fromRoot { root => | ||
val binDirPath = root / ".scala" / "scala-cli" | ||
|
||
val binDummyScalaCliFirst = dummyScalaCliFirstName.stripSuffix(".scala").toLowerCase | ||
val binDummyScalaCliSecond = dummyScalaCliSecondName.stripSuffix(".scala").toLowerCase | ||
|
||
packageDummyScalaCli(root, dummyScalaCliFirstName, binDummyScalaCliFirst) | ||
packageDummyScalaCli(root, dummyScalaCliSecondName, binDummyScalaCliSecond) | ||
|
||
// install 1 version | ||
installScalaCli(root, binDummyScalaCliFirst, binDirPath, force = true) | ||
|
||
println(binDirPath / dummyScalaCliBinName) | ||
|
||
val v1Install = os.proc(binDirPath / dummyScalaCliBinName).call( | ||
cwd = root, | ||
stdin = os.Inherit | ||
).out.text.trim | ||
expect(v1Install == firstVersion) | ||
|
||
// update to 2 version | ||
installScalaCli(root, binDummyScalaCliSecond, binDirPath, force = false) | ||
|
||
val v2Update = os.proc(binDirPath / dummyScalaCliBinName).call( | ||
cwd = root, | ||
stdin = os.Inherit | ||
).out.text.trim | ||
expect(v2Update == secondVersion) | ||
|
||
// downgrade to 1 version with force | ||
installScalaCli(root, binDummyScalaCliFirst, binDirPath, force = true) | ||
|
||
val v1Downgrade = os.proc(binDirPath / dummyScalaCliBinName).call( | ||
cwd = root, | ||
stdin = os.Inherit | ||
).out.text.trim | ||
expect(v1Downgrade == firstVersion) | ||
} | ||
} | ||
|
||
if (!Properties.isWin && TestUtil.isCI) | ||
test("updating and downgrading dummy scala-cli using install-home command") { | ||
runInstallHome() | ||
} | ||
|
||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to put
exit
in a function namedlogDowngrade
. Minor issue, can be done in a follow-up PR