<commit_before>require_relative 'test_base'

class BombRobustNessTest < TestBase

  def self.hex_prefix
    '1B5'
  end

  # - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'CD5',
  '[C,assert] fork-bomb does not run indefinitely' do
    with_captured_log {
      run_cyber_dojo_sh({
        changed: { 'hiker.c' => intact(C_FORK_BOMB) },
        max_seconds: 3
      })
    }
    assert timed_out? || printed?('All tests passed'), result
    assert timed_out? || printed?('fork()'), result
  end

  # - - - - - - - - - - - - - - - - - - - - - - - - - -

  multi_os_test 'CD6',
  'shell fork-bomb does not run indefinitely' do
    with_captured_log {
      run_cyber_dojo_sh({
        changed: { 'cyber-dojo.sh' => intact(SHELL_FORK_BOMB) },
        max_seconds: 3
      })
    }
    cant_fork = (os === :Alpine ? "can't fork" : 'Cannot fork')
    assert timed_out? ||
      printed?(cant_fork) ||
        printed?('bomb'), result
  end

  # - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'DB3',
  '[C,assert] file-handles quickly become exhausted' do
    run_cyber_dojo_sh({
      changed: { 'hiker.c' => intact(FILE_HANDLE_BOMB) },
      max_seconds: 3
    })
    assert printed?('fopen() != NULL'),  result
  end<commit_msg>refactoring; capture occasional log output in file-handle exhaustion robustness test<commit_after>require_relative 'test_base'

class BombRobustNessTest < TestBase

  def self.hex_prefix
    '1B5'
  end

  # - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'CD5',
  '[C,assert] fork-bomb does not run indefinitely' do
    with_captured_log {
      run_cyber_dojo_sh({
        changed: { 'hiker.c' => intact(C_FORK_BOMB) },
        max_seconds: 3
      })
    }
    assert timed_out? || printed?('All tests passed'), result
    assert timed_out? || printed?('fork()'), result
  end

  # - - - - - - - - - - - - - - - - - - - - - - - - - -

  multi_os_test 'CD6',
  'shell fork-bomb does not run indefinitely' do
    with_captured_log {
      run_cyber_dojo_sh({
        changed: { 'cyber-dojo.sh' => intact(SHELL_FORK_BOMB) },
        max_seconds: 3
      })
    }
    cant_fork = (os === :Alpine ? "can't fork" : 'Cannot fork')
    assert timed_out? ||
      printed?(cant_fork) ||
        printed?('bomb'), result
  end

  # - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'DB3',
  '[C,assert] file-handles quickly become exhausted' do
    with_captured_log {
      run_cyber_dojo_sh({
        changed: { 'hiker.c' => intact(FILE_HANDLE_BOMB) },
        max_seconds: 3
      })
    }
    assert printed?('fopen() != NULL'),  result
  end
{'fraction_non_alphanumeric': 0.17374665135859166, 'fraction_numerical': 0.006123230003827019, 'mean_word_length': 1.8537117903930131, 'pattern_counts': {'":': 0, '<': 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': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3423523', 'n_tokens_mistral': 1028, 'n_tokens_neox': 984, 'n_words': 179}