- block:
  - name: test installing a collection with an invalid float version value
    command: 'ansible-galaxy collection install git+file://{{ test_error_repo_path }}/.git#float_version_collection -vvvvvv'
    ignore_errors: yes
    register: invalid_version_result

  - assert:
      that:
        - invalid_version_result is failed
        - msg in invalid_version_result.stderr
    vars:
      req: error_test.float_version_collection:1.0
      ver: "1.0 (<class 'float'>)"
      msg: "Invalid version found for the collection '{{ req }}': {{ ver }}. A SemVer-compliant version or '*' is required."

  - name: test installing a collection with an invalid non-SemVer string version value
    command: 'ansible-galaxy collection install git+file://{{ test_error_repo_path }}/.git#not_semantic_version_collection -vvvvvv'
    ignore_errors: yes
    register: invalid_version_result

  - assert:
      that:
        - invalid_version_result is failed
        - msg in invalid_version_result.stderr
    vars:
      req: error_test.not_semantic_version_collection:1.0
      ver: "1.0 (<class 'str'>)"
      msg: "Invalid version found for the collection '{{ req }}': {{ ver }}. A SemVer-compliant version or '*' is required."

  - name: test installing a collection with an invalid list version value
    command: 'ansible-galaxy collection install git+file://{{ test_error_repo_path }}/.git#list_version_collection -vvvvvv'
    ignore_errors: yes
    register: invalid_version_result

  - assert:
      that:
        - invalid_version_result is failed
        - msg in invalid_version_result.stderr
    vars:
      req: "error_test.list_version_collection:['1.0.0']"
      msg: "Invalid version found for the collection '{{ req }}'. A SemVer-compliant version or '*' is required."

  - name: test installing a collection with an invalid dict version value
    command: 'ansible-galaxy collection install git+file://{{ test_error_repo_path }}/.git#dict_version_collection -vvvvvv'
    ignore_errors: yes
    register: invalid_version_result

  - assert:
      that:
        - invalid_version_result is failed
        - msg in invalid_version_result.stderr
    vars:
      req: "error_test.dict_version_collection:{'broken': 'version'}"
      msg: "Invalid version found for the collection '{{ req }}'. A SemVer-compliant version or '*' is required."

  always:
  - include_tasks: ./empty_installed_collections.yml
    when: cleanup
