Repository: apple/swift
File: test/Interop/Cxx/stdlib/overlay/custom-iterator-typechecker.swift (Swift)

Code before:
// RUN: %target-typecheck-verify-swift -verify-ignore-unrelated -suppress-notes -I %S/Inputs -cxx-interoperability-mode=default -Xcc -std=c++20 -DCPP20 -verify-additional-prefix cpp20-
// RUN: %target-typecheck-verify-swift -verify-ignore-unrelated -suppress-notes -I %S/Inputs -cxx-interoperability-mode=default

// Check whether each of the custom iterator types in Inputs/custom-iterator.h
// conform to the various iterator protocols from the C++ overlay.
//
// Note that we only detect contiguous iterator when C++'20 is enabled.

import CustomIterator

func checkInput<It: UnsafeCxxInputIterator>(_ _: It) {}
func checkRandomAccess<It: UnsafeCxxRandomAccessIterator>(_ _: It) {}
func checkContiguous<It: UnsafeCxxContiguousIterator>(_ _: It) {}
func checkMutableInput<It: UnsafeCxxMutableInputIterator>(_ _: It) {}
func checkMutableRandomAccess<It: UnsafeCxxMutableRandomAccessIterator>(_ _: It) {}
func checkMutableContiguous<It: UnsafeCxxMutableContiguousIterator>(_ _: It) {}

func check(it: ConstIterator) {
  checkInput(it)
  checkRandomAccess(it)         // expected-error {{requires}}
  checkContiguous(it)           // expected-error {{requires}}
  checkMutableInput(it)         // expected-error {{requires}}
  checkMutableRandomAccess(it)  // expected-error {{requires}}
  checkMutableContiguous(it)    // expected-error {{requires}}
}

func check(it: ConstRACIterator) {
  checkInput(it)
  checkRandomAccess(it)
  checkContiguous(it)           // expected-error {{requires}}
  checkMutableInput(it)         // expected-error {{requires}}
  checkMutableRandomAccess(it)  // expected-error {{requires}}
  checkMutableContiguous(it)    // expected-error {{requires}}

Review comment (suggestion):
@hnrklssn, do we know for sure that such `%if (condition) %{` logic works on all supported OS platform CI now? If so, is that because of your recent work to switch all CI to the lit shell?

I ask because I know in the past people have tried to use bash and other shells' logic in lit tests like this and that broke the ability to run those tests across all supported OS platforms.

Code after:
// Check whether each of the custom iterator types in Inputs/custom-iterator.h
// conform to the various iterator protocols from the C++ overlay.
//
// Note that we only detect contiguous iterator when C++'20 is enabled.
// This is disabled for some distributions that are known to lack support for
// contiguous iterators.
//
// RUN: %if !(LinuxDistribution=ubuntu-20.04 || LinuxDistribution=amzn-2) %{ \
// RUN:   %target-typecheck-verify-swift -verify-ignore-unrelated -suppress-notes -I %S/Inputs -cxx-interoperability-mode=default -Xcc -std=c++20 -DCPP20 -verify-additional-prefix cpp20- \
// RUN: %}
// RUN: %target-typecheck-verify-swift -verify-ignore-unrelated -suppress-notes -I %S/Inputs -cxx-interoperability-mode=default

import CustomIterator

func checkInput<It: UnsafeCxxInputIterator>(_ _: It) {}
func checkRandomAccess<It: UnsafeCxxRandomAccessIterator>(_ _: It) {}
func checkContiguous<It: UnsafeCxxContiguousIterator>(_ _: It) {}
func checkMutableInput<It: UnsafeCxxMutableInputIterator>(_ _: It) {}
func checkMutableRandomAccess<It: UnsafeCxxMutableRandomAccessIterator>(_ _: It) {}
func checkMutableContiguous<It: UnsafeCxxMutableContiguousIterator>(_ _: It) {}

func check(it: ConstIterator) {
  checkInput(it)
  checkRandomAccess(it)         // expected-error {{requires}}
  checkContiguous(it)           // expected-error {{requires}}
  checkMutableInput(it)         // expected-error {{requires}}
  checkMutableRandomAccess(it)  // expected-error {{requires}}
  checkMutableContiguous(it)    // expected-error {{requires}}
}

func check(it: ConstRACIterator) {
  checkInput(it)
  checkRandomAccess(it)