<commit_before>set(web_client_port 30001)

function(javascript_tests_init)
  if (NOT BUILD_JAVASCRIPT_TESTS)
    return()
  endif()

  add_test(
    NAME js_coverage_reset
    COMMAND "${PYTHON_EXECUTABLE}"
            "${PROJECT_SOURCE_DIR}/tests/js_coverage_tool.py"
            reset
            "${PROJECT_BINARY_DIR}/js_coverage"
  )
  add_test(
    NAME js_coverage_combine_report
    WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
    COMMAND "${PYTHON_EXECUTABLE}"
            "${PROJECT_SOURCE_DIR}/tests/js_coverage_tool.py"
            "--threshold=${JS_COVERAGE_MINIMUM_PASS}"
            "--source=${PROJECT_SOURCE_DIR}"
            combine_report
            "${PROJECT_BINARY_DIR}/js_coverage"
  )
endfunction()

include(${PROJECT_SOURCE_DIR}/scripts/JsonConfigExpandRelpaths.cmake)
include(${PROJECT_SOURCE_DIR}/scripts/JsonConfigMerge.cmake)

function(add_javascript_style_test name input)
  if (NOT BUILD_JAVASCRIPT_TESTS)
    return()
  endif()

  set(_args JSHINT_EXTRA_CONFIGS JSSTYLE_EXTRA_CONFIGS)
  cmake_parse_arguments(fn "${_options}" "${_args}" "${_multival_args}" ${ARGN})

  # jshint
  set(jshint_config "${PROJECT_BINARY_DIR}/tests/${name}_jshint.cfg")
  json_config_merge(
    INPUTFILES
      "${PROJECT_SOURCE_DIR}/tests/jshint.cfg"
      ${fn_JSHINT_EXTRA_CONFIGS}
    OUTPUTFILE
      ${jshint_config}
    )

  # jsstyle
  set(inputfiles
    "${PROJECT_SOURCE_DIR}/tests/jsstyle.cfg"
    ${fn_JSSTYLE_EXTRA_CONFIGS}
    )
  set(expanded_jsstyle_inputfiles)
  foreach(inputfile IN LISTS inputfiles)
    set(outputfile ${CMAKE_CURRENT_BINARY_DIR}/${inputfile})
    get_filename_component(outputdir ${outputfile} PATH)
    file(MAKE_DIRECTORY ${outputdir})
    list(APPEND expanded_jsstyle_inputfiles ${outputfile})
    json_config_expand_relpaths(
      INPUTFILE ${inputfile}
      OUTPUTFILE ${outputfile}
      RELATIVE_PATH_KEYS excludeFiles
      )
  endforeach()

  set(jsstyle_config "${PROJECT_BINARY_DIR}/tests/${name}_jsstyle.cfg")
  json_config_merge(
    INPUTFILES ${expanded_jsstyle_inputfiles}
    OUTPUTFILE ${jsstyle_config}
    )

  # add tests
  set(working_dir "${PROJECT_SOURCE_DIR}/clients/web")
  if(NOT IS_ABSOLUTE ${input})
    set(input ${working_dir}/${input})
  endif()
  if(NOT EXISTS ${input})
    message(FATAL_ERROR "Failed to add javascript style tests."
                        "Directory or file '${input}' does not exist.")
  endif()

  # check if the input is a directory or file and set the working directory
  if(IS_DIRECTORY "${input}")
    set(test_directory "${input}")
  else()
    get_filename_component(test_directory "${input}" DIRECTORY)
  endif()

  add_test(
    NAME "jshint_${name}"
    WORKING_DIRECTORY "${test_directory}"
    COMMAND "${JSHINT_EXECUTABLE}" --config "${jshint_config}" "${input}"
  )
  add_test(
    NAME "jsstyle_${name}"
    WORKING_DIRECTORY "${test_directory}"
    COMMAND "${JSSTYLE_EXECUTABLE}"  --config "${jsstyle_config}" "${input}"
  )
endfunction()

function(add_web_client_test case specFile)
  # test a web client using a spec file and the specRunner
  # :param case: the name of this test case
  # :param specFile: the path of the spec file to run
  # Optional parameters:
  # PLUGIN (name of plugin) : this plugin is loaded (unless overridden with
  #     ENABLEDPLUGINS) and the test name includes the plugin name
  # PLUGIN_DIRS (list of plugin dirs) : A list of directories plugins
  # should live in.
  # ASSETSTORE (assetstore type) : use the specified assetstore type when
  #     running the test.  Defaults to 'filesystem'
  # WEBSECURITY (boolean) : if false, don't use CORS validatation.  Defaults to
  #     'true'
  # ENABLEDPLUGINS (list of plugins): A list of plugins to load.  If PLUGIN is
  #     specified, this overrides loading that plugin, so it probably should be
  #     included in this list, too.
  # RESOURCE_LOCKS (list of resources): A list of resources that this test
  #     needs exclusive access to.  Defaults to mongo and cherrypy.
  # TIMEOUT (seconds): An overall test timeout.
  # BASEURL (url): The base url to load for the test.
  if (NOT BUILD_JAVASCRIPT_TESTS)
    return()
  endif()

  set(testname "web_client_${case}")

  set(_options NOCOVERAGE)
  set(_args PLUGIN ASSETSTORE WEBSECURITY BASEURL PLUGIN_DIRS)
  set(_multival_args RESOURCE_LOCKS TIMEOUT ENABLEDPLUGINS)
  cmake_parse_arguments(fn "${_options}" "${_args}" "${_multival_args}" ${ARGN})<commit_msg>Changing TIMEOUT to be a single value argument<commit_after>set(web_client_port 30001)

function(javascript_tests_init)
  if (NOT BUILD_JAVASCRIPT_TESTS)
    return()
  endif()

  add_test(
    NAME js_coverage_reset
    COMMAND "${PYTHON_EXECUTABLE}"
            "${PROJECT_SOURCE_DIR}/tests/js_coverage_tool.py"
            reset
            "${PROJECT_BINARY_DIR}/js_coverage"
  )
  add_test(
    NAME js_coverage_combine_report
    WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
    COMMAND "${PYTHON_EXECUTABLE}"
            "${PROJECT_SOURCE_DIR}/tests/js_coverage_tool.py"
            "--threshold=${JS_COVERAGE_MINIMUM_PASS}"
            "--source=${PROJECT_SOURCE_DIR}"
            combine_report
            "${PROJECT_BINARY_DIR}/js_coverage"
  )
endfunction()

include(${PROJECT_SOURCE_DIR}/scripts/JsonConfigExpandRelpaths.cmake)
include(${PROJECT_SOURCE_DIR}/scripts/JsonConfigMerge.cmake)

function(add_javascript_style_test name input)
  if (NOT BUILD_JAVASCRIPT_TESTS)
    return()
  endif()

  set(_args JSHINT_EXTRA_CONFIGS JSSTYLE_EXTRA_CONFIGS)
  cmake_parse_arguments(fn "${_options}" "${_args}" "${_multival_args}" ${ARGN})

  # jshint
  set(jshint_config "${PROJECT_BINARY_DIR}/tests/${name}_jshint.cfg")
  json_config_merge(
    INPUTFILES
      "${PROJECT_SOURCE_DIR}/tests/jshint.cfg"
      ${fn_JSHINT_EXTRA_CONFIGS}
    OUTPUTFILE
      ${jshint_config}
    )

  # jsstyle
  set(inputfiles
    "${PROJECT_SOURCE_DIR}/tests/jsstyle.cfg"
    ${fn_JSSTYLE_EXTRA_CONFIGS}
    )
  set(expanded_jsstyle_inputfiles)
  foreach(inputfile IN LISTS inputfiles)
    set(outputfile ${CMAKE_CURRENT_BINARY_DIR}/${inputfile})
    get_filename_component(outputdir ${outputfile} PATH)
    file(MAKE_DIRECTORY ${outputdir})
    list(APPEND expanded_jsstyle_inputfiles ${outputfile})
    json_config_expand_relpaths(
      INPUTFILE ${inputfile}
      OUTPUTFILE ${outputfile}
      RELATIVE_PATH_KEYS excludeFiles
      )
  endforeach()

  set(jsstyle_config "${PROJECT_BINARY_DIR}/tests/${name}_jsstyle.cfg")
  json_config_merge(
    INPUTFILES ${expanded_jsstyle_inputfiles}
    OUTPUTFILE ${jsstyle_config}
    )

  # add tests
  set(working_dir "${PROJECT_SOURCE_DIR}/clients/web")
  if(NOT IS_ABSOLUTE ${input})
    set(input ${working_dir}/${input})
  endif()
  if(NOT EXISTS ${input})
    message(FATAL_ERROR "Failed to add javascript style tests."
                        "Directory or file '${input}' does not exist.")
  endif()

  # check if the input is a directory or file and set the working directory
  if(IS_DIRECTORY "${input}")
    set(test_directory "${input}")
  else()
    get_filename_component(test_directory "${input}" DIRECTORY)
  endif()

  add_test(
    NAME "jshint_${name}"
    WORKING_DIRECTORY "${test_directory}"
    COMMAND "${JSHINT_EXECUTABLE}" --config "${jshint_config}" "${input}"
  )
  add_test(
    NAME "jsstyle_${name}"
    WORKING_DIRECTORY "${test_directory}"
    COMMAND "${JSSTYLE_EXECUTABLE}"  --config "${jsstyle_config}" "${input}"
  )
endfunction()

function(add_web_client_test case specFile)
  # test a web client using a spec file and the specRunner
  # :param case: the name of this test case
  # :param specFile: the path of the spec file to run
  # Optional parameters:
  # PLUGIN (name of plugin) : this plugin is loaded (unless overridden with
  #     ENABLEDPLUGINS) and the test name includes the plugin name
  # PLUGIN_DIRS (list of plugin dirs) : A list of directories plugins
  # should live in.
  # ASSETSTORE (assetstore type) : use the specified assetstore type when
  #     running the test.  Defaults to 'filesystem'
  # WEBSECURITY (boolean) : if false, don't use CORS validatation.  Defaults to
  #     'true'
  # ENABLEDPLUGINS (list of plugins): A list of plugins to load.  If PLUGIN is
  #     specified, this overrides loading that plugin, so it probably should be
  #     included in this list, too.
  # RESOURCE_LOCKS (list of resources): A list of resources that this test
  #     needs exclusive access to.  Defaults to mongo and cherrypy.
  # TIMEOUT (seconds): An overall test timeout.
  # BASEURL (url): The base url to load for the test.
  if (NOT BUILD_JAVASCRIPT_TESTS)
    return()
  endif()

  set(testname "web_client_${case}")

  set(_options NOCOVERAGE)
  set(_args PLUGIN ASSETSTORE WEBSECURITY BASEURL PLUGIN_DIRS TIMEOUT)
  set(_multival_args RESOURCE_LOCKS ENABLEDPLUGINS)
  cmake_parse_arguments(fn "${_options}" "${_args}" "${_multival_args}" ${ARGN})
{'fraction_non_alphanumeric': 0.10553613710677641, 'fraction_numerical': 0.0011275228323373548, 'mean_word_length': 4.016968325791855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '7630999', 'n_tokens_mistral': 3062, 'n_tokens_neox': 2947, 'n_words': 694}