From f8423ebea413605b42de23f5dd06c5479d3fa1dd Mon Sep 17 00:00:00 2001 From: Ethan Werner Date: Sat, 10 Oct 2026 20:55:33 +0000 Subject: initial commit --- tests/test_quine.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/test_quine.c (limited to 'tests/test_quine.c') diff --git a/tests/test_quine.c b/tests/test_quine.c new file mode 100644 index 0000000..c010539 --- /dev/null +++ b/tests/test_quine.c @@ -0,0 +1,27 @@ +/* test_quine.c — a C quine: running it prints its own source. + * + * How it works: the file is a fixed point of a "quinate" function. + * The two strings below are that function's data; everything around + * them is code that re-emits the data verbatim, spliced back into the + * same program shape. No argv, no /proc/self, no tricks — just two + * printf calls. + * + * Build: musl-gcc -std=gnu11 -Oz -Wall -Wextra -o test_quine tests/test_quine.c + * Check: ./test_quine | diff - tests/test_quine.c (no output = quine) */ + +#include + +int main(void) { + const char *s = + "const char *s = \"%s\";\n" + "const char *f = \"%s\";\n" + "printf(f, s, s, f);\n" + "return 0;\n"; + const char *f = + "int main(void) {\n" + " %s printf(f, s, s, f);\n" + " return 0;\n" + "}\n"; + printf(f, s, s, f); + return 0; +} -- cgit v1.3.1