jaredsburrows / gradle-spoon-plugin

Gradle plugin that provides a task to run Android instrumentation tests via Spoon.
https://search.maven.org/artifact/com.jaredsburrows/gradle-spoon-plugin
Apache License 2.0
124 stars 29 forks source link

Validate Spoon Task Inputs #82

Open ZakTaccardi opened 4 years ago

ZakTaccardi commented 4 years ago

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!

jaredsburrows commented 3 years ago

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