Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Does GLib's "GTest" testing framework have any filesystem mocking functionality?

+2
−0

I'm writing tests for some code that interacts with the filesystem, and I want to assert that it writes the expected data to disk. My problem is that some of the code I want to test includes hardcoded paths and due to my requirements I cannot avoid these without adding test-specific code paths, which I would like to avoid. As such, it seems to me that some sort of filesystem mocking is the only way to avoid polluting the filesystem with real files and potentially also messing with user configuration—the program configures other programs on the system, like a settings app.

I read through the Testing Framework section of the GLib docs, but it doesn't mention anything about this. I also searched for "test" and scanned through the results but I couldn't find anything relevant there either.

Does GLib's GTest testing framework provide any filesystem mocking functionality?

History

0 comment threads

1 answer

+0
−0

This won't work for every use-case, but for mine I was able to use the G_TEST_OPTION_ISOLATE_DIRS flag for g_test_init () like so:

g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);

This only affects XDG directories, so if your program doesn't respect those or operates outside of them this will do nothing. But for my use-case this is perfect.

History

0 comment threads

Sign up to answer this question »