vvc:
$(CC) $(CC_FLAGS) -o $@ vv_compiler.c
+test: all
+ @echo "Starting test suite..."
+ @./vv_test.py
+
clean:
@rm -f vvc vvc.core vvi vvi.core
--- /dev/null
+# This test verifies we can push a number on the stack, print it as a
+# character, and cleanly exit. These three functions form a basis for further
+# tests.
+
+SSSTSSSSSTN | ST: Push +65 (ASCII A)
+TNSS | IO: Output character
+NNN | FC: Terminate program
--- /dev/null
+# This test verifies operations under the Stack IMP ([Space]).
+
+SSSTSSSSSTN | ST: Push +65 (ASCII A)
+SSSTSSSSTSN | ST: Push +66 (ASCII B)
+SNS | ST: Duplicate TOS
+TNSS | IO: Output character
+SNT | ST: Swap TOS and NOS
+SNN | ST: Discard TOS
+TNSS | IO: Output character
+NNN | FC: Terminate program
fclose(input);
fclose(output);
- printf("Successfully converted source code.\n");
-
exit(EXIT_SUCCESS);
}
void
ws_die(size_t * pc, char * msg)
{
- printf("\n");
printf("SIM_ERROR @ PC %lu: %s\n", *pc, msg);
fflush(stdout);
exit(EXIT_FAILURE);
switch (next_code_byte(code,pc)) {
case '\n':
/* Technically another LF is required but we ignore it. */
- printf("\n");
fflush(stdout);
exit(EXIT_SUCCESS);
case ' ':
--- /dev/null
+#!/usr/local/bin/python3.6
+
+# (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
+# All rights reserved.
+
+# Quick and dirty tests for the VVhitespace interpreter.
+
+import os, subprocess
+
+compiler_path = './vvc'
+interpreter_path = './vvi'
+temp_file = './test.vvs'
+path_to_tests = './tests/'
+src_extension = '.pvvs'
+
+tests = [
+ ['0001_push_printchar_exit', 'A'],
+ ['1001_stack_operations', 'BB']
+ ]
+
+for test in tests:
+ subprocess.run([compiler_path, '-i', path_to_tests + test[0] + src_extension, '-o', temp_file])
+ result = subprocess.run([interpreter_path, '-i', temp_file], stdout=subprocess.PIPE)
+ if result.stdout.decode('utf-8') != test[1]:
+ print(test[0])
+ else:
+ print('.', end='')
+ os.remove(temp_file)
+
+print("")