Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for limiting updates through config
change limiting to not count ignored updates add license header fix behaviour refactor processUpdates address pr comments
- Loading branch information
Manuel cueto Rodriguez
committed
Oct 21, 2019
1 parent
b409475
commit f5d3d80
Showing
7 changed files
with
134 additions
and
32 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
24 changes: 24 additions & 0 deletions
24
modules/core/src/main/scala/org/scalasteward/core/data/ProcessResult.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,24 @@ | ||
/* | ||
* Copyright 2018-2019 Scala Steward contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.scalasteward.core.data | ||
|
||
sealed trait ProcessResult extends Product with Serializable | ||
|
||
object ProcessResult { | ||
case object Ignored extends ProcessResult | ||
case object Updated extends ProcessResult | ||
} |
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 |
---|---|---|
|
@@ -146,4 +146,5 @@ package object util { | |
|
||
outerLoop(list, ListBuffer.empty, ListBuffer.empty).toList | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
modules/core/src/test/scala/org/scalasteward/core/nurture/NurtureAlgTest.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,52 @@ | ||
package org.scalasteward.core.nurture | ||
|
||
import cats.data.{NonEmptyList, StateT} | ||
import cats.effect.{Async, IO} | ||
import cats.syntax.option._ | ||
import org.scalacheck.{Arbitrary, Gen} | ||
import org.scalasteward.core.data.ProcessResult.{Ignored, Updated} | ||
import org.scalasteward.core.data.Update.Single | ||
import org.scalasteward.core.data.{GroupId, ProcessResult, Update} | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks | ||
|
||
class NurtureAlgTest extends AnyFunSuite with Matchers with ScalaCheckPropertyChecks { | ||
|
||
implicit val updateArbitrary: Arbitrary[Update] = Arbitrary(for { | ||
groupId <- Gen.alphaStr.map(GroupId.apply) | ||
artifactId <- Gen.alphaStr | ||
currentVersion <- Gen.alphaStr | ||
newerVersion <- Gen.alphaStr | ||
} yield Single(groupId, artifactId, currentVersion, NonEmptyList.one(newerVersion))) | ||
|
||
test("processUpdates with No Limiting") { | ||
forAll { updates: List[Update] => | ||
NurtureAlg | ||
.processUpdates( | ||
updates, | ||
_ => StateT[IO, Int, ProcessResult](actionAcc => IO.pure(actionAcc + 1 -> Ignored)), | ||
None | ||
) | ||
.runS(0) | ||
.unsafeRunSync() shouldBe updates.size | ||
} | ||
} | ||
|
||
test("processUpdates with Limiting should process all updates up to the limit") { | ||
forAll { updates: Set[Update] => | ||
val (ignorableUpdates, appliableUpdates) = updates.toList.splitAt(updates.size / 2) | ||
|
||
implicit val stateAsync = Async.catsStateTAsync[IO, Int] | ||
val f: Update => StateT[IO, Int, ProcessResult] = update => | ||
StateT[IO, Int, ProcessResult]( | ||
actionAcc => | ||
IO.pure(actionAcc + 1 -> (if (ignorableUpdates.contains(update)) Ignored else Updated)) | ||
) | ||
NurtureAlg | ||
.processUpdates(ignorableUpdates ++ appliableUpdates, f, appliableUpdates.size.some) | ||
.runS(0) | ||
.unsafeRunSync() shouldBe updates.size | ||
} | ||
} | ||
} |
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