<<

NAME

Utils.pm -- some useful helper subroutines.

DESCRIPTION

This module provides general helper subroutines such as parsing config or data files.

Static subroutines

  Utils::get_tmp_dir([tmp_root])

Returns tmp_root/scriptname_process_id_timestamp

This directory is unique in a local file system. The root directory to be used can be specified with tmp_root (optional). The default is D4J_TMP_DIR.

  Utils::get_abs_path(dir)

Returns the absolute path to the directory dir.

  Utils::get_failing_tests(test_result_file)

Determines all failing test classes and test methods in test_result_file, which may contain arbitrary lines. A line indicating a test failure matches the following pattern: /--- ([^:]+)(::([^:]+))?/.

This subroutine returns a reference to a hash that contains three keys (classes, methods, and asserts), which map to lists of failing tests:

  {classes} => [org.foo.Class1 org.bar.Class2]
  {methods} => [org.foo.Class3::method1 org.foo.Class3::method2]
  {asserts} => {org.foo.Class3::method1} => 4711
  Utils::has_failing_tests(result_file)

Returns 1 if the provided result_file lists any failing test classes or failing test methods. Returns 0 otherwise.

  Utils::write_config_file(filename, config_hash)

Writes all key-value pairs of config_hash to a config file named filename. Existing entries are overridden and missing entries are added to the config file -- all existing but unmodified entries are preserved.

  Utils::read_config_file(filename)

Read all key-value pairs of the config file named filename. Format: key=value. Returns a hash containing all key-value pairs on success, undef otherwise.

  Utils::check_vid(vid)

Check whether vid represents a valid version id, i.e., matches \d+[bf].

  Utils::tag_prefix(pid, bid)

Returns the Defects4J prefix for tagging a buggy or fixed program version.

  Utils::exec_cmd(cmd, description [, log_ref])

Runs a system command and indicates whether it succeeded or failed. This subroutine captures the output (stdout) of the command and only logs that output to stderr if the command fails or if Constants::DEBUG is set to true. This subroutine converts exit codes into boolean values, i.e., it returns 1 if the command succeeded and 0 otherwise. If the optional reference log_ref is provided, the captured output is stored in that variable.

  Utils::get_all_test_suites(suite_dir, pid [, vid])

Determines all Defects4J test suite archives that exist in suite_dir and that match the given project id (pid) and version id (vid). Note that vid is optional.

This subroutine returns a reference to a hierarchical hash that holds all matching test suite archives:

  $result->{vid}->{suite_src}->{test_id}->{file_name}
  Utils::extract_test_suite(test_suite, test_dir)

Extracts an archive of an external test suite (test_suite) into a given test directory (test_dir). The directory test_dir is created if it doesn't exist. This subroutine returns 1 on success, 0 otherwise.

<<