-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fractional and subtraction for jobs flag (#3554)
Resolve #3482 Allow jobs param to have following formats: 1. An integer indicates the parallel level. 2. A float N followed by character "C" indicates uses (N * all available cores). e.g. "0.5C" uses half of the available cores. 3. "C-" followed by an integer N indicates uses (all available cores - N). e.g. "C-1" leaves 1 core and uses all the other cores. --------- Co-authored-by: Li Haoyi <[email protected]>
- Loading branch information
Showing
3 changed files
with
116 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package mill.runner | ||
|
||
import utest._ | ||
|
||
object MillMainTests extends TestSuite { | ||
|
||
private def assertParseErr(result: Either[String, Int], msg: String): Unit = { | ||
assert(result.isLeft) | ||
assert(result.swap.toOption.get.contains(msg)) | ||
} | ||
|
||
def tests: Tests = Tests { | ||
|
||
test("Parsing --jobs/-j flag") { | ||
|
||
test("parse none") { | ||
assert(MillMain.parseThreadCount(None, 10) == Right(10)) | ||
} | ||
|
||
test("parse int number") { | ||
assert(MillMain.parseThreadCount(Some("1"), 10) == Right(1)) | ||
assert(MillMain.parseThreadCount(Some("11"), 10) == Right(11)) | ||
|
||
assertParseErr(MillMain.parseThreadCount(Some("1.0"), 10), "Failed to find a int number") | ||
assertParseErr(MillMain.parseThreadCount(Some("1.1"), 10), "Failed to find a int number") | ||
assertParseErr(MillMain.parseThreadCount(Some("0.1"), 10), "Failed to find a int number") | ||
assert(MillMain.parseThreadCount(Some("0"), 10) == Right(10)) | ||
assert(MillMain.parseThreadCount(Some("-1"), 10) == Right(1)) | ||
} | ||
|
||
test("parse fraction number") { | ||
assert(MillMain.parseThreadCount(Some("0.5C"), 10) == Right(5)) | ||
assert(MillMain.parseThreadCount(Some("0.54C"), 10) == Right(5)) | ||
assert(MillMain.parseThreadCount(Some("0.59C"), 10) == Right(5)) | ||
assert(MillMain.parseThreadCount(Some(".5C"), 10) == Right(5)) | ||
assert(MillMain.parseThreadCount(Some("1.0C"), 10) == Right(10)) | ||
assert(MillMain.parseThreadCount(Some("1.5C"), 10) == Right(15)) | ||
assert(MillMain.parseThreadCount(Some("0.09C"), 10) == Right(1)) | ||
assert(MillMain.parseThreadCount(Some("-0.5C"), 10) == Right(1)) | ||
assertParseErr( | ||
MillMain.parseThreadCount(Some("0.5.4C"), 10), | ||
"Failed to find a float number before \"C\"" | ||
) | ||
} | ||
|
||
test("parse subtraction") { | ||
assert(MillMain.parseThreadCount(Some("C-1"), 10) == Right(9)) | ||
assert(MillMain.parseThreadCount(Some("C-10"), 10) == Right(1)) | ||
assert(MillMain.parseThreadCount(Some("C-11"), 10) == Right(1)) | ||
|
||
assertParseErr( | ||
MillMain.parseThreadCount(Some("C-1.1"), 10), | ||
"Failed to find a int number after \"C-\"" | ||
) | ||
assertParseErr( | ||
MillMain.parseThreadCount(Some("11-C"), 10), | ||
"Failed to find a float number before \"C\"" | ||
) | ||
} | ||
|
||
test("parse invalid input") { | ||
assertParseErr( | ||
MillMain.parseThreadCount(Some("CCCC"), 10), | ||
"Failed to find a float number before \"C\"" | ||
) | ||
assertParseErr( | ||
MillMain.parseThreadCount(Some("abcdefg"), 10), | ||
"Failed to find a int number" | ||
) | ||
} | ||
|
||
} | ||
|
||
} | ||
} |