From 58b346d986171fd69599b614a8dc823c2d4cc0ec Mon Sep 17 00:00:00 2001 From: Matthew James Briggs Date: Fri, 22 May 2026 13:12:31 +0200 Subject: [PATCH] Redirect example.musicxml and stray test outputs to data/testOutput Closes #150. The mxwrite example program previously hard-coded its output to "./example.musicxml", which left an untracked file at the repo root every time examples ran (which happens for every make test/test-all run). Fixes: - mxwrite now accepts an optional output path via argv[1] and the Makefile's run_examples helper points it at ./data/testOutput/, which is already a gitignored directory. - data/testOutput/.gitignore now also ignores *.musicxml (it only covered *.xml / *.csv / *.txt before). - Two other writeToFile calls that also dumped XML at the repo root (DocumentManagerTest.cpp sillytest.xml, RoundTrip.h output.xml) now write into data/testOutput via mxtest::getResourcesDirectoryPath(). - README and Write.cpp comments updated to describe the new behavior. Verified locally with make fmt, make check, and make test-all; no example.xml/example.musicxml/sillytest.xml/output.xml are left at the repo root after the run. --- Makefile | 5 ++++- README.md | 6 ++++-- data/testOutput/.gitignore | 1 + src/private/mx/examples/Write.cpp | 7 +++++-- src/private/mxtest/api/DocumentManagerTest.cpp | 4 +++- src/private/mxtest/api/RoundTrip.h | 4 +++- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 5f6ab1e9c..933256f16 100644 --- a/Makefile +++ b/Makefile @@ -123,9 +123,12 @@ endef # Run the three example programs from the given mode dir ($1). The test # targets run these too, so the examples are exercised everywhere tests run. +# mxwrite is told to write into data/testOutput so we don't leave an untracked +# example.musicxml at the repo root (issue #150). define run_examples + @mkdir -p data/testOutput $(call run_bin,$(1),mxread,) - $(call run_bin,$(1),mxwrite,) + $(call run_bin,$(1),mxwrite,./data/testOutput/example.musicxml) $(call run_bin,$(1),mxhide,) endef diff --git a/README.md b/README.md index e3ffbed40..37901b156 100644 --- a/README.md +++ b/README.md @@ -301,8 +301,10 @@ int main(int argc, const char * argv[]) std::cout << std::endl; #endif - // write to a file - mgr.writeToFile( documentID, "./example.musicxml" ); + // write to a file. argv[1] overrides the default output path so the build + // system can send the file to a gitignored location (see issue #150). + const std::string outputPath = ( argc > 1 ) ? argv[1] : "./example.musicxml"; + mgr.writeToFile( documentID, outputPath ); // we need to explicitly delete the object held by the manager mgr.destroyDocument( documentID ); diff --git a/data/testOutput/.gitignore b/data/testOutput/.gitignore index 3b3c2abaf..8e414ff61 100644 --- a/data/testOutput/.gitignore +++ b/data/testOutput/.gitignore @@ -1,3 +1,4 @@ *.csv +*.musicxml *.txt *.xml diff --git a/src/private/mx/examples/Write.cpp b/src/private/mx/examples/Write.cpp index bd58277a7..fc7b4382f 100644 --- a/src/private/mx/examples/Write.cpp +++ b/src/private/mx/examples/Write.cpp @@ -120,8 +120,11 @@ int main(int argc, const char *argv[]) std::cout << std::endl; #endif - // write to a file - mgr.writeToFile(documentID, "./example.musicxml"); + // write to a file. argv[1] overrides the default output path so the build + // system can send the file to a gitignored location during automated runs; + // see issue #150. + const std::string outputPath = (argc > 1) ? argv[1] : "./example.musicxml"; + mgr.writeToFile(documentID, outputPath); // we need to explicitly delete the object held by the manager mgr.destroyDocument(documentID); diff --git a/src/private/mxtest/api/DocumentManagerTest.cpp b/src/private/mxtest/api/DocumentManagerTest.cpp index abb5bac45..96eb8fe4d 100644 --- a/src/private/mxtest/api/DocumentManagerTest.cpp +++ b/src/private/mxtest/api/DocumentManagerTest.cpp @@ -187,7 +187,9 @@ TEST( sillyTest, DocumentManager ) score.encoding.encodingDate.day = 30; score.copyright = "© 2016 by Matthew James Briggs"; auto documentId = DocumentManager::getInstance().createFromScore( score ); - DocumentManager::getInstance().writeToFile( documentId, "./sillytest.xml" ); + const std::string sillyOutputPath = mxtest::getResourcesDirectoryPath() + "testOutput" + + mxtest::FILE_PATH_SEPARATOR + "sillytest.xml"; + DocumentManager::getInstance().writeToFile( documentId, sillyOutputPath ); DocumentManager::getInstance().destroyDocument( documentId ); } T_END diff --git a/src/private/mxtest/api/RoundTrip.h b/src/private/mxtest/api/RoundTrip.h index b7458c636..d89ac97e6 100644 --- a/src/private/mxtest/api/RoundTrip.h +++ b/src/private/mxtest/api/RoundTrip.h @@ -7,6 +7,7 @@ #include "mx/api/DocumentManager.h" #include "mxtest/control/CompileControl.h" #include "mxtest/file/MxFileRepository.h" +#include "mxtest/file/Path.h" #include namespace mxtest @@ -21,7 +22,8 @@ inline void roundTrip() auto scoreData = docMgr.getData(docId); docMgr.destroyDocument(docId); docId = docMgr.createFromScore(scoreData); - docMgr.writeToFile(docId, "./output.xml"); + const std::string outputPath = getResourcesDirectoryPath() + "testOutput" + FILE_PATH_SEPARATOR + "output.xml"; + docMgr.writeToFile(docId, outputPath); docMgr.destroyDocument(docId); }