# fss-0005 iki-0002
#
# Performs runtime testing, which includes building the program.
#

settings:
  fail exit
  modes individual individual_thread level monolithic clang test fanalyzer thread threadless

  environment PATH LD_LIBRARY_PATH
  environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH

  # Change this to a valid shell script, such as "bash" or "zsh".
  parameter script bash

  # To build the specific tests files use an empty string instead of "test-".
  parameter test_prefix test-

main:
  build settings
  build settings.eki_read
  build settings.iki_read

  operate build_path
  operate ld_library_path
  operate generate_process
  operate verify_process

verify:
  operate build_path
  operate ld_library_path
  operate verify_process

generate:
  operate build_path
  operate ld_library_path
  operate generate_process

generate_process:
  print
  print Generating Test IKI (0000).
  print

  touch directory parameter:"build_path"test/iki
  run parameter:"script" ./tests/runtime/script/generate.sh parameter:"test_prefix"iki tests/runtime/iki/source/test-0000-basic.iki parameter:"build_path"test/iki

  print
  print Generating Test EKI (0000).
  print

  touch directory parameter:"build_path"test/eki
  run parameter:"script" ./tests/runtime/script/generate.sh parameter:"test_prefix"eki tests/runtime/eki/source/test-0000-basic.eki parameter:"build_path"test/eki

verify_process:
  print
  print Verifying Tests for IKI (0000).
  print
  run parameter:"script" ./tests/runtime/script/verify.sh build/test/iki/ tests/runtime/iki/expect/ "IKI (0000)"

  print
  print Verifying Tests for EKI (0000).
  print
  run parameter:"script" ./tests/runtime/script/verify.sh build/test/eki/ tests/runtime/eki/expect/ "EKI (0000)"

build_path:
  parameter build_path build/

  if parameter build:value
    parameter build_path parameter:"build:value"

  touch directory parameter:"build_path" parameter:"build_path"test

  # Setup the PATH to use the just compiled programs.
  define PATH parameter:"build_path"programs/static:parameter:"build_path"programs/shared:define:"PATH"

ld_library_path:
  if define LD_LIBRARY_PATH
  and parameter work:value
    define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:parameter:"work:value"libraries/shared:define:"LD_LIBRARY_PATH"'

  else
  if define LD_LIBRARY_PATH
    define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:define:"LD_LIBRARY_PATH"'

  else
  if parameter work:value
    define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:parameter:"work:value"libraries/shared'

  else
    define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared'

help:
  print
  print context:'title'Fakefile Options for IKI Read Software Testing.context:'reset'
  print

  print
  print The following operations are available\:
  print "  - context:'notable'help:context:'reset'      Perform the help operation, printing this message."
  print "  - context:'notable'main:context:'reset'      Build the main program, generate the data, and verify the tests."
  print "  - context:'notable'generate:context:'reset'  Generate the data (main program must be built)."
  print "  - context:'notable'verify:context:'reset'    Verify the tests (main program must be built)."
