I want to write a function which does this: given a file and a name (string), append to the file if the last line is not 'name' (create the file if the file is not there). Otherwise just do nothing. I can certainly create a function like this:
appendIfLastLineNotEqual(file fd, string name) { ... }
However, this will be hard to write unit test as it dumps to file. Is there a cleaner way to do this, as well as easy to unit test? Also I can do file parsing backward etc to implement the function. Any smart way instead of reading the file, compare with the last line etc? Thanks!