<commit_before>defmodule UARTTest do
  use ExUnit.Case
  alias Nerves.UART

  # Define the following environment variables for your environment:
  #
  #   NERVES_UART_PORT1 - e.g., COM1 or ttyS0
  #   NERVES_UART_PORT2
  #
  # The unit tests expect those ports to exist, be different ports,
  # and be connected to each other through a null modem cable.
  #
  # On Linux, it's possible to use tty0tty. See
  # https://github.com/freemed/tty0tty.
  def port1() do
    System.get_env("NERVES_UART_PORT1")
  end
  def port2() do
    System.get_env("NERVES_UART_PORT2")
  end

  def common_setup() do
    assert !is_nil(port1) && !is_nil(port2),
      "Please define NERVES_UART_PORT1 and NERVES_UART_PORT2 in your
  environment (e.g. to ttyS0 or COM1) and connect them via a null
  modem cable."

    if !String.starts_with?(port1, "tnt") do
        # Let things settle between tests for real serial ports
        :timer.sleep(500)
    end

    {:ok, uart1} = UART.start_link
    {:ok, uart2} = UART.start_link
    {:ok, uart1: uart1, uart2: uart2}
  end
end<commit_msg>Improve help message when env not set for tests<commit_after>defmodule UARTTest do
  use ExUnit.Case
  alias Nerves.UART

  # Define the following environment variables for your environment:
  #
  #   NERVES_UART_PORT1 - e.g., COM1 or ttyS0
  #   NERVES_UART_PORT2
  #
  # The unit tests expect those ports to exist, be different ports,
  # and be connected to each other through a null modem cable.
  #
  # On Linux, it's possible to use tty0tty. See
  # https://github.com/freemed/tty0tty.
  def port1() do
    System.get_env("NERVES_UART_PORT1")
  end
  def port2() do
    System.get_env("NERVES_UART_PORT2")
  end

  def common_setup() do
    if is_nil(port1) || is_nil(port2) do
      msg = "Please define NERVES_UART_PORT1 and NERVES_UART_PORT2 in your
  environment (e.g. to ttyS0 or COM1) and connect them via a null
  modem cable.\n\n"

      ports = UART.enumerate
      if ports == [] do
        msg = msg <> "No serial ports were found. Check your OS to see if they exist"
      else
        msg = msg <> "The following ports were found: #{inspect Map.keys(ports)}"
      end
      flunk msg
    end

    if !String.starts_with?(port1, "tnt") do
        # Let things settle between tests for real serial ports
        :timer.sleep(500)
    end

    {:ok, uart1} = UART.start_link
    {:ok, uart2} = UART.start_link
    {:ok, uart1: uart1, uart2: uart2}
  end
end
{'fraction_non_alphanumeric': 0.08930766079475624, 'fraction_numerical': 0.021302744776730848, 'mean_word_length': 2.9450726978998385, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1413017', 'n_tokens_mistral': 907, 'n_tokens_neox': 869, 'n_words': 277}