<commit_before>total_coverage_file = 'coverage.txt' # This path is specified by codecov.

task :build do
  sh 'go build -o bin/tisp src/cmd/tisp/main.go'
end

task :fast_unit_test do
  sh 'go test ./...'
end

task :unit_test do
  coverage_file = "/tmp/tisp-unit-test-#{Process.pid}.coverage"

  `go list ./...`.split.each do |package|
    sh %W[go test
          -covermode atomic
          -coverprofile #{coverage_file}
          -race
          #{package}].join(' ')

    verbose false do
      if File.exist? coverage_file
        sh "cat #{coverage_file} >> #{total_coverage_file}"
        rm coverage_file
      end
    end
  end
end

task :test_build do
  sh 'go test -c -cover '\
     "-coverpkg $(go list ./... | perl -0777 -pe 's/\\n(.)/,\\1/g') "\
     './src/cmd/tisp'
  mkdir_p 'bin'
  mv 'tisp.test', 'bin'

  File.write 'bin/tisp', [
    '#!/bin/sh',
    'file=/tmp/tisp-test-$$.out',
    'coverage_file=/tmp/tisp-test-$$.coverage',
    %(ARGS="$@" #{File.absolute_path 'bin/tisp.test'} )\
    + '-test.coverprofile $coverage_file > $file &&',
    "cat $file | perl -0777 -pe 's/(.*)PASS.*/\\1/s' &&",
    'rm $file &&',
    "cat $coverage_file >> #{total_coverage_file} &&",
    'rm $coverage_file'
  ].join("\n") + "\n"

  chmod 0o755, 'bin/tisp'
end

task command_test: :test_build do
  tmp_dir = 'tmp'
  mkdir_p tmp_dir

  Dir.glob('test/*.tisp').each do |file|
    shell_script = file.ext '.sh'
<commit_msg>Improve style of rakefile<commit_after>total_coverage_file = 'coverage.txt' # This path is specified by codecov.

task :build do
  sh 'go build -o bin/tisp src/cmd/tisp/main.go'
end

task :fast_unit_test do
  sh 'go test ./...'
end

task :unit_test do
  coverage_file = "/tmp/tisp-unit-test-#{Process.pid}.coverage"

  `go list ./...`.split.each do |package|
    sh %W[go test
          -covermode atomic
          -coverprofile #{coverage_file}
          -race
          #{package}].join ' '

    verbose false do
      if File.exist? coverage_file
        sh "cat #{coverage_file} >> #{total_coverage_file}"
        rm coverage_file
      end
    end
  end
end

task :test_build do
  sh %w[go test -c -cover
        -coverpkg $(go list ./... | perl -0777 -pe 's/\\n(.)/,\\1/g')
        ./src/cmd/tisp].join ' '
  mkdir_p 'bin'
  mv 'tisp.test', 'bin'

  File.write 'bin/tisp', [
    '#!/bin/sh',
    'file=/tmp/tisp-test-$$.out',
    'coverage_file=/tmp/tisp-test-$$.coverage',
    %(ARGS="$@" #{File.absolute_path 'bin/tisp.test'} )\
    + '-test.coverprofile $coverage_file > $file &&',
    "cat $file | perl -0777 -pe 's/(.*)PASS.*/\\1/s' &&",
    'rm $file &&',
    "cat $coverage_file >> #{total_coverage_file} &&",
    'rm $coverage_file'
  ].join("\n") + "\n"

  chmod 0o755, 'bin/tisp'
end

task command_test: :test_build do
  tmp_dir = 'tmp'
  mkdir_p tmp_dir

  Dir.glob('test/*.tisp').each do |file|
    shell_script = file.ext '.sh'

{'fraction_non_alphanumeric': 0.18580375782881003, 'fraction_numerical': 0.009742519137091163, 'mean_word_length': 2.447242206235012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '7265036', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1106, 'n_words': 253}