This isn't really be any different to TDD on a standard application (especially one that interfaces to a database etc...). You can unit test the components that are composed to make your application in isolation. Then for the test you mention above, you just have to use your best judgement to make a test that still allows the code to be flexible, but also still thoroughly tests the desired behaviour.
One idea would be to still test the resultant code comes out correctly, but isolate the checks behind a builder object that builds up the expected output source code to assert against. e.g.
With(int number)
{
_sourceString += number.ToString(<Assign formatting here>);
Return this;
}
This way if your outputs do change, you only have to change them in the one builder method.