Skip to content

Commit

Permalink
closes #185 Fix target.txt ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmelt committed Aug 10, 2015
1 parent c536539 commit a92178e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cosmos/system/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,16 @@ def add_all_cmd_tlm(dir)

# Make sure all partials are included in the cmd_tlm list for the MD5 calculation
def add_cmd_tlm_partials(dir)
partial_files = []
if Dir.exist?(File.join(dir, 'cmd_tlm'))
# Grab all _*.txt files in the cmd_tlm folder and subfolders
Dir[File.join(dir, 'cmd_tlm', '**', '_*.txt')].each do |filename|
@cmd_tlm_files << filename
partial_files << filename
end
end
partial_files.sort!
@cmd_tlm_files.concat(partial_files)
@cmd_tlm_files.uniq!
@cmd_tlm_files.sort!
end

end # class Target
Expand Down
27 changes: 27 additions & 0 deletions spec/system/target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,33 @@ module Cosmos

FileUtils.rm_r(tgt_dir)
end

it "filename order must be preserved" do
tgt_path = File.join(Cosmos::USERPATH,'target_spec_temp')
tgt_name = "TEST"
tgt_dir = File.join(tgt_path,tgt_name)
FileUtils.mkdir_p(tgt_dir)
FileUtils.mkdir_p(tgt_dir + '/cmd_tlm')
File.open(tgt_dir + '/cmd_tlm/tgt_cmds.txt', 'w') {|file| file.puts "# comment"}
File.open(tgt_dir + '/cmd_tlm/tgt_cmds2.txt', 'w') {|file| file.puts "# comment"}
File.open(tgt_dir + '/cmd_tlm/tgt_cmds3.txt', 'w') {|file| file.puts "# comment"}
File.open(tgt_dir + '/cmd_tlm/tgt_tlm.txt', 'w') {|file| file.puts "# comment"}
File.open(tgt_dir + '/cmd_tlm/tgt_tlm2.txt', 'w') {|file| file.puts "# comment"}
File.open(tgt_dir + '/cmd_tlm/tgt_tlm3.txt', 'w') {|file| file.puts "# comment"}
File.open(File.join(tgt_dir,'target.txt'),'w') do |file|
file.puts("COMMANDS tgt_cmds3.txt")
file.puts("COMMANDS tgt_cmds2.txt")
file.puts("TELEMETRY tgt_tlm3.txt")
file.puts("TELEMETRY tgt_tlm.txt")
end

tgt = Target.new(tgt_name,nil,tgt_path)
expect(tgt.dir).to eql tgt_dir
expect(tgt.cmd_tlm_files.length).to eql 4
expect(tgt.cmd_tlm_files).to eql [tgt_dir + '/cmd_tlm/tgt_cmds3.txt', tgt_dir + '/cmd_tlm/tgt_cmds2.txt', tgt_dir + '/cmd_tlm/tgt_tlm3.txt', tgt_dir + '/cmd_tlm/tgt_tlm.txt']

FileUtils.rm_r(tgt_dir)
end
end
end

Expand Down

0 comments on commit a92178e

Please sign in to comment.