craigmarksmith-rake 0.8.3.100

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/CHANGES +427 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +196 -0
  4. data/Rakefile +416 -0
  5. data/TODO +20 -0
  6. data/bin/rake +31 -0
  7. data/doc/command_line_usage.rdoc +102 -0
  8. data/doc/example/Rakefile1 +38 -0
  9. data/doc/example/Rakefile2 +35 -0
  10. data/doc/example/a.c +6 -0
  11. data/doc/example/b.c +6 -0
  12. data/doc/example/main.c +11 -0
  13. data/doc/glossary.rdoc +51 -0
  14. data/doc/jamis.rb +591 -0
  15. data/doc/proto_rake.rdoc +127 -0
  16. data/doc/rake.1.gz +0 -0
  17. data/doc/rakefile.rdoc +534 -0
  18. data/doc/rational.rdoc +151 -0
  19. data/doc/release_notes/rake-0.4.14.rdoc +23 -0
  20. data/doc/release_notes/rake-0.4.15.rdoc +35 -0
  21. data/doc/release_notes/rake-0.5.0.rdoc +53 -0
  22. data/doc/release_notes/rake-0.5.3.rdoc +78 -0
  23. data/doc/release_notes/rake-0.5.4.rdoc +46 -0
  24. data/doc/release_notes/rake-0.6.0.rdoc +141 -0
  25. data/doc/release_notes/rake-0.7.0.rdoc +119 -0
  26. data/doc/release_notes/rake-0.7.1.rdoc +59 -0
  27. data/doc/release_notes/rake-0.7.2.rdoc +121 -0
  28. data/doc/release_notes/rake-0.7.3.rdoc +47 -0
  29. data/doc/release_notes/rake-0.8.0.rdoc +114 -0
  30. data/doc/release_notes/rake-0.8.2.rdoc +165 -0
  31. data/doc/release_notes/rake-0.8.3.rdoc +112 -0
  32. data/doc/release_notes/rake-0.8.4.rdoc +147 -0
  33. data/install.rb +88 -0
  34. data/lib/rake/classic_namespace.rb +8 -0
  35. data/lib/rake/clean.rb +33 -0
  36. data/lib/rake/contrib/compositepublisher.rb +24 -0
  37. data/lib/rake/contrib/ftptools.rb +153 -0
  38. data/lib/rake/contrib/publisher.rb +75 -0
  39. data/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  40. data/lib/rake/contrib/sshpublisher.rb +47 -0
  41. data/lib/rake/contrib/sys.rb +209 -0
  42. data/lib/rake/gempackagetask.rb +97 -0
  43. data/lib/rake/loaders/makefile.rb +42 -0
  44. data/lib/rake/packagetask.rb +184 -0
  45. data/lib/rake/rake_test_loader.rb +5 -0
  46. data/lib/rake/rdoctask.rb +209 -0
  47. data/lib/rake/ruby182_test_unit_fix.rb +23 -0
  48. data/lib/rake/runtest.rb +23 -0
  49. data/lib/rake/tasklib.rb +23 -0
  50. data/lib/rake/testtask.rb +161 -0
  51. data/lib/rake/win32.rb +55 -0
  52. data/lib/rake.rb +2519 -0
  53. data/test/capture_stdout.rb +26 -0
  54. data/test/check_expansion.rb +5 -0
  55. data/test/contrib/test_sys.rb +47 -0
  56. data/test/data/chains/Rakefile +15 -0
  57. data/test/data/default/Rakefile +19 -0
  58. data/test/data/dryrun/Rakefile +22 -0
  59. data/test/data/file_creation_task/Rakefile +33 -0
  60. data/test/data/imports/Rakefile +19 -0
  61. data/test/data/imports/deps.mf +1 -0
  62. data/test/data/multidesc/Rakefile +17 -0
  63. data/test/data/namespace/Rakefile +57 -0
  64. data/test/data/rakelib/test1.rb +3 -0
  65. data/test/data/rbext/rakefile.rb +3 -0
  66. data/test/data/sample.mf +14 -0
  67. data/test/data/statusreturn/Rakefile +8 -0
  68. data/test/data/unittest/Rakefile +1 -0
  69. data/test/filecreation.rb +32 -0
  70. data/test/functional.rb +15 -0
  71. data/test/in_environment.rb +30 -0
  72. data/test/rake_test_setup.rb +24 -0
  73. data/test/reqfile.rb +3 -0
  74. data/test/reqfile2.rb +3 -0
  75. data/test/session_functional.rb +339 -0
  76. data/test/shellcommand.rb +3 -0
  77. data/test/test_application.rb +690 -0
  78. data/test/test_clean.rb +14 -0
  79. data/test/test_definitions.rb +85 -0
  80. data/test/test_earlytime.rb +35 -0
  81. data/test/test_extension.rb +63 -0
  82. data/test/test_file_creation_task.rb +62 -0
  83. data/test/test_file_task.rb +143 -0
  84. data/test/test_filelist.rb +623 -0
  85. data/test/test_fileutils.rb +251 -0
  86. data/test/test_ftp.rb +59 -0
  87. data/test/test_invocation_chain.rb +81 -0
  88. data/test/test_makefile_loader.rb +26 -0
  89. data/test/test_multitask.rb +45 -0
  90. data/test/test_namespace.rb +55 -0
  91. data/test/test_package_task.rb +118 -0
  92. data/test/test_pathmap.rb +210 -0
  93. data/test/test_rake.rb +41 -0
  94. data/test/test_rdoc_task.rb +88 -0
  95. data/test/test_require.rb +35 -0
  96. data/test/test_rules.rb +349 -0
  97. data/test/test_task_arguments.rb +89 -0
  98. data/test/test_task_manager.rb +173 -0
  99. data/test/test_tasklib.rb +12 -0
  100. data/test/test_tasks.rb +374 -0
  101. data/test/test_test_task.rb +77 -0
  102. data/test/test_top_level_functions.rb +86 -0
  103. data/test/test_win32.rb +72 -0
  104. metadata +186 -0
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake/clean'
5
+
6
+ class TestClean < Test::Unit::TestCase
7
+ include Rake
8
+ def test_clean
9
+ assert Task['clean'], "Should define clean"
10
+ assert Task['clobber'], "Should define clobber"
11
+ assert Task['clobber'].prerequisites.include?("clean"),
12
+ "Clobber should require clean"
13
+ end
14
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'test/filecreation'
7
+ require 'test/rake_test_setup'
8
+
9
+ ######################################################################
10
+ class TestDefinitions < Test::Unit::TestCase
11
+ include Rake
12
+ include TestMethods
13
+
14
+ EXISTINGFILE = "testdata/existing"
15
+
16
+ def setup
17
+ Task.clear
18
+ end
19
+
20
+ def test_task
21
+ done = false
22
+ task :one => [:two] do done = true end
23
+ task :two
24
+ task :three => [:one, :two]
25
+ check_tasks(:one, :two, :three)
26
+ assert done, "Should be done"
27
+ end
28
+
29
+ def test_file_task
30
+ done = false
31
+ file "testdata/one" => "testdata/two" do done = true end
32
+ file "testdata/two"
33
+ file "testdata/three" => ["testdata/one", "testdata/two"]
34
+ check_tasks("testdata/one", "testdata/two", "testdata/three")
35
+ assert done, "Should be done"
36
+ end
37
+
38
+ def check_tasks(n1, n2, n3)
39
+ t = Task[n1]
40
+ assert Task === t, "Should be a Task"
41
+ assert_equal n1.to_s, t.name
42
+ assert_equal [n2.to_s], t.prerequisites.collect{|n| n.to_s}
43
+ t.invoke
44
+ t2 = Task[n2]
45
+ assert_equal FileList[], t2.prerequisites
46
+ t3 = Task[n3]
47
+ assert_equal [n1.to_s, n2.to_s], t3.prerequisites.collect{|n|n.to_s}
48
+ end
49
+
50
+ def test_incremental_definitions
51
+ runs = []
52
+ task :t1 => [:t2] do runs << "A"; 4321 end
53
+ task :t1 => [:t3] do runs << "B"; 1234 end
54
+ task :t1 => [:t3]
55
+ task :t2
56
+ task :t3
57
+ Task[:t1].invoke
58
+ assert_equal ["A", "B"], runs
59
+ assert_equal ["t2", "t3"], Task[:t1].prerequisites
60
+ end
61
+
62
+ def test_missing_dependencies
63
+ task :x => ["testdata/missing"]
64
+ assert_exception(RuntimeError) { Task[:x].invoke }
65
+ end
66
+
67
+ def test_implicit_file_dependencies
68
+ runs = []
69
+ create_existing_file
70
+ task :y => [EXISTINGFILE] do |t| runs << t.name end
71
+ Task[:y].invoke
72
+ assert_equal runs, ['y']
73
+ end
74
+
75
+ private # ----------------------------------------------------------
76
+
77
+ def create_existing_file
78
+ Dir.mkdir File.dirname(EXISTINGFILE) unless
79
+ File.exist?(File.dirname(EXISTINGFILE))
80
+ open(EXISTINGFILE, "w") do |f| f.puts "HI" end unless
81
+ File.exist?(EXISTINGFILE)
82
+ end
83
+
84
+ end
85
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ class TestEarlyTime < Test::Unit::TestCase
7
+ def test_create
8
+ early = Rake::EarlyTime.instance
9
+ time = Time.mktime(1970, 1, 1, 0, 0, 0)
10
+ assert early <= Time.now
11
+ assert early < Time.now
12
+ assert early != Time.now
13
+ assert Time.now > early
14
+ assert Time.now >= early
15
+ assert Time.now != early
16
+ end
17
+
18
+ def test_equality
19
+ early = Rake::EarlyTime.instance
20
+ assert_equal early, early, "two early times should be equal"
21
+ end
22
+
23
+ def test_original_time_compare_is_not_messed_up
24
+ t1 = Time.mktime(1970, 1, 1, 0, 0, 0)
25
+ t2 = Time.now
26
+ assert t1 < t2
27
+ assert t2 > t1
28
+ assert t1 == t1
29
+ assert t2 == t2
30
+ end
31
+
32
+ def test_to_s
33
+ assert_equal "<EARLY TIME>", Rake::EARLY.to_s
34
+ end
35
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+ require 'stringio'
6
+
7
+ ######################################################################
8
+ class TestExtension < Test::Unit::TestCase
9
+
10
+ module Redirect
11
+ def error_redirect
12
+ old_err = $stderr
13
+ result = StringIO.new
14
+ $stderr = result
15
+ yield
16
+ result
17
+ ensure
18
+ $stderr = old_err
19
+ end
20
+ end
21
+
22
+ class Sample
23
+ extend Redirect
24
+
25
+ def duplicate_method
26
+ :original
27
+ end
28
+
29
+ OK_ERRS = error_redirect do
30
+ rake_extension("a") do
31
+ def ok_method
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ DUP_ERRS = error_redirect do
38
+ rake_extension("duplicate_method") do
39
+ def duplicate_method
40
+ :override
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_methods_actually_exist
47
+ sample = Sample.new
48
+ sample.ok_method
49
+ sample.duplicate_method
50
+ end
51
+
52
+ def test_no_warning_when_defining_ok_method
53
+ assert_equal "", Sample::OK_ERRS.string
54
+ end
55
+
56
+ def test_extension_complains_when_a_method_that_is_present
57
+ assert_match(/warning:/i, Sample::DUP_ERRS.string)
58
+ assert_match(/already exists/i, Sample::DUP_ERRS.string)
59
+ assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
60
+ assert_equal :original, Sample.new.duplicate_method
61
+ end
62
+
63
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'test/filecreation'
7
+
8
+ ######################################################################
9
+ class TestFileCreationTask < Test::Unit::TestCase
10
+ include Rake
11
+ include FileCreation
12
+
13
+ DUMMY_DIR = 'testdata/dummy_dir'
14
+
15
+ def setup
16
+ Task.clear
17
+ end
18
+
19
+ def teardown
20
+ FileUtils.rm_rf DUMMY_DIR
21
+ end
22
+
23
+ def test_file_needed
24
+ create_dir DUMMY_DIR
25
+ fc_task = Task[DUMMY_DIR]
26
+ assert_equal DUMMY_DIR, fc_task.name
27
+ FileUtils.rm_rf fc_task.name
28
+ assert fc_task.needed?, "file should be needed"
29
+ FileUtils.mkdir fc_task.name
30
+ assert_equal nil, fc_task.prerequisites.collect{|n| Task[n].timestamp}.max
31
+ assert ! fc_task.needed?, "file should not be needed"
32
+ end
33
+
34
+ def test_directory
35
+ directory DUMMY_DIR
36
+ fc_task = Task[DUMMY_DIR]
37
+ assert_equal DUMMY_DIR, fc_task.name
38
+ assert FileCreationTask === fc_task
39
+ end
40
+
41
+ def test_no_retriggers_on_filecreate_task
42
+ create_timed_files(OLDFILE, NEWFILE)
43
+ t1 = Rake.application.intern(FileCreationTask, OLDFILE).enhance([NEWFILE])
44
+ t2 = Rake.application.intern(FileCreationTask, NEWFILE)
45
+ assert ! t2.needed?, "Should not need to build new file"
46
+ assert ! t1.needed?, "Should not need to rebuild old file because of new"
47
+ end
48
+
49
+ def test_no_retriggers_on_file_task
50
+ create_timed_files(OLDFILE, NEWFILE)
51
+ t1 = Rake.application.intern(FileCreationTask, OLDFILE).enhance([NEWFILE])
52
+ t2 = Rake.application.intern(FileCreationTask, NEWFILE)
53
+ assert ! t2.needed?, "Should not need to build new file"
54
+ assert ! t1.needed?, "Should not need to rebuild old file because of new"
55
+ end
56
+
57
+ def test_very_early_timestamp
58
+ t1 = Rake.application.intern(FileCreationTask, OLDFILE)
59
+ assert t1.timestamp < Time.now
60
+ assert t1.timestamp < Time.now - 1000000
61
+ end
62
+ end
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'test/filecreation'
7
+ require 'test/rake_test_setup'
8
+
9
+ ######################################################################
10
+ class TestFileTask < Test::Unit::TestCase
11
+ include Rake
12
+ include FileCreation
13
+ include TestMethods
14
+
15
+ def setup
16
+ Task.clear
17
+ @runs = Array.new
18
+ FileUtils.rm_f NEWFILE
19
+ FileUtils.rm_f OLDFILE
20
+ end
21
+
22
+ def test_file_need
23
+ name = "testdata/dummy"
24
+ file name
25
+ ftask = Task[name]
26
+ assert_equal name.to_s, ftask.name
27
+ File.delete(ftask.name) rescue nil
28
+ assert ftask.needed?, "file should be needed"
29
+ open(ftask.name, "w") { |f| f.puts "HI" }
30
+ assert_equal nil, ftask.prerequisites.collect{|n| Task[n].timestamp}.max
31
+ assert ! ftask.needed?, "file should not be needed"
32
+ File.delete(ftask.name) rescue nil
33
+ end
34
+
35
+ def test_file_times_new_depends_on_old
36
+ create_timed_files(OLDFILE, NEWFILE)
37
+
38
+ t1 = Rake.application.intern(FileTask, NEWFILE).enhance([OLDFILE])
39
+ t2 = Rake.application.intern(FileTask, OLDFILE)
40
+ assert ! t2.needed?, "Should not need to build old file"
41
+ assert ! t1.needed?, "Should not need to rebuild new file because of old"
42
+ end
43
+
44
+ def test_file_times_old_depends_on_new
45
+ create_timed_files(OLDFILE, NEWFILE)
46
+
47
+ t1 = Rake.application.intern(FileTask,OLDFILE).enhance([NEWFILE])
48
+ t2 = Rake.application.intern(FileTask, NEWFILE)
49
+ assert ! t2.needed?, "Should not need to build new file"
50
+ preq_stamp = t1.prerequisites.collect{|t| Task[t].timestamp}.max
51
+ assert_equal t2.timestamp, preq_stamp
52
+ assert t1.timestamp < preq_stamp, "T1 should be older"
53
+ assert t1.needed?, "Should need to rebuild old file because of new"
54
+ end
55
+
56
+ def test_file_depends_on_task_depend_on_file
57
+ create_timed_files(OLDFILE, NEWFILE)
58
+
59
+ file NEWFILE => [:obj] do |t| @runs << t.name end
60
+ task :obj => [OLDFILE] do |t| @runs << t.name end
61
+ file OLDFILE do |t| @runs << t.name end
62
+
63
+ Task[:obj].invoke
64
+ Task[NEWFILE].invoke
65
+ assert ! @runs.include?(NEWFILE)
66
+ end
67
+
68
+ def test_existing_file_depends_on_non_existing_file
69
+ create_file(OLDFILE)
70
+ delete_file(NEWFILE)
71
+ file NEWFILE
72
+ file OLDFILE => NEWFILE
73
+ assert_nothing_raised do Task[OLDFILE].invoke end
74
+ end
75
+
76
+ # I have currently disabled this test. I'm not convinced that
77
+ # deleting the file target on failure is always the proper thing to
78
+ # do. I'm willing to hear input on this topic.
79
+ def ztest_file_deletes_on_failure
80
+ task :obj
81
+ file NEWFILE => [:obj] do |t|
82
+ FileUtils.touch NEWFILE
83
+ fail "Ooops"
84
+ end
85
+ assert Task[NEWFILE]
86
+ begin
87
+ Task[NEWFILE].invoke
88
+ rescue Exception
89
+ end
90
+ assert( ! File.exist?(NEWFILE), "NEWFILE should be deleted")
91
+ end
92
+
93
+ end
94
+
95
+ ######################################################################
96
+ class TestDirectoryTask < Test::Unit::TestCase
97
+ include Rake
98
+
99
+ def setup
100
+ rm_rf "testdata", :verbose=>false
101
+ end
102
+
103
+ def teardown
104
+ rm_rf "testdata", :verbose=>false
105
+ end
106
+
107
+ def test_directory
108
+ desc "DESC"
109
+ directory "testdata/a/b/c"
110
+ assert_equal FileCreationTask, Task["testdata"].class
111
+ assert_equal FileCreationTask, Task["testdata/a"].class
112
+ assert_equal FileCreationTask, Task["testdata/a/b/c"].class
113
+ assert_nil Task["testdata"].comment
114
+ assert_equal "DESC", Task["testdata/a/b/c"].comment
115
+ assert_nil Task["testdata/a/b"].comment
116
+ verbose(false) {
117
+ Task['testdata/a/b'].invoke
118
+ }
119
+ assert File.exist?("testdata/a/b")
120
+ assert ! File.exist?("testdata/a/b/c")
121
+ end
122
+
123
+ if Rake::Win32.windows?
124
+ def test_directory_win32
125
+ desc "WIN32 DESC"
126
+ FileUtils.mkdir_p("testdata")
127
+ Dir.chdir("testdata") do
128
+ directory 'c:/testdata/a/b/c'
129
+ assert_equal FileCreationTask, Task['c:/testdata'].class
130
+ assert_equal FileCreationTask, Task['c:/testdata/a'].class
131
+ assert_equal FileCreationTask, Task['c:/testdata/a/b/c'].class
132
+ assert_nil Task['c:/testdata'].comment
133
+ assert_equal "WIN32 DESC", Task['c:/testdata/a/b/c'].comment
134
+ assert_nil Task['c:/testdata/a/b'].comment
135
+ verbose(false) {
136
+ Task['c:/testdata/a/b'].invoke
137
+ }
138
+ assert File.exist?('c:/testdata/a/b')
139
+ assert ! File.exist?('c:/testdata/a/b/c')
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,623 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ require 'test/capture_stdout'
7
+ require 'test/rake_test_setup'
8
+
9
+ class TestFileList < Test::Unit::TestCase
10
+ FileList = Rake::FileList
11
+ include CaptureStdout
12
+ include TestMethods
13
+
14
+ def setup
15
+ create_test_data
16
+ end
17
+
18
+ def teardown
19
+ # FileList.select_default_ignore_patterns
20
+ FileUtils.rm_rf("testdata")
21
+ end
22
+
23
+ def test_delgating_methods_do_not_include_to_a_or_to_ary
24
+ assert ! FileList::DELEGATING_METHODS.include?("to_a"), "should not include to_a"
25
+ assert ! FileList::DELEGATING_METHODS.include?(:to_a), "should not include to_a"
26
+ assert ! FileList::DELEGATING_METHODS.include?("to_ary"), "should not include to_ary"
27
+ assert ! FileList::DELEGATING_METHODS.include?(:to_ary), "should not include to_ary"
28
+ end
29
+
30
+ def test_create
31
+ fl = FileList.new
32
+ assert_equal 0, fl.size
33
+ end
34
+
35
+ def test_create_with_args
36
+ fl = FileList.new("testdata/*.c", "x")
37
+ assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
38
+ fl.sort
39
+ end
40
+
41
+ def test_create_with_block
42
+ fl = FileList.new { |f| f.include("x") }
43
+ assert_equal ["x"], fl.resolve
44
+ end
45
+
46
+ def test_create_with_brackets
47
+ fl = FileList["testdata/*.c", "x"]
48
+ assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
49
+ fl.sort
50
+ end
51
+
52
+ def test_create_with_brackets_and_filelist
53
+ fl = FileList[FileList["testdata/*.c", "x"]]
54
+ assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
55
+ fl.sort
56
+ end
57
+
58
+ def test_include_with_another_array
59
+ fl = FileList.new.include(["x", "y", "z"])
60
+ assert_equal ["x", "y", "z"].sort, fl.sort
61
+ end
62
+
63
+ def test_include_with_another_filelist
64
+ fl = FileList.new.include(FileList["testdata/*.c", "x"])
65
+ assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
66
+ fl.sort
67
+ end
68
+
69
+ def test_append
70
+ fl = FileList.new
71
+ fl << "a.rb" << "b.rb"
72
+ assert_equal ['a.rb', 'b.rb'], fl
73
+ end
74
+
75
+ def test_add_many
76
+ fl = FileList.new
77
+ fl.include %w(a d c)
78
+ fl.include('x', 'y')
79
+ assert_equal ['a', 'd', 'c', 'x', 'y'], fl
80
+ assert_equal ['a', 'd', 'c', 'x', 'y'], fl.resolve
81
+ end
82
+
83
+ def test_add_return
84
+ f = FileList.new
85
+ g = f << "x"
86
+ assert_equal f.object_id, g.object_id
87
+ h = f.include("y")
88
+ assert_equal f.object_id, h.object_id
89
+ end
90
+
91
+ def test_match
92
+ fl = FileList.new
93
+ fl.include('test/test*.rb')
94
+ assert fl.include?("test/test_filelist.rb")
95
+ assert fl.size > 3
96
+ fl.each { |fn| assert_match(/\.rb$/, fn) }
97
+ end
98
+
99
+ def test_add_matching
100
+ fl = FileList.new
101
+ fl << "a.java"
102
+ fl.include("test/*.rb")
103
+ assert_equal "a.java", fl[0]
104
+ assert fl.size > 2
105
+ assert fl.include?("test/test_filelist.rb")
106
+ end
107
+
108
+ def test_multiple_patterns
109
+ create_test_data
110
+ fl = FileList.new
111
+ fl.include('*.c', '*xist*')
112
+ assert_equal [], fl
113
+ fl.include('testdata/*.c', 'testdata/*xist*')
114
+ assert_equal [
115
+ 'testdata/x.c', 'testdata/xyz.c', 'testdata/abc.c', 'testdata/existing'
116
+ ].sort, fl.sort
117
+ end
118
+
119
+ def test_square_bracket_pattern
120
+ fl = FileList.new
121
+ fl.include("testdata/abc.[ch]")
122
+ assert fl.size == 2
123
+ assert fl.include?("testdata/abc.c")
124
+ assert fl.include?("testdata/abc.h")
125
+ end
126
+
127
+ def test_curly_bracket_pattern
128
+ fl = FileList.new
129
+ fl.include("testdata/abc.{c,h}")
130
+ assert fl.size == 2
131
+ assert fl.include?("testdata/abc.c")
132
+ assert fl.include?("testdata/abc.h")
133
+ end
134
+
135
+ def test_reject
136
+ fl = FileList.new
137
+ fl.include %w(testdata/x.c testdata/abc.c testdata/xyz.c testdata/existing)
138
+ fl.reject! { |fn| fn =~ %r{/x} }
139
+ assert_equal [
140
+ 'testdata/abc.c', 'testdata/existing'
141
+ ], fl
142
+ end
143
+
144
+ def test_exclude
145
+ fl = FileList['testdata/x.c', 'testdata/abc.c', 'testdata/xyz.c', 'testdata/existing']
146
+ fl.each { |fn| touch fn, :verbose => false }
147
+ x = fl.exclude(%r{/x.+\.})
148
+ assert_equal FileList, x.class
149
+ assert_equal %w(testdata/x.c testdata/abc.c testdata/existing), fl
150
+ assert_equal fl.object_id, x.object_id
151
+ fl.exclude('testdata/*.c')
152
+ assert_equal ['testdata/existing'], fl
153
+ fl.exclude('testdata/existing')
154
+ assert_equal [], fl
155
+ end
156
+
157
+ def test_excluding_via_block
158
+ fl = FileList['testdata/a.c', 'testdata/b.c', 'testdata/xyz.c']
159
+ fl.exclude { |fn| fn.pathmap('%n') == 'xyz' }
160
+ assert fl.exclude?("xyz.c"), "Should exclude xyz.c"
161
+ assert_equal ['testdata/a.c', 'testdata/b.c'], fl
162
+ end
163
+
164
+ def test_exclude_return_on_create
165
+ fl = FileList['testdata/*'].exclude(/.*\.[hcx]$/)
166
+ assert_equal ['testdata/existing', 'testdata/cfiles'].sort, fl.sort
167
+ assert_equal FileList, fl.class
168
+ end
169
+
170
+ def test_exclude_with_string_return_on_create
171
+ fl = FileList['testdata/*'].exclude('testdata/abc.c')
172
+ assert_equal %w(testdata/existing testdata/cfiles testdata/x.c testdata/abc.h testdata/abc.x testdata/xyz.c).sort, fl.sort
173
+ assert_equal FileList, fl.class
174
+ end
175
+
176
+ def test_default_exclude
177
+ fl = FileList.new
178
+ fl.clear_exclude
179
+ fl.include("**/*~", "**/*.bak", "**/core")
180
+ assert fl.member?("testdata/core"), "Should include core"
181
+ assert fl.member?("testdata/x.bak"), "Should include .bak files"
182
+ end
183
+
184
+ def test_unique
185
+ fl = FileList.new
186
+ fl << "x.c" << "a.c" << "b.rb" << "a.c"
187
+ assert_equal ['x.c', 'a.c', 'b.rb', 'a.c'], fl
188
+ fl.uniq!
189
+ assert_equal ['x.c', 'a.c', 'b.rb'], fl
190
+ end
191
+
192
+ def test_to_string
193
+ fl = FileList.new
194
+ fl << "a.java" << "b.java"
195
+ assert_equal "a.java b.java", fl.to_s
196
+ assert_equal "a.java b.java", "#{fl}"
197
+ end
198
+
199
+ def test_to_array
200
+ fl = FileList['a.java', 'b.java']
201
+ assert_equal ['a.java', 'b.java'], fl.to_a
202
+ assert_equal Array, fl.to_a.class
203
+ assert_equal ['a.java', 'b.java'], fl.to_ary
204
+ assert_equal Array, fl.to_ary.class
205
+ end
206
+
207
+ def test_to_s_pending
208
+ fl = FileList['testdata/abc.*']
209
+ result = fl.to_s
210
+ assert_match(%r{testdata/abc\.c}, result)
211
+ assert_match(%r{testdata/abc\.h}, result)
212
+ assert_match(%r{testdata/abc\.x}, result)
213
+ assert_match(%r{(testdata/abc\..\b ?){2}}, result)
214
+ end
215
+
216
+ def test_inspect_pending
217
+ fl = FileList['testdata/abc.*']
218
+ result = fl.inspect
219
+ assert_match(%r{"testdata/abc\.c"}, result)
220
+ assert_match(%r{"testdata/abc\.h"}, result)
221
+ assert_match(%r{"testdata/abc\.x"}, result)
222
+ assert_match(%r|^\[("testdata/abc\..", ){2}"testdata/abc\.."\]$|, result)
223
+ end
224
+
225
+ def test_sub
226
+ fl = FileList["testdata/*.c"]
227
+ f2 = fl.sub(/\.c$/, ".o")
228
+ assert_equal FileList, f2.class
229
+ assert_equal ["testdata/abc.o", "testdata/x.o", "testdata/xyz.o"].sort,
230
+ f2.sort
231
+ f3 = fl.gsub(/\.c$/, ".o")
232
+ assert_equal FileList, f3.class
233
+ assert_equal ["testdata/abc.o", "testdata/x.o", "testdata/xyz.o"].sort,
234
+ f3.sort
235
+ end
236
+
237
+ def test_claim_to_be_a_kind_of_array
238
+ fl = FileList['testdata/*.c']
239
+ assert fl.is_a?(Array)
240
+ assert fl.kind_of?(Array)
241
+ end
242
+
243
+ def test_claim_to_be_a_kind_of_filelist
244
+ fl = FileList['testdata/*.c']
245
+ assert fl.is_a?(FileList)
246
+ assert fl.kind_of?(FileList)
247
+ end
248
+
249
+ def test_claim_to_be_a_filelist_instance
250
+ fl = FileList['testdata/*.c']
251
+ assert fl.instance_of?(FileList)
252
+ end
253
+
254
+ def test_dont_claim_to_be_an_array_instance
255
+ fl = FileList['testdata/*.c']
256
+ assert ! fl.instance_of?(Array)
257
+ end
258
+
259
+ def test_sub!
260
+ f = "x/a.c"
261
+ fl = FileList[f, "x/b.c"]
262
+ res = fl.sub!(/\.c$/, ".o")
263
+ assert_equal ["x/a.o", "x/b.o"].sort, fl.sort
264
+ assert_equal "x/a.c", f
265
+ assert_equal fl.object_id, res.object_id
266
+ end
267
+
268
+ def test_sub_with_block
269
+ fl = FileList["src/org/onestepback/a.java", "src/org/onestepback/b.java"]
270
+ # The block version doesn't work the way I want it to ...
271
+ # f2 = fl.sub(%r{^src/(.*)\.java$}) { |x| "classes/" + $1 + ".class" }
272
+ f2 = fl.sub(%r{^src/(.*)\.java$}, "classes/\\1.class")
273
+ assert_equal [
274
+ "classes/org/onestepback/a.class",
275
+ "classes/org/onestepback/b.class"
276
+ ].sort,
277
+ f2.sort
278
+ end
279
+
280
+ def test_string_ext
281
+ assert_equal "one.net", "one.two".ext("net")
282
+ assert_equal "one.net", "one.two".ext(".net")
283
+ assert_equal "one.net", "one".ext("net")
284
+ assert_equal "one.net", "one".ext(".net")
285
+ assert_equal "one.two.net", "one.two.c".ext(".net")
286
+ assert_equal "one/two.net", "one/two.c".ext(".net")
287
+ assert_equal "one.x/two.net", "one.x/two.c".ext(".net")
288
+ assert_equal "one.x/two.net", "one.x/two".ext(".net")
289
+ assert_equal ".onerc.net", ".onerc.dot".ext("net")
290
+ assert_equal ".onerc.net", ".onerc".ext("net")
291
+ assert_equal ".a/.onerc.net", ".a/.onerc".ext("net")
292
+ assert_equal "one", "one.two".ext('')
293
+ assert_equal "one", "one.two".ext
294
+ assert_equal ".one", ".one.two".ext
295
+ assert_equal ".one", ".one".ext
296
+ assert_equal ".", ".".ext("c")
297
+ assert_equal "..", "..".ext("c")
298
+ # These only need to work in windows
299
+ if Rake::Win32.windows?
300
+ assert_equal "one.x\\two.net", "one.x\\two.c".ext(".net")
301
+ assert_equal "one.x\\two.net", "one.x\\two".ext(".net")
302
+ end
303
+ end
304
+
305
+ def test_filelist_ext
306
+ assert_equal FileList['one.c', '.one.c'],
307
+ FileList['one.net', '.one'].ext('c')
308
+ end
309
+
310
+ def test_gsub
311
+ create_test_data
312
+ fl = FileList["testdata/*.c"]
313
+ f2 = fl.gsub(/a/, "A")
314
+ assert_equal ["testdAtA/Abc.c", "testdAtA/x.c", "testdAtA/xyz.c"].sort,
315
+ f2.sort
316
+ end
317
+
318
+ def test_gsub!
319
+ create_test_data
320
+ f = FileList["testdata/*.c"]
321
+ f.gsub!(/a/, "A")
322
+ assert_equal ["testdAtA/Abc.c", "testdAtA/x.c", "testdAtA/xyz.c"].sort,
323
+ f.sort
324
+ end
325
+
326
+ def test_egrep_with_output
327
+ files = FileList['test/test*.rb']
328
+ the_line_number = __LINE__ + 1
329
+ out = capture_stdout do files.egrep(/PUGH/) end
330
+ assert_match(/:#{the_line_number}:/, out)
331
+ end
332
+
333
+ def test_egrep_with_block
334
+ files = FileList['test/test*.rb']
335
+ found = false
336
+ the_line_number = __LINE__ + 1
337
+ files.egrep(/XYZZY/) do |fn, ln, line |
338
+ assert_equal 'test/test_filelist.rb', fn
339
+ assert_equal the_line_number, ln
340
+ assert_match(/files\.egrep/, line)
341
+ found = true
342
+ end
343
+ assert found, "should have found a matching line"
344
+ end
345
+
346
+ def test_existing
347
+ fl = FileList['testdata/abc.c', 'testdata/notthere.c']
348
+ assert_equal ["testdata/abc.c"], fl.existing
349
+ assert fl.existing.is_a?(FileList)
350
+ end
351
+
352
+ def test_existing!
353
+ fl = FileList['testdata/abc.c', 'testdata/notthere.c']
354
+ result = fl.existing!
355
+ assert_equal ["testdata/abc.c"], fl
356
+ assert_equal fl.object_id, result.object_id
357
+ end
358
+
359
+ def test_ignore_special
360
+ f = FileList['testdata/*']
361
+ assert ! f.include?("testdata/CVS"), "Should not contain CVS"
362
+ assert ! f.include?("testdata/.svn"), "Should not contain .svn"
363
+ assert ! f.include?("testdata/.dummy"), "Should not contain dot files"
364
+ assert ! f.include?("testdata/x.bak"), "Should not contain .bak files"
365
+ assert ! f.include?("testdata/x~"), "Should not contain ~ files"
366
+ assert ! f.include?("testdata/core"), "Should not contain core files"
367
+ end
368
+
369
+ def test_clear_ignore_patterns
370
+ f = FileList['testdata/*', 'testdata/.svn']
371
+ f.clear_exclude
372
+ assert f.include?("testdata/abc.c")
373
+ assert f.include?("testdata/xyz.c")
374
+ assert f.include?("testdata/CVS")
375
+ assert f.include?("testdata/.svn")
376
+ assert f.include?("testdata/x.bak")
377
+ assert f.include?("testdata/x~")
378
+ end
379
+
380
+ def test_exclude_with_alternate_file_seps
381
+ fl = FileList.new
382
+ assert fl.exclude?("x/CVS/y")
383
+ assert fl.exclude?("x\\CVS\\y")
384
+ assert fl.exclude?("x/.svn/y")
385
+ assert fl.exclude?("x\\.svn\\y")
386
+ assert fl.exclude?("x/core")
387
+ assert fl.exclude?("x\\core")
388
+ end
389
+
390
+ def test_add_default_exclude_list
391
+ fl = FileList.new
392
+ fl.exclude(/~\d+$/)
393
+ assert fl.exclude?("x/CVS/y")
394
+ assert fl.exclude?("x\\CVS\\y")
395
+ assert fl.exclude?("x/.svn/y")
396
+ assert fl.exclude?("x\\.svn\\y")
397
+ assert fl.exclude?("x/core")
398
+ assert fl.exclude?("x\\core")
399
+ assert fl.exclude?("x/abc~1")
400
+ end
401
+
402
+ def test_basic_array_functions
403
+ f = FileList['b', 'c', 'a']
404
+ assert_equal 'b', f.first
405
+ assert_equal 'b', f[0]
406
+ assert_equal 'a', f.last
407
+ assert_equal 'a', f[2]
408
+ assert_equal 'a', f[-1]
409
+ assert_equal ['a', 'b', 'c'], f.sort
410
+ f.sort!
411
+ assert_equal ['a', 'b', 'c'], f
412
+ end
413
+
414
+ def test_flatten
415
+ assert_equal ['a', 'testdata/x.c', 'testdata/xyz.c', 'testdata/abc.c'].sort,
416
+ ['a', FileList['testdata/*.c']].flatten.sort
417
+ end
418
+
419
+ def test_clone_and_dup
420
+ a = FileList['a', 'b', 'c']
421
+ c = a.clone
422
+ d = a.dup
423
+ a << 'd'
424
+ assert_equal ['a', 'b', 'c', 'd'], a
425
+ assert_equal ['a', 'b', 'c'], c
426
+ assert_equal ['a', 'b', 'c'], d
427
+ end
428
+
429
+ def test_dup_and_clone_replicate_taint
430
+ a = FileList['a', 'b', 'c']
431
+ a.taint
432
+ c = a.clone
433
+ d = a.dup
434
+ assert c.tainted?, "Clone should be tainted"
435
+ assert d.tainted?, "Dup should be tainted"
436
+ end
437
+
438
+ def test_duped_items_will_thaw
439
+ a = FileList['a', 'b', 'c']
440
+ a.freeze
441
+ d = a.dup
442
+ d << 'more'
443
+ assert_equal ['a', 'b', 'c', 'more'], d
444
+ end
445
+
446
+ def test_cloned_items_stay_frozen
447
+ a = FileList['a', 'b', 'c']
448
+ a.freeze
449
+ c = a.clone
450
+ assert_exception(TypeError, RuntimeError) do
451
+ c << 'more'
452
+ end
453
+ end
454
+
455
+ def test_array_comparisons
456
+ fl = FileList['b', 'b']
457
+ a = ['b', 'a']
458
+ b = ['b', 'b']
459
+ c = ['b', 'c']
460
+ assert_equal( 1, fl <=> a )
461
+ assert_equal( 0, fl <=> b )
462
+ assert_equal( -1, fl <=> c )
463
+ assert_equal( -1, a <=> fl )
464
+ assert_equal( 0, b <=> fl )
465
+ assert_equal( 1, c <=> fl )
466
+ end
467
+
468
+ def test_array_equality
469
+ a = FileList['a', 'b']
470
+ b = ['a', 'b']
471
+ assert a == b
472
+ assert b == a
473
+ # assert a.eql?(b)
474
+ # assert b.eql?(a)
475
+ assert ! a.equal?(b)
476
+ assert ! b.equal?(a)
477
+ end
478
+
479
+ def test_enumeration_methods
480
+ a = FileList['a', 'b']
481
+ b = a.collect { |it| it.upcase }
482
+ assert_equal ['A', 'B'], b
483
+ assert_equal FileList, b.class
484
+
485
+ b = a.map { |it| it.upcase }
486
+ assert_equal ['A', 'B'], b
487
+ assert_equal FileList, b.class
488
+
489
+ b = a.sort
490
+ assert_equal ['a', 'b'], b
491
+ assert_equal FileList, b.class
492
+
493
+ b = a.sort_by { |it| it }
494
+ assert_equal ['a', 'b'], b
495
+ assert_equal FileList, b.class
496
+
497
+ b = a.find_all { |it| it == 'b'}
498
+ assert_equal ['b'], b
499
+ assert_equal FileList, b.class
500
+
501
+ b = a.select { |it| it.size == 1 }
502
+ assert_equal ['a', 'b'], b
503
+ assert_equal FileList, b.class
504
+
505
+ b = a.reject { |it| it == 'b' }
506
+ assert_equal ['a'], b
507
+ assert_equal FileList, b.class
508
+
509
+ b = a.grep(/./)
510
+ assert_equal ['a', 'b'], b
511
+ assert_equal FileList, b.class
512
+
513
+ b = a.partition { |it| it == 'b' }
514
+ assert_equal [['b'], ['a']], b
515
+ assert_equal Array, b.class
516
+ assert_equal FileList, b[0].class
517
+ assert_equal FileList, b[1].class
518
+
519
+ b = a.zip(['x', 'y']).to_a
520
+ assert_equal [['a', 'x'], ['b', 'y']], b
521
+ assert_equal Array, b.class
522
+ assert_equal Array, b[0].class
523
+ assert_equal Array, b[1].class
524
+ end
525
+
526
+ def test_array_operators
527
+ a = ['a', 'b']
528
+ b = ['c', 'd']
529
+ f = FileList['x', 'y']
530
+ g = FileList['w', 'z']
531
+
532
+ r = f + g
533
+ assert_equal ['x', 'y', 'w', 'z'], r
534
+ assert_equal FileList, r.class
535
+
536
+ r = a + g
537
+ assert_equal ['a', 'b', 'w', 'z'], r
538
+ assert_equal Array, r.class
539
+
540
+ r = f + b
541
+ assert_equal ['x', 'y', 'c', 'd'], r
542
+ assert_equal FileList, r.class
543
+
544
+ r = FileList['w', 'x', 'y', 'z'] - f
545
+ assert_equal ['w', 'z'], r
546
+ assert_equal FileList, r.class
547
+
548
+ r = FileList['w', 'x', 'y', 'z'] & f
549
+ assert_equal ['x', 'y'], r
550
+ assert_equal FileList, r.class
551
+
552
+ r = f * 2
553
+ assert_equal ['x', 'y', 'x', 'y'], r
554
+ assert_equal FileList, r.class
555
+
556
+ r = f * ','
557
+ assert_equal 'x,y', r
558
+ assert_equal String, r.class
559
+
560
+ r = f | ['a', 'x']
561
+ assert_equal ['a', 'x', 'y'].sort, r.sort
562
+ assert_equal FileList, r.class
563
+ end
564
+
565
+ def test_other_array_returning_methods
566
+ f = FileList['a', nil, 'b']
567
+ r = f.compact
568
+ assert_equal ['a', 'b'], r
569
+ assert_equal FileList, r.class
570
+
571
+ f = FileList['a', 'b']
572
+ r = f.concat(['x', 'y'])
573
+ assert_equal ['a', 'b', 'x', 'y'], r
574
+ assert_equal FileList, r.class
575
+
576
+ f = FileList['a', ['b', 'c'], FileList['d', 'e']]
577
+ r = f.flatten
578
+ assert_equal ['a', 'b', 'c', 'd', 'e'], r
579
+ assert_equal FileList, r.class
580
+
581
+ f = FileList['a', 'b', 'a']
582
+ r = f.uniq
583
+ assert_equal ['a', 'b'], r
584
+ assert_equal FileList, r.class
585
+
586
+ f = FileList['a', 'b', 'c', 'd']
587
+ r = f.values_at(1,3)
588
+ assert_equal ['b', 'd'], r
589
+ assert_equal FileList, r.class
590
+ end
591
+
592
+ def test_file_utils_can_use_filelists
593
+ cfiles = FileList['testdata/*.c']
594
+
595
+ cp cfiles, @cdir, :verbose => false
596
+
597
+ assert File.exist?(File.join(@cdir, 'abc.c'))
598
+ assert File.exist?(File.join(@cdir, 'xyz.c'))
599
+ assert File.exist?(File.join(@cdir, 'x.c'))
600
+ end
601
+
602
+ def create_test_data
603
+ verbose(false) do
604
+
605
+ mkdir "testdata" unless File.exist? "testdata"
606
+ mkdir "testdata/CVS" rescue nil
607
+ mkdir "testdata/.svn" rescue nil
608
+ @cdir = "testdata/cfiles"
609
+ mkdir @cdir rescue nil
610
+ touch "testdata/.dummy"
611
+ touch "testdata/x.bak"
612
+ touch "testdata/x~"
613
+ touch "testdata/core"
614
+ touch "testdata/x.c"
615
+ touch "testdata/xyz.c"
616
+ touch "testdata/abc.c"
617
+ touch "testdata/abc.h"
618
+ touch "testdata/abc.x"
619
+ touch "testdata/existing"
620
+ end
621
+ end
622
+
623
+ end