Module: Treebis::Test::TestColorAndRmAndMoveAndPatch

Included in:
TestCase
Defined in:
lib/treebis.rb

Instance Method Summary collapse

Instance Method Details

#setup_sourcedirObject



1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
# File 'lib/treebis.rb', line 1078

def setup_sourcedir
  src_dir = tmpdir+'/banana'
  # return if File.exist?(src_dir)
  task = Treebis::Task.new do
    rm_rf
    mkdir_p
    mkdir_p 'dir1'
    write 'dir1/stooges.txt.diff', <<-FILE
      --- a/stooges.txt    2010-04-25 03:23:18.000000000 -0400
      +++ b/stooges.txt    2010-04-25 03:23:12.000000000 -0400
      @@ -1,2 +1,3 @@
       larry
      +moe
       curly
    FILE

    write 'stooges.orig.txt', <<-FILE
      larry
      curly
    FILE

    write 'treebis-task.rb', <<-FILE
      Treebis.tasks.task(:banana) do
        copy './stooges.orig.txt'
        mkdir_p_unless_exists './dir1'
        move './stooges.orig.txt', './dir1/stooges.txt'
        apply './dir1/stooges.txt.diff'
      end
    FILE
  end
  task.on(src_dir).run
end

#test_moveObject



1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
# File 'lib/treebis.rb', line 1110

def test_move
  setup_sourcedir
  task = Treebis.dir_task(tmpdir+'/banana')
  out_dir = tmpdir+'/test-move-output'
  file_utils.remove_entry_secure(out_dir) if File.exist?(out_dir)
  file_utils.mkdir_p(out_dir)
  task.on(out_dir).run
  tree = dir_as_hash(out_dir)
  assert_equal({"dir1"=>{"stooges.txt"=>"larry\nmoe\ncurly\n"}}, tree)
end

#test_no_colorObject



1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
# File 'lib/treebis.rb', line 1053

def test_no_color
  t = task.new do
    report_action :fake, "blah"
  end
  Treebis::Config.no_color!
  out = t.ui_capture{ on('x').run }

  Treebis::Config.color!
  assert_equal("      fake blah\n", out)
end

#test_no_overwriteObject



1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File 'lib/treebis.rb', line 1063

def test_no_overwrite
  dir = tmpdir + '/no-overwrite/'
  Fu.remove_entry_secure(dir) if File.exist?(dir)
  t = task.new do
    mkdir_p_unless_exists
    write 'foo.txt','blah content'
  end
  t2 = task.new do
    write 'foo.txt','blah content again'
  end
  str1 = t.ui_capture{ on(dir).run }
  str2 = t2.ui_capture{ on(dir).run }
  assert_match( /wrote/, str1 )
  assert_match( /won/, str2 )
end

#test_rm_rfObject



1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
# File 'lib/treebis.rb', line 1041

def test_rm_rf
  t = task.new do
    rm_rf
    mkdir_p
    write('foo.txt', "hi i'm foo")
  end
  out = tmpdir+'/blearg'
  t.on(out).run
  t.on(out).run
  tree = dir_as_hash(out)
  assert_equal({"foo.txt"=>"hi i'm foo"}, tree)
end