gradle-spoon-plugin icon indicating copy to clipboard operation
gradle-spoon-plugin copied to clipboard

Validate Spoon Task Inputs

Open ZakTaccardi opened this issue 4 years ago • 1 comments

I have the following code:

spoon {
  // The number of separate shards to create.
  if (project.hasProperty('spoonNumShards')) {
    numShards = project.spoonNumShards
  }
  // The shardIndex option to specify which shard to run.
  if (project.hasProperty('spoonShardIndex')) {
    shardIndex = project.spoonShardIndex
  }
}

I ran the following command

./gradlew :app:spoonDebugAndroidTest -PspoonNumShards=4 -PspoonShardIndex=0

Expected output:

I/RemoteAndroidTest: Running am instrument -w -r   -e shardIndex 0 -e numShards 4 -e log true

Actual output:

I/RemoteAndroidTest: Running am instrument -w -r   -e  shardIndex 48 -e numShards 52 -e log true

To fix this, Integer.valueOf(..) is needed.

spoon {
  // The number of separate shards to create.
  if (project.hasProperty('spoonNumShards')) {
    numShards = Integer.valueOf(project.spoonNumShards)
  }
  // The shardIndex option to specify which shard to run.
  if (project.hasProperty('spoonShardIndex')) {
    shardIndex = Integer.valueOf(project.spoonShardIndex)
  }
}

Ask: Avoid this issue by having the spoon gradle plugin validate its input and throw an exception when numShards/shardIndex, are not integers.

Thanks!

ZakTaccardi avatar Apr 23 '20 19:04 ZakTaccardi

Are you saying that these tests are validating this already? https://github.com/jaredsburrows/gradle-spoon-plugin/blob/master/src/test/groovy/com/jaredsburrows/spoon/SpoonPluginSpec.groovy#L79

jaredsburrows avatar Dec 30 '20 20:12 jaredsburrows