name: Tests

on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:
    inputs:
      stress_count:
        description: "Number of times to run stress tests"
        required: false
        default: "10"

jobs:
  test:
    name: cargo-test ...
    runs-on: ubuntu-latest
    env:
      CARGO_TERM_COLOR: always
      RUST_BACKTRACE: 1
      RUST_LOG: trace
      STRESS_COUNT: ${{ github.event.inputs.stress_count || 1 }}
    strategy:
      fail-fast: false
      matrix:
        rust: [stable, beta, nightly]
        runtimes: ["tokio_runtime", "async_runtime", "async_runtime,tokio"]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@nextest

      - name: workspace
        run: cargo nextest run --profile ci --workspace --all-targets --stress-count $STRESS_COUNT

      - name: test (most)
        run: cargo nextest run --profile ci --workspace --all-targets --no-default-features --features ${{matrix.runtimes}} --stress-count $STRESS_COUNT

      - name: lib test ${{matrix.runtimes}}
        run: cargo nextest run --profile ci --workspace --lib --no-default-features --features ${{matrix.runtimes}} --stress-count $STRESS_COUNT

      - name: doc test (default)
        run: cargo test --doc --workspace

      - name: doc test ${{matrix.runtimes}}
        run: cargo test --doc --workspace --no-default-features --features ${{matrix.runtimes}}
