-1

I am using XcodeCoverageConverter to convert XCResult to Cobertura XML as per the instruction provided in the README file. It is working as expected when only one item was passed as value for --exclude-packages. However when I try to pass an array as follows,

xcc generate coverage.json TargetDirectory cobertura-xml --exclude-packages Tests AnotherPackageName --verbose

I get the following error,

Error: The value 'AnotherPackageName' is invalid for '<output-formats>'
Usage: xcc generate <json-file> <output-path> [<output-formats> ...] [--exclude-targets <exclude-targets> ...] [--exclude-packages <exclude-packages> ...] [--verbose]

Same thing I am trying from my Bash script, where I get the same error if I pass array for --exclude-packages.

Sample 1

jsonPath="coverage.json"
coberturaTargetPath="Cobertura"

xcc generate $jsonPath \
   $coberturaTargetPath cobertura-xml \
   --exclude-packages Tests AnotherPackageName \
   --verbose

Sample 2

jsonPath="coverage.json"
coberturaTargetPath="Cobertura"
excludePackages=(Tests AnotherPackageName)

xcc generate $jsonPath \
   $coberturaTargetPath cobertura-xml \
   --exclude-packages ${excludePackages[@]} \
   --verbose

Sample 3

jsonPath="coverage.json"
coberturaTargetPath="Cobertura"
excludePackages=(Tests AnotherPackageName)

xcc generate $jsonPath \
   $coberturaTargetPath cobertura-xml \
   --exclude-packages=${excludePackages[@]} \
   --verbose

Sample 4

jsonPath="coverage.json"
coberturaTargetPath="Cobertura"
outputFormats=(cobertura-xml)
excludePackages=(Tests AnotherPackageName)

xcc generate $jsonPath \
   $coberturaTargetPath ${outputFormats[@]} \
   --exclude-packages=${excludePackages[@]} \
   --verbose

Sample 5

jsonPath="coverage.json"
coberturaTargetPath="Cobertura"
outputFormats=(cobertura-xml)
excludePackages=(Tests AnotherPackageName)

xcc generate $jsonPath \
   $coberturaTargetPath ${outputFormats[@]} \
   --exclude-packages="${excludePackages[@]} " \
   --verbose

In all the above attempts, I am getting the same error. The items (excluding first item) which I pass for --exclude-packages is considered for output-formats. How to fix this?

Update:

xcc utility does support multiple arguments for --exclude-packages. Reference

Vignesh
  • 3,571
  • 6
  • 28
  • 44
  • Based on your suggestion I tried `--exclude-packages="${excludePackages[@]} "` where I get the same error. When I try with `--exclude-packages "Tests AnotherPackageName"` it considers it as array with 1 element "Tests AnotherPackageName" – Vignesh Sep 07 '21 at 09:46
  • How would you run it without using array at all? Would you do `--exclude-packages something --exclude-packages somethingelse`? In other words, what does `xcc` utility expect to have when user wants to pass multiple arguments to `exclude-packages` and does `xcc` utility support such use case? – KamilCuk Sep 07 '21 at 10:12
  • Yes `xcc` utility supports multiple arguments, here is the reference [link](https://github.com/twittemb/XcodeCoverageConverter/blob/3e668c2b0a9aed9bbc67391d1f9e64232e8edb40/Sources/XcodeCoverageConverter/main.swift#L30) – Vignesh Sep 07 '21 at 11:16

1 Answers1

2

Check your scripts with https://shellcheck.net .

Assuming xcc utility supports multiple --exclude-packages arguments, then: for each array element, add --exclude-packages before each array element, then pass it to the command.

excludePackages=(Tests AnotherPackageName)

cmd=(
    xcc generate
    "$jsonPath"
    "$coberturaTargetPath"
    "${outputFormats[@]}"
)
for ii in "${excludePackages[@]}"; do
   cmd+=(--exclude-packages "$ii")
done
cmd+=(--verbose)

echo "Running: ${cmd[*]}"
"${cmd[@]}"
KamilCuk
  • 120,984
  • 8
  • 59
  • 111