-
-
Notifications
You must be signed in to change notification settings - Fork 83
TempPath (<: AutoCloseable) and withTempFile|Dir convenience methods #147
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
mpollmeier
wants to merge
15
commits into
com-lihaoyi:main
Choose a base branch
from
mpollmeier:michael/with-temp-file
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bb34ab7
TempPath (<: AutoCloseable) and withTempFile | withTempDir convenienc…
mpollmeier 6bfa0a1
return A directly, rather than Try[A] (PR comment)
mpollmeier 4ea3d1f
rename to `os.temp.with[File|Dir]`
mpollmeier 4b16482
provide the same set of options as we do in the apply methods
mpollmeier 9a35dba
Added Scala version specific source paths based on ranges
lefou 40c2f1d
add `new` modifier for scala 2
mpollmeier 76be191
add scala.util.Using from stdlib for 2.12- builds
mpollmeier aea113b
change namespace of scala.util.Using
mpollmeier 304a9b8
use custom `removeRecursively` function, to please scala2 compiler...
mpollmeier e2da3fd
ugliness for Scala 2.11 support
mpollmeier e93cbdc
reducing line length to <= 100 chars - I miss scalafmt
mpollmeier 0b8bfef
use scala-collection-compat for scala 2.12-
mpollmeier c2dfe01
Merge branch 'main' into michael/with-temp-file
lefou 6edb4f2
Update os/src/TempOps.scala
mpollmeier 7e6c994
Update os/src/TempOps.scala
mpollmeier 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
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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package test.os | ||
|
|
||
| import os._ | ||
| import scala.util.Using | ||
| import utest.{assert => _, _} | ||
|
|
||
| object TempPathTests extends TestSuite{ | ||
| val tests = Tests { | ||
|
|
||
| test("convenience methods") { | ||
| test("temp.withFile") { | ||
| var tempFilePath: String = null | ||
| os.temp.withFile { file => | ||
| tempFilePath = file.toString | ||
| assert(os.exists(file)) | ||
| } | ||
| assert(!os.exists(os.Path(tempFilePath)), | ||
| s"temp file did not get auto-deleted after `Using` block: $tempFilePath") | ||
| } | ||
| test("temp.withDir") { | ||
| var tempDirPath: String = null | ||
| var tempFilePath: String = null | ||
| os.temp.withDir { dir => | ||
| val file = dir / "somefile" | ||
| tempDirPath = dir.toString | ||
| tempFilePath = file.toString | ||
| os.write(file, "some content") | ||
| assert(os.exists(dir)) | ||
| assert(os.exists(file)) | ||
| } | ||
| assert(!os.exists(os.Path(tempDirPath)), | ||
| s"temp dir did not get auto-deleted after `Using` block: $tempDirPath") | ||
| } | ||
| } | ||
|
|
||
| test("delete after `Using` block") { | ||
| test("single file") { | ||
| var tempFilePath: String = null | ||
| Using(os.temp()) { file => | ||
| tempFilePath = file.toString | ||
| assert(os.exists(file)) | ||
| } | ||
| assert(!os.exists(os.Path(tempFilePath)), | ||
| s"temp file did not get auto-deleted after `Using` block: $tempFilePath") | ||
| } | ||
| test("directory") { | ||
| var tempDirPath: String = null | ||
| var tempFilePath: String = null | ||
| Using(os.temp.dir()) { dir => | ||
| val file = dir / "somefile" | ||
| tempDirPath = dir.toString | ||
| tempFilePath = file.toString | ||
| os.write(file, "some content") | ||
| assert(os.exists(dir)) | ||
| assert(os.exists(file)) | ||
| } | ||
| assert(!os.exists(os.Path(tempDirPath)), | ||
| s"temp dir did not get auto-deleted after `Using` block: $tempDirPath") | ||
| } | ||
|
|
||
| test("multiple files") { | ||
| var tempFilePaths: Seq[String] = Nil | ||
| Using.Manager { use => | ||
| val file1 = use(os.temp()) | ||
| val file2 = use(os.temp()) | ||
| val files = Seq(file1, file2) | ||
| tempFilePaths = files.map(_.toString) | ||
| files.foreach(file => assert(os.exists(file))) | ||
| } | ||
| tempFilePaths.foreach { file => | ||
| assert(!os.exists(os.Path(file)), | ||
| s"temp file did not get auto-deleted after `Using` block: $file") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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.