<commit_before>desc 'Create an application generator'
task :new do
  OrigenAppGenerators::New.start []
end

desc 'Test run the new app process'
task :test, [:set] do |t, args|
  _delete_tmp_dir
  if args[:set]
    vals = OrigenAppGenerators::TEST_INPUTS[args[:set].to_i]
    vals.pop # Throw away the test commands
    str = vals.map { |i| i == :default ? "\n" : "#{i}\n" }.join('')
    result = system "echo '#{str}' | rake test"
  else
    result = _execute_generator(:invoke)
  end
  exit 1 unless result
end

desc "Test run a specific generator: rake 'run[TestEngineering::GenericTestBlock]'"
task :run, [:generator_class] do |_t, args|
  _delete_tmp_dir
  begin
    klass = eval(args[:generator_class])
  rescue
    klass = eval("OrigenAppGenerators::#{args[:generator_class]}")
  end
  _execute_generator(klass)
end

desc 'Test that all generators build'
task :regression do
  OrigenAppGenerators::TEST_INPUTS.each do |inputs|
    # Default test that are run for all app builds
    commands = ['origen -v',
                'origen lint',
                'rake new_app_tests:load_target',
                'origen web compile --no-serve',
               ] + inputs.pop
    if ENV['TRAVIS'] && ENV['CONTINUOUS_INTEGRATION']
      prefix = 'bundle && bundle exec '
    end
    str = inputs.map { |i| i == :default ? "\n" : "#{i}\n" }.join('')
    # Test the app can build
    unless system "echo '#{str}' | rake test"
      Origen.app.stats.report_fail
      exit 1
    end
    # Copy the new app test rake tasks to the new app
    t = File.expand_path('../new_app_tests.rake', Pathname.new(__FILE__).realpath)
    FileUtils.cp t, 'tmp/lib/tasks'
    # Test the app can boot
    Bundler.with_clean_env do
      Dir.chdir 'tmp' do
        commands.each do |command|
          Origen.log.info "Running command: #{command}"
          unless system("#{prefix}#{command}")
            Origen.app.stats.report_fail
            exit 1
          end
          Origen.log.success "Command passed: #{command}"
        end
      end
    end
  end
  Origen.app.stats.report_pass
end

def _execute_generator(klass)
  # With the generator identified this now launches it in a standalone shell
  # This is to emulate how it will run in real life and cause it to fail if there are
  # any dependencies on running within an Origen app environment

  boot = "#{File.expand_path(File.dirname(__FILE__))}/boot.rb"
  origen_lib = "#{Origen.top}/lib"
  origen_lib = '/proj/mem_c40tfs_testeng/r49409/origen/lib'
  cmd = "#{boot} #{origen_lib} #{klass}"
  cmd = "ruby #{cmd}" if Origen.running_on_windows?
  # puts cmd
  result = false
  Bundler.with_clean_env do
    result = system cmd
  end
  result
end

def _delete_tmp_dir
  sh "rm -rf #{Origen.root}/tmp", verbose: false do |ok, _res|
    # Sometimes vim can lock a dir if the file is being viewed, trying again will
    # usually finish the job
    unless ok
      sh "rm -rf #{Origen.root}/tmp", verbose: false do |ok, _res|
        unless ok
          # I did my best!
        end
      end
    end
  end
end
<commit_msg>Lint cleanup<commit_after>desc 'Create an application generator'
task :new do
  OrigenAppGenerators::New.start []
end

desc 'Test run the new app process'
task :test, [:set] do |t, args|
  _delete_tmp_dir
  if args[:set]
    vals = OrigenAppGenerators::TEST_INPUTS[args[:set].to_i]
    vals.pop # Throw away the test commands
    str = vals.map { |i| i == :default ? "\n" : "#{i}\n" }.join('')
    result = system "echo '#{str}' | rake test"
  else
    result = _execute_generator(:invoke)
  end
  exit 1 unless result
end

desc "Test run a specific generator: rake 'run[TestEngineering::GenericTestBlock]'"
task :run, [:generator_class] do |_t, args|
  _delete_tmp_dir
  begin
    klass = eval(args[:generator_class])
  rescue
    klass = eval("OrigenAppGenerators::#{args[:generator_class]}")
  end
  _execute_generator(klass)
end

desc 'Test that all generators build'
task :regression do
  OrigenAppGenerators::TEST_INPUTS.each do |inputs|
    # Default test that are run for all app builds
    commands = ['origen -v',
                'origen lint',
                'rake new_app_tests:load_target',
                'origen web compile --no-serve'
               ] + inputs.pop
    if ENV['TRAVIS'] && ENV['CONTINUOUS_INTEGRATION']
      prefix = 'bundle && bundle exec '
    end
    str = inputs.map { |i| i == :default ? "\n" : "#{i}\n" }.join('')
    # Test the app can build
    unless system "echo '#{str}' | rake test"
      Origen.app.stats.report_fail
      exit 1
    end
    # Copy the new app test rake tasks to the new app
    t = File.expand_path('../new_app_tests.rake', Pathname.new(__FILE__).realpath)
    FileUtils.cp t, 'tmp/lib/tasks'
    # Test the app can boot
    Bundler.with_clean_env do
      Dir.chdir 'tmp' do
        commands.each do |command|
          Origen.log.info "Running command: #{command}"
          unless system("#{prefix}#{command}")
            Origen.app.stats.report_fail
            exit 1
          end
          Origen.log.success "Command passed: #{command}"
        end
      end
    end
  end
  Origen.app.stats.report_pass
end

def _execute_generator(klass)
  # With the generator identified this now launches it in a standalone shell
  # This is to emulate how it will run in real life and cause it to fail if there are
  # any dependencies on running within an Origen app environment

  boot = "#{File.expand_path(File.dirname(__FILE__))}/boot.rb"
  origen_lib = "#{Origen.top}/lib"
  origen_lib = '/proj/mem_c40tfs_testeng/r49409/origen/lib'
  cmd = "#{boot} #{origen_lib} #{klass}"
  cmd = "ruby #{cmd}" if Origen.running_on_windows?
  # puts cmd
  result = false
  Bundler.with_clean_env do
    result = system cmd
  end
  result
end

def _delete_tmp_dir
  sh "rm -rf #{Origen.root}/tmp", verbose: false do |ok, _res|
    # Sometimes vim can lock a dir if the file is being viewed, trying again will
    # usually finish the job
    unless ok
      sh "rm -rf #{Origen.root}/tmp", verbose: false do |ok, _res|
        unless ok
          # I did my best!
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1130192999672882, 'fraction_numerical': 0.0032711808963035655, 'mean_word_length': 2.807596513075965, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2619850', 'n_tokens_mistral': 2029, 'n_tokens_neox': 2010, 'n_words': 633}