<commit_before>describe 'header.sh', integration: true do
  let(:top) { Pathname.new(ENV.fetch('TOP')) }
  let(:header_sh) { top.join('./lib/travis/build/templates/header.sh') }
  let(:build_dir) { Dir.mktmpdir(%w(travis-build- -header-spec)) }

  after :each do
    FileUtils.rm_rf(build_dir)
  end

  let :header_rendered do
    Travis::Build::Template::Template.new(
      build_dir: build_dir,
      root: build_dir,
      home: build_dir,
      internal_ruby_regex: Travis::Build.config.internal_ruby_regex.untaint
    ).render(header_sh)
  end

  let :bash_body do
    script = ["source $HOME/.build_stages", "export"]
    header_sh.read.split("\n").grep(/^[a-z][a-z_]+\(\) \{/).each do |func|
      script << "type #{func.match(/^(.+)\(\) \{/)[1]}"
    end
    script.join("\n")
  end

  let :bash_output do
    IO.popen(
      [
        'env', '-i', "HOME=#{build_dir}",
        'bash', '-c', header_rendered + bash_body, err: %i(child out)
      ]
    ).read
  end

  it 'can render' do
    expect(header_rendered).to_not be_empty
  end

  %w(
    travis_assert
    travis_cmd
    travis_fold
    travis_internal_ruby
    travis_jigger
    travis_nanoseconds
    travis_result
    travis_retry
    travis_terminate
    travis_time_finish
    travis_time_start
    travis_wait
  ).each do |api_function|
    it "defines #{api_function}" do
      expect(bash_output).to match(/^#{api_function} is a function/)
    end
  end

  {
    SHELL: '/bin/bash',
    TERM: 'xterm',
    USER: 'travis'
  }.each do |env_var, val|
    it "exports #{env_var}" do
      expect(bash_output).to match(/^declare -x #{env_var}="#{val}"$/)
    end
  end
<commit_msg>Relax SHELL export checking<commit_after>describe 'header.sh', integration: true do
  let(:top) { Pathname.new(ENV.fetch('TOP')) }
  let(:header_sh) { top.join('./lib/travis/build/templates/header.sh') }
  let(:build_dir) { Dir.mktmpdir(%w(travis-build- -header-spec)) }

  after :each do
    FileUtils.rm_rf(build_dir)
  end

  let :header_rendered do
    Travis::Build::Template::Template.new(
      build_dir: build_dir,
      root: build_dir,
      home: build_dir,
      internal_ruby_regex: Travis::Build.config.internal_ruby_regex.untaint
    ).render(header_sh)
  end

  let :bash_body do
    script = ["source $HOME/.build_stages", "export"]
    header_sh.read.split("\n").grep(/^[a-z][a-z_]+\(\) \{/).each do |func|
      script << "type #{func.match(/^(.+)\(\) \{/)[1]}"
    end
    script.join("\n")
  end

  let :bash_output do
    IO.popen(
      [
        'env', '-i', "HOME=#{build_dir}",
        'bash', '-c', header_rendered + bash_body, err: %i(child out)
      ]
    ).read
  end

  it 'can render' do
    expect(header_rendered).to_not be_empty
  end

  %w(
    travis_assert
    travis_cmd
    travis_fold
    travis_internal_ruby
    travis_jigger
    travis_nanoseconds
    travis_result
    travis_retry
    travis_terminate
    travis_time_finish
    travis_time_start
    travis_wait
  ).each do |api_function|
    it "defines #{api_function}" do
      expect(bash_output).to match(/^#{api_function} is a function/)
    end
  end

  {
    SHELL: /.+/, # nonempty
    TERM: 'xterm',
    USER: 'travis'
  }.each do |env_var, val|
    it "exports #{env_var}" do
      expect(bash_output).to match(/^declare -x #{env_var}="#{val}"$/)
    end
  end

{'fraction_non_alphanumeric': 0.1555354993983153, 'fraction_numerical': 0.0006016847172081829, 'mean_word_length': 2.898007033997655, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6326799', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1261, 'n_words': 241}