#!/usr/bin/env ruby
# frozen_string_literal: true

# This script is used to run the tests for this project.
#
# bundle exec bin/test [test_file_name ...]
#
# If no test file names are provided, all tests in the `tests/units` directory will be run.

require 'bundler/setup'

`git config --global user.email "git@example.com"` if `git config --global user.email`.empty?
`git config --global user.name "GitExample"` if `git config --global user.name`.empty?
`git config --global init.defaultBranch main` if `git config --global init.defaultBranch`.empty?

project_root = File.expand_path(File.join(__dir__, '..'))

$LOAD_PATH.unshift(File.join(project_root, 'tests'))

paths =
  if ARGV.empty?
    Dir.glob('tests/units/test_*.rb').map { |p| File.basename(p) }
  else
    ARGV
  end.map { |p| File.join(project_root, 'tests/units', p) }

paths.each { |p| require p }
