Sha256: 495e38ad2df5b17fba8b40edae1b0d0678e9e2de23f1a521f00a22558578ff75

Contents?: true

Size: 1.74 KB

Versions: 13

Compression:

Stored size: 1.74 KB

Contents

require 'test/unit'
require 'cute/bash'

class TestBash < Test::Unit::TestCase

    def with_bash(cmd = 'bash', &block)
        return Cute::Bash.bash(cmd, &block)
    end

    def assert_status_error(&block)
        throws = false
        begin
            with_bash(&block)
        rescue Cute::Bash::StatusError
            throws = true
        end
        assert_equal throws, true
    end

    def test_files_dirs
        with_bash do
            cd '/'
            assert pwd == '/'
            assert dirs.include?('bin')
            cd 'tmp'
            assert pwd == '/tmp'
            run 'rm -rf /tmp/bash_tests'
            mkdir 'bash_tests'
            cd 'bash_tests'
            assert ls == []
            touch 'file'
            assert ls == [ 'file' ]
            assert ls == files
            mv 'file', 'backup'
            assert ls == [ 'backup' ]
            mkdir 'subdir'
            assert ls.length == 2
            assert dirs == [ 'subdir' ]
            cp 'backup', 'subdir/whatever'
            cd 'subdir'
            assert ls == [ 'whatever' ]
            cd '..'
            assert abspath('subdir/hmmm') == '/tmp/bash_tests/subdir/hmmm'

            f = tmp_file()
            assert exists(f)
            assert get_type(f) == :file
            assert get_type('/var') == :dir
            append_line f, "1st"
            append_lines f, [ "2nd", "3rd" ]
            assert cat(f) == contents(f)
            lines = cat(f)
            assert lines == "1st\n2nd\n3rd\n"
        end
    end

    def test_utils
        with_bash do
            assert (echo 'anybody?') == ("anybody?\n")
            assert (bc '2 + 2 * 2') == '6'
        end
    end

    def test_error
        assert_status_error do
            rm '/'
        end
    end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ruby-cute-0.24 test/test_bash.rb
ruby-cute-0.13 test/test_bash.rb
ruby-cute-0.12 test/test_bash.rb
ruby-cute-0.11 test/test_bash.rb
ruby-cute-0.10 test/test_bash.rb
ruby-cute-0.9 test/test_bash.rb
ruby-cute-0.8 test/test_bash.rb
ruby-cute-0.7 test/test_bash.rb
ruby-cute-0.6 test/test_bash.rb
ruby-cute-0.5 test/test_bash.rb
ruby-cute-0.4 test/test_bash.rb
ruby-cute-0.3 test/test_bash.rb
ruby-cute-0.0.2 test/test_bash.rb