<commit_before>package t::Util;

use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use File::Temp qw(tempfile);
use IO::Socket::INET;
use IO::Socket::SSL;
use IO::Poll qw(POLLIN POLLOUT POLLHUP POLLERR);
use Net::EmptyPort qw(check_port empty_port);
use POSIX ":sys_wait_h";
use Path::Tiny;
use Protocol::HTTP2::Connection;
use Protocol::HTTP2::Constants;
use Scope::Guard qw(scope_guard);
use Test::More;
use Time::HiRes qw(sleep gettimeofday tv_interval);

use base qw(Exporter);
our @EXPORT = qw(ASSETS_DIR DOC_ROOT bindir run_as_root server_features exec_unittest exec_mruby_unittest spawn_server spawn_h2o spawn_h2o_raw empty_ports create_data_file md5_file prog_exists run_prog openssl_can_negotiate curl_supports_http2 run_with_curl h2get_exists run_with_h2get run_with_h2get_simple one_shot_http_upstream wait_debugger spawn_forked spawn_h2_server find_blackhole_ip get_tracer check_dtrace_availability);

use constant ASSETS_DIR => 't/assets';
use constant DOC_ROOT   => ASSETS_DIR . "/doc_root";

sub bindir {
    $ENV{H2O_VALGRIND} || $ENV{BINARY_DIR} || '.';
}

sub run_as_root {
    return if $< == 0;
    exec qw(sudo -E env PERL5LIB=.), $^X, $0;
    die "failed to invoke $0 using sudo:$!";
}

sub server_features {<commit_msg>test: automatically enables autflush for GitHub Actions<commit_after>package t::Util;

use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use File::Temp qw(tempfile);
use IO::Handle ();
use IO::Socket::INET;
use IO::Socket::SSL;
use IO::Poll qw(POLLIN POLLOUT POLLHUP POLLERR);
use Net::EmptyPort qw(check_port empty_port);
use POSIX ":sys_wait_h";
use Path::Tiny;
use Protocol::HTTP2::Connection;
use Protocol::HTTP2::Constants;
use Scope::Guard qw(scope_guard);
use Test::More;
use Time::HiRes qw(sleep gettimeofday tv_interval);

use base qw(Exporter);
our @EXPORT = qw(ASSETS_DIR DOC_ROOT bindir run_as_root server_features exec_unittest exec_mruby_unittest spawn_server spawn_h2o spawn_h2o_raw empty_ports create_data_file md5_file prog_exists run_prog openssl_can_negotiate curl_supports_http2 run_with_curl h2get_exists run_with_h2get run_with_h2get_simple one_shot_http_upstream wait_debugger spawn_forked spawn_h2_server find_blackhole_ip get_tracer check_dtrace_availability);

use constant ASSETS_DIR => 't/assets';
use constant DOC_ROOT   => ASSETS_DIR . "/doc_root";

# autoflush for STDOUT and STDERR is on if they are connected to TTY,
# but they are not connected to TTY in GitHub Actions.
STDOUT->autoflush(1);
STDERR->autoflush(1);

sub bindir {
    $ENV{H2O_VALGRIND} || $ENV{BINARY_DIR} || '.';
}

sub run_as_root {
    return if $< == 0;
    exec qw(sudo -E env PERL5LIB=.), $^X, $0;
    die "failed to invoke $0 using sudo:$!";
}

sub server_features {
{'fraction_non_alphanumeric': 0.10348623853211009, 'fraction_numerical': 0.013211009174311927, 'mean_word_length': 6.766381766381766, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 9, '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': '6378824', 'n_tokens_mistral': 1050, 'n_tokens_neox': 998, 'n_words': 257}