Skip to content

Commit

Permalink
added ordering of files before writing test output for consistent res…
Browse files Browse the repository at this point in the history
…ults
  • Loading branch information
RlanderRISCSW committed Sep 29, 2022
1 parent 9daca1b commit 24a5fcc
Show file tree
Hide file tree
Showing 5 changed files with 555 additions and 536 deletions.
16 changes: 16 additions & 0 deletions src/lib/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ namespace tigl {
File::File(boost::filesystem::path filename)
: m_stream(new std::ostringstream), m_filename(std::move(filename)) {}

auto File::path() const -> const boost::filesystem::path&
{
return m_filename;
}

auto File::stream() -> std::ostream& {
return *m_stream;
}
Expand Down Expand Up @@ -68,11 +73,22 @@ namespace tigl {

void Filesystem::mergeFilesInto(boost::filesystem::path filename) {
File f(std::move(filename));
sortFiles();
for (auto& file : m_files) {
auto str = file.m_stream->str();
f.m_stream->write(str.c_str(), str.size());
}
m_files.clear();
m_files.push_back(std::move(f));
}

void Filesystem::sortFiles() {
std::sort(std::begin(m_files), std::end(m_files), [](const File& a, const File& b) {
return a.path() < b.path();
});
// ensure that header files come first
std::sort(std::begin(m_files), std::end(m_files), [](const File& a, const File& b) {
return a.path().extension() > b.path().extension();
});
}
}
3 changes: 3 additions & 0 deletions src/lib/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace tigl {
File(File&&) = default;
File& operator=(File&&) = default;

auto path() const -> const boost::filesystem::path&;
auto stream() -> std::ostream&;

private:
Expand All @@ -46,6 +47,8 @@ namespace tigl {
std::size_t deleted = 0;

private:
void sortFiles();

std::deque<File> m_files;
};
}
Loading

0 comments on commit 24a5fcc

Please sign in to comment.