# ============================================================================ #
# Copyright (c) 2022 - 2026 NVIDIA Corporation & Affiliates.                   #
# All rights reserved.                                                         #
#                                                                              #
# This source code and the accompanying materials are made available under     #
# the terms of the Apache License 2.0 which accompanies this distribution.     #
# ============================================================================ #

# Validate that list_simulators excludes QPU targets (those with platform-qpu)
# and library-mode targets (those with library-mode-execution-manager).

# The list_simulators function is used internally by nvq++ when processing
# CUDAQ_DEFAULT_SIMULATOR. We test it by creating temporary target yml files
# and invoking the relevant logic.

# RUN: rm -rf %t && mkdir -p %t/targets

# Create a simulator target (no platform-qpu, no library-mode-execution-manager)
# RUN: echo 'name: fake-sim'              >  %t/targets/fake-sim.yml
# RUN: echo 'config:'                     >> %t/targets/fake-sim.yml
# RUN: echo '  nvqir-simulation-backend: qpp' >> %t/targets/fake-sim.yml

# Create a QPU target (has platform-qpu)
# RUN: echo 'name: fake-qpu'              >  %t/targets/fake-qpu.yml
# RUN: echo 'config:'                     >> %t/targets/fake-qpu.yml
# RUN: echo '  platform-qpu: remote_rest' >> %t/targets/fake-qpu.yml

# Create a library-mode target (has library-mode-execution-manager)
# RUN: echo 'name: fake-libmode'                          >  %t/targets/fake-libmode.yml
# RUN: echo 'config:'                                     >> %t/targets/fake-libmode.yml
# RUN: echo '  library-mode-execution-manager: photonics' >> %t/targets/fake-libmode.yml

# Run list_simulators logic against the temp directory and check results.
# The simulator should appear, but QPU and library-mode targets should not.
# RUN: bash -c '\
# RUN:   install_dir=%t; \
# RUN:   function target_config_files_in_dir { \
# RUN:     local target_dir="$1"; \
# RUN:     if [ ! -d "${target_dir}" ]; then return; fi; \
# RUN:     for file in "${target_dir}"/*.yml; do \
# RUN:       if [ -f "${file}" ]; then echo "${file}"; fi; \
# RUN:     done; \
# RUN:   }; \
# RUN:   for file in $(target_config_files_in_dir "${install_dir}/targets"); do \
# RUN:     if ! grep -q "platform-qpu" $file && ! grep -q "library-mode-execution-manager" $file; then \
# RUN:       echo $(basename $file | cut -d "." -f 1); \
# RUN:     fi; \
# RUN:   done' | FileCheck %s

# CHECK: fake-sim
# CHECK-NOT: fake-qpu
# CHECK-NOT: fake-libmode
