-- Reading and writing files on the database host. -- -- Everything is written under /tmp because that is the one directory the tests -- can rely on already existing: SQL has no way to create one. -- Error CONTEXT carries plpgsql line numbers, which would make this -- expected output break on every unrelated edit. \set SHOW_CONTEXT never -- Quiet, so that the expected output is the same whether or not an earlier -- test in the same database already created the extension. set client_min_messages to warning; create extension if not exists pg_statecharts_dev cascade; reset client_min_messages; \set dir '/tmp/pg_statecharts_test' \set chart_a '/tmp/pg_statecharts_test_a-1.0.scxml' \set chart_b '/tmp/pg_statecharts_test_b-1.0.scxml' -- -- Writing files -- -- Content has to survive the COPY based writer untouched, including -- backslashes, dollar quotes, tabs, empty lines and a trailing newline. select fsm.__write_file(:'dir' || '_roundtrip.txt', E'line one\n\nbackslash \\ and \\n literal\n$$ do $tag$ x $tag$ $$\ttab\nlast\n'); select pg_read_file(:'dir' || '_roundtrip.txt') = E'line one\n\nbackslash \\ and \\n literal\n$$ do $tag$ x $tag$ $$\ttab\nlast\n' as roundtrip_exact; -- COPY terminates every row, so content that does not end in a newline gets -- one. Documented rather than fixed: everything this extension writes ends in -- a newline already. select fsm.__write_file(:'dir' || '_nonewline.txt', 'abc'); select pg_read_file(:'dir' || '_nonewline.txt') = E'abc\n' as trailing_newline_added; -- writing again replaces rather than appends select fsm.__write_file(:'dir' || '_nonewline.txt', 'xyz'); select pg_read_file(:'dir' || '_nonewline.txt') as replaced; -- a missing output directory is reported with the directory that is missing select fsm.__write_file('/tmp/pg_statecharts_no_such_dir/out.sql', 'x'); -- carriage returns cannot survive the writer, so they are rejected up front select fsm.__write_file(:'dir' || '_cr.txt', E'a\r\nb'); -- so is a line that is exactly a backslash and a dot, which COPY would quote select fsm.__write_file(:'dir' || '_eod.txt', E'a\n\\.\nb\n'); -- a backslash-dot with anything else on the line is fine select fsm.__write_file(:'dir' || '_eod.txt', E'a\n\\.x\nb\n'); select pg_read_file(:'dir' || '_eod.txt') = E'a\n\\.x\nb\n' as near_miss_written_exactly; -- -- Finding files -- select fsm.__write_file(:'chart_a', '' '