Skip to content

Commit

Permalink
added code and spec to shorten filenames that will cause Errno::ENAME…
Browse files Browse the repository at this point in the history
…TOOLONG
  • Loading branch information
Jade Meskill authored and Integrum Pairing Station committed Jul 19, 2011
1 parent 13a339f commit ee3d0ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ci/reporter/report_manager.rb
Expand Up @@ -33,12 +33,18 @@ def write_report(suite)
# SPEC-MailsController.N.xml
#
# with N < 100000, to prevent endless sidestep loops
MAX_SIDESTEPS = 100000
MAX_SIDESTEPS = 100000
MAX_FILENAME_SIZE = 240
#
def filename_for(suite)
basename = "#{@basename}-#{suite.name.gsub(/[^a-zA-Z0-9]+/, '-')}"
suffix = "xml"

# shorten basename if it exceeds 240 characters
# most filesystems have a 255 character limit
# so leave some room for the sidesteps
basename = basename[0..MAX_FILENAME_SIZE] if basename.length > MAX_FILENAME_SIZE

# the initial filename, e.g. SPEC-MailsController.xml
filename = [basename, suffix].join(".")

Expand Down
11 changes: 11 additions & 0 deletions spec/ci/reporter/report_manager_spec.rb
Expand Up @@ -36,4 +36,15 @@
File.exist?(filename).should be_true
File.open(filename) {|f| f.read.should == "<xml></xml>"}
end

it "should shorten extremely long report filenames" do
reporter = CI::Reporter::ReportManager.new("spec")
suite = mock("test suite")
suite.should_receive(:name).and_return("some test suite name that goes on and on and on and on and on and on and does not look like it will end any time soon and just when you think it is almost over it just continues to go on and on and on and on and on until it is almost over but wait there is more and then el fin")
suite.should_receive(:to_xml).and_return("<xml></xml>")
reporter.write_report(suite)
filename = "#{REPORTS_DIR}/SPEC-some-test-suite-name-that-goes-on-and-on-and-on-and-on-and-on-and-on-and-does-not-look-like-it-will-end-any-time-soon-and-just-when-you-think-it-is-almost-over-it-just-continues-to-go-on.xml"
File.exist?(filename).should be_true
File.open(filename) {|f| f.read.should == "<xml></xml>"}
end
end

0 comments on commit ee3d0ef

Please sign in to comment.