<commit_before>require File.expand_path('../test_helper', __FILE__)
require 'shell_test'

class ReadmeTest < Test::Unit::TestCase
  include ShellTest
  LIBDIR = File.expand_path('../../lib', __FILE__)

  def test_shell_test_example
    script = prepare('test.rb') do |io|
      io << outdent(%q{
        require 'shell_test/unit'

        class ShellTestExample < Test::Unit::TestCase
          include ShellTest

          def test_a_script
            script = prepare('script.sh') do |io|
              io.puts "echo goodnight $1"
            end

            assert_script %{
              $ sh '#{script}' moon
              goodnight moon
            }
          end
        end
      })
    end
    
    result = `ruby -I'#{LIBDIR}' '#{script}'`
    assert_equal 0, $?.exitstatus, indent(result, '    ')
  end
  
  def test_shell_methods_example
    script = prepare('test.rb') do |io|
      io << outdent(%q{
        require 'shell_test/unit'

        class ShellMethodsExample < Test::Unit::TestCase
          include ShellTest::ShellMethods

          def test_a_script_with_env_variables
            with_env("THIS" => "moon") do
              assert_script %{
                $ THAT="boat"
                $ echo "goodnight $THIS"
                goodnight moon
                $ echo "goodnight $THAT"
                goodnight boat
              }
            end
          end

          def test_multiline_commands
            assert_script %{
              $ for n in one two; do
              >   echo $n
              > done
              one
              two
            }
          end

          def test_exit_status
            assert_script %{
              $ false
            }, :exitstatus => 1
          end<commit_msg>oops add test for last commit<commit_after>require File.expand_path('../test_helper', __FILE__)
require 'shell_test'

class ReadmeTest < Test::Unit::TestCase
  include ShellTest
  LIBDIR = File.expand_path('../../lib', __FILE__)

  def test_shell_test_example
    script = prepare('test.rb') do |io|
      io << outdent(%q{
        require 'shell_test/unit'

        class ShellTestExample < Test::Unit::TestCase
          include ShellTest

          def test_a_script
            script = prepare('script.sh') do |io|
              io.puts "echo goodnight $1"
            end

            assert_script %{
              $ sh '#{script}' moon
              goodnight moon
            }, :exitstatus => 0
          end
        end
      })
    end
    
    result = `ruby -I'#{LIBDIR}' '#{script}'`
    assert_equal 0, $?.exitstatus, indent(result, '    ')
  end
  
  def test_shell_methods_example
    script = prepare('test.rb') do |io|
      io << outdent(%q{
        require 'shell_test/unit'

        class ShellMethodsExample < Test::Unit::TestCase
          include ShellTest::ShellMethods

          def test_a_script_with_env_variables
            with_env("THIS" => "moon") do
              assert_script %{
                $ THAT="boat"
                $ echo "goodnight $THIS"
                goodnight moon
                $ echo "goodnight $THAT"
                goodnight boat
              }
            end
          end

          def test_multiline_commands
            assert_script %{
              $ for n in one two; do
              >   echo $n
              > done
              one
              two
            }
          end
{'fraction_non_alphanumeric': 0.09408997353719495, 'fraction_numerical': 0.0017641870038224052, 'mean_word_length': 1.4457225017972681, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, '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': '4771264', 'n_tokens_mistral': 957, 'n_tokens_neox': 906, 'n_words': 225}