fixbraces 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/fixbraces +13 -2
- data/features/fixbraces.feature +2 -2
- data/features/fixbraces_dry.feature +43 -0
- data/features/step_definitions/fixbraces_steps.rb +15 -0
- data/lib/fixbraces/version.rb +1 -1
- data/lib/fixbraces.rb +12 -0
- data/spec/fixbraces_spec.rb +50 -14
- metadata +4 -2
data/bin/fixbraces
CHANGED
@@ -16,6 +16,7 @@ Usage:
|
|
16
16
|
where [options] are:
|
17
17
|
BANN
|
18
18
|
|
19
|
+
opt :dry_run, "Do not change any files, but list the names of those that would be changed."
|
19
20
|
end
|
20
21
|
|
21
22
|
source_files = []
|
@@ -23,6 +24,7 @@ source_files = []
|
|
23
24
|
# Bail if no path of file is given
|
24
25
|
Trollop::die "fixbraces needs to know what directory or files to attempt to correct" if ARGV.length < 1
|
25
26
|
|
27
|
+
# Sort out the files that need to be processed
|
26
28
|
ARGV.each do |path|
|
27
29
|
f = File.expand_path path
|
28
30
|
|
@@ -43,11 +45,20 @@ ARGV.each do |path|
|
|
43
45
|
end
|
44
46
|
|
45
47
|
source_files.flatten.each do |f|
|
46
|
-
changed_file =
|
48
|
+
changed_file = ""
|
49
|
+
output_prefix = ""
|
50
|
+
|
51
|
+
if opts[:dry_run]
|
52
|
+
changed_file = Fixbraces.dry_process_file f
|
53
|
+
output_prefix = "Will Correct:"
|
54
|
+
else
|
55
|
+
changed_file = Fixbraces.process_file f
|
56
|
+
output_prefix = "Corrected:"
|
57
|
+
end
|
47
58
|
|
48
59
|
if changed_file
|
49
60
|
path_name = Pathname.new changed_file
|
50
61
|
relative_path_name = path_name.relative_path_from Pathname.pwd
|
51
|
-
puts "
|
62
|
+
puts "#{output_prefix} #{relative_path_name}"
|
52
63
|
end
|
53
64
|
end
|
data/features/fixbraces.feature
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Feature: The
|
2
|
-
In order to
|
1
|
+
Feature: The script correctly makes changes to files
|
2
|
+
In order to correct the formatting of the Objective-C source files
|
3
3
|
The developer will need to make sure that these tests pass
|
4
4
|
|
5
5
|
Scenario: Run the app on a single file
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Feature: The script correctly implements a dry run feature
|
2
|
+
In order to see what files _will_ be changed by running the script
|
3
|
+
the developer will need to make these tests pass
|
4
|
+
|
5
|
+
Scenario: Run the app on a single file
|
6
|
+
Given a single source file called MasterViewController.m
|
7
|
+
When I run `fixbraces -d MasterViewController.m`
|
8
|
+
Then MasterViewController.m should not be formatted correctly
|
9
|
+
Then the output should contain "MasterViewController.m"
|
10
|
+
And the exit status should be 0
|
11
|
+
|
12
|
+
Scenario: Run the app on a directory
|
13
|
+
Given an Xcode project
|
14
|
+
When I run `"fixbraces -d ."`
|
15
|
+
Then the files in the directory should be unchanged
|
16
|
+
And the exit status should be 0
|
17
|
+
|
18
|
+
Scenario: Run the app on a number of files in the directory
|
19
|
+
Given an Xcode project
|
20
|
+
When I run `"fixbraces -d FixbracesTestProject/*.m"`
|
21
|
+
And the suggested changed files should be listed
|
22
|
+
And the files in the directory should be unchanged
|
23
|
+
And the exit status should be 0
|
24
|
+
|
25
|
+
Scenario: Show an error message if no file or directory is provided
|
26
|
+
Given an Xcode project
|
27
|
+
When I run `fixbraces -d`
|
28
|
+
Then the output should contain "Error: fixbraces needs to know what directory or files to attempt to correct."
|
29
|
+
And the exit status should not be 0
|
30
|
+
|
31
|
+
Scenario: Show an error message for a non-existent file or directory
|
32
|
+
Given an Xcode project
|
33
|
+
When I run `fixbraces -d non_existent_path`
|
34
|
+
Then the output should contain "Invalid path"
|
35
|
+
And the exit status should be 0
|
36
|
+
|
37
|
+
Scenario: If one of the files is non-existent correct the file that can be changed and show an error message for the non-existent one
|
38
|
+
Given a single source file called MasterViewController.m
|
39
|
+
When I run `fixbraces -d MasterViewController.m some_file.m`
|
40
|
+
Then MasterViewController.m should not be formatted correctly
|
41
|
+
And the output should contain "MasterViewController.m"
|
42
|
+
And the output should contain "Invalid path"
|
43
|
+
And the exit status should be 0
|
@@ -10,6 +10,12 @@ Then /^MasterViewController\.m should be formatted correctly$/ do
|
|
10
10
|
expect(FileUtils.compare_file @result_file, @expected_file).to eq true
|
11
11
|
end
|
12
12
|
|
13
|
+
Then /^MasterViewController\.m should not be formatted correctly$/ do
|
14
|
+
@expected_file = @fixtures_input_dir + "FixbracesTestProject/MasterViewController.m"
|
15
|
+
@result_file = @working_dir + "MasterViewController.m"
|
16
|
+
expect(FileUtils.compare_file @result_file, @expected_file).to eq true
|
17
|
+
end
|
18
|
+
|
13
19
|
Given /^an Xcode project$/ do
|
14
20
|
FileUtils.mkdir_p @working_dir
|
15
21
|
FileUtils.cp_r @fixtures_input_dir + "FixbracesTestProject", @working_dir
|
@@ -22,6 +28,11 @@ Then /^the files in the directory should be formatted correctly$/ do
|
|
22
28
|
expect(result).to eq ""
|
23
29
|
end
|
24
30
|
|
31
|
+
Then /^the files in the directory should be unchanged$/ do
|
32
|
+
result = `diff -r --brief --exclude=.DS_Store #{@working_dir} #{@fixtures_input_dir}`
|
33
|
+
expect(result).to eq ""
|
34
|
+
end
|
35
|
+
|
25
36
|
Then /^the \.m files in that directory are changed$/ do
|
26
37
|
# Under testing we have complete control over the files. so use a hard coded list.
|
27
38
|
base_dir = File.join @working_dir, "FixbracesTestProject"
|
@@ -45,6 +56,10 @@ Then /^the changed files should be listed$/ do
|
|
45
56
|
step %(the output should contain "main.m")
|
46
57
|
end
|
47
58
|
|
59
|
+
When /^the suggested changed files should be listed$/ do
|
60
|
+
step %(the changed files should be listed)
|
61
|
+
end
|
62
|
+
|
48
63
|
Then /^there should not be any .h files listed$/ do
|
49
64
|
step %(the output should not contain "AppDelegate.h")
|
50
65
|
end
|
data/lib/fixbraces/version.rb
CHANGED
data/lib/fixbraces.rb
CHANGED
@@ -40,4 +40,16 @@ module Fixbraces
|
|
40
40
|
# Return the file path or nil if no changes were made
|
41
41
|
corrected_text ? file : nil
|
42
42
|
end
|
43
|
+
|
44
|
+
def Fixbraces.dry_process_file(file)
|
45
|
+
corrected_text = ""
|
46
|
+
|
47
|
+
# Read in the text and pass it to the method that corrects it.
|
48
|
+
File.open(file, "r") do |f|
|
49
|
+
contents = f.read
|
50
|
+
corrected_text = fixbraces contents
|
51
|
+
end
|
52
|
+
|
53
|
+
corrected_text ? file : nil
|
54
|
+
end
|
43
55
|
end
|
data/spec/fixbraces_spec.rb
CHANGED
@@ -32,7 +32,8 @@ describe Fixbraces do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
context "Working with files" do
|
36
|
+
|
36
37
|
before(:each) do
|
37
38
|
tests_dir = Dir.pwd + "/tmp/spec/"
|
38
39
|
|
@@ -53,26 +54,61 @@ describe Fixbraces do
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
files
|
59
|
-
|
57
|
+
describe "#process_file" do
|
58
|
+
|
59
|
+
it "manages to update multiple files" do
|
60
|
+
files = Dir.glob Dir.pwd + "/tmp/spec/*.{h,m}"
|
61
|
+
files.each do |f|
|
62
|
+
Fixbraces.process_file f
|
63
|
+
end
|
64
|
+
|
65
|
+
result = `diff -r --brief #{Dir.pwd + "/tmp/spec/"} #{Dir.pwd + "/spec/fixtures/expected/"}`
|
66
|
+
expect(result).to eq ""
|
60
67
|
end
|
61
68
|
|
62
|
-
|
63
|
-
|
69
|
+
it 'should preserve the original file mode' do
|
70
|
+
files = Dir.glob Dir.pwd + "/tmp/spec/*.{h,m}"
|
71
|
+
files.each do |f|
|
72
|
+
original_mode = File.new(f).stat.mode
|
73
|
+
Fixbraces.process_file f
|
74
|
+
new_mode = File.new(f).stat.mode
|
75
|
+
|
76
|
+
expect(new_mode).to eq original_mode
|
77
|
+
end
|
78
|
+
end
|
64
79
|
end
|
65
80
|
|
66
|
-
|
67
|
-
files
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
81
|
+
describe "#dry_process_file" do
|
82
|
+
it "returns the names of the files if changes could be applied" do
|
83
|
+
files = Dir.glob Dir.pwd + "/tmp/spec/*.{h,m}"
|
84
|
+
|
85
|
+
processed_files = Set.new
|
86
|
+
files.each do |f|
|
87
|
+
processed_file = Fixbraces.dry_process_file f
|
88
|
+
unless processed_file
|
89
|
+
next
|
90
|
+
end
|
91
|
+
processed_files.add (File.basename processed_file)
|
92
|
+
end
|
93
|
+
|
94
|
+
expected_processed_files = ["MasterViewController.h", "AppDelegate.m", "MasterViewController.m"].to_set
|
72
95
|
|
73
|
-
expect(
|
96
|
+
expect(processed_files).to eq expected_processed_files
|
74
97
|
end
|
98
|
+
|
99
|
+
it 'should not change the contents of the files' do
|
100
|
+
files = Dir.glob Dir.pwd + "/tmp/spec/*.{h,m}"
|
101
|
+
files.each do |f|
|
102
|
+
Fixbraces.dry_process_file f
|
103
|
+
end
|
104
|
+
|
105
|
+
result = `diff -r --brief #{Dir.pwd + "/tmp/spec/"} #{Dir.pwd + "/spec/fixtures/input/"}`
|
106
|
+
expect(result).to eq ""
|
107
|
+
end
|
108
|
+
|
75
109
|
end
|
110
|
+
|
76
111
|
end
|
77
112
|
|
113
|
+
|
78
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixbraces
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: trollop
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- bin/fixbraces
|
100
100
|
- features/cli.feature
|
101
101
|
- features/fixbraces.feature
|
102
|
+
- features/fixbraces_dry.feature
|
102
103
|
- features/fixtures/FixbracesTestProject/FixbracesTestProject.xcodeproj/project.pbxproj
|
103
104
|
- features/fixtures/FixbracesTestProject/FixbracesTestProject/AppDelegate.h
|
104
105
|
- features/fixtures/FixbracesTestProject/FixbracesTestProject/AppDelegate.m
|
@@ -181,6 +182,7 @@ summary: Puts the opening brace on the same line
|
|
181
182
|
test_files:
|
182
183
|
- features/cli.feature
|
183
184
|
- features/fixbraces.feature
|
185
|
+
- features/fixbraces_dry.feature
|
184
186
|
- features/fixtures/FixbracesTestProject/FixbracesTestProject.xcodeproj/project.pbxproj
|
185
187
|
- features/fixtures/FixbracesTestProject/FixbracesTestProject/AppDelegate.h
|
186
188
|
- features/fixtures/FixbracesTestProject/FixbracesTestProject/AppDelegate.m
|