Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision e3a5a73f76c9a4e3291e13112839d8e420bda8be)
+++ tests/Makefile.am	(revision 8c3a0336d1b9f37a088d18644f11e4b63c247629)
@@ -44,5 +44,5 @@
 CC = @CFACC@
 
-PRETTY_PATH=cd ${srcdir} &&
+PRETTY_PATH=mkdir -p $(dir $(abspath ${@})) && cd ${srcdir} &&
 
 .PHONY: list .validate
@@ -85,74 +85,70 @@
 #----------------------------------------------------------------------------------------------------------------
 
+# Use for all tests, make sure the path are correct and all flags are added
+CFACOMPILETEST=$(PRETTY_PATH) $(CFACOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) $($(shell echo "${@}_FLAGS" | sed 's/-\|\//_/g'))
+
+# Use for tests that either generate an executable, print directyl to stdout or the make command is expected to fail
+CFATEST_STDOUT=$(CFACOMPILETEST) -o $(abspath ${@})
+
+# Use for tests where the make command is expecte to succeed but the expected.txt should be compared to stderr
+CFATEST_STDERR=$(CFACOMPILETEST) 2> $(abspath ${@})
+
+#----------------------------------------------------------------------------------------------------------------
+
 # implicit rule so not all test require a rule
 % : %.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+	$(CFATEST_STDOUT)
 
 % : %.cpp
 	$(PRETTY_PATH) $(CXXCOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
 
-declarationSpecifier: declarationSpecifier.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -CFA -XCFA -p $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+#------------------------------------------------------------------------------
+# TARGET WITH STANDARD RULE BUT CUSTOM FLAGS
+#------------------------------------------------------------------------------
+# Expected failures
+declarationSpecifier_FLAGS= -CFA -XCFA -p
+gccExtensions_FLAGS= -CFA -XCFA -p
+extension_FLAGS= -CFA -XCFA -p
+attributes_FLAGS= -CFA -XCFA -p
+functions_FLAGS= -CFA -XCFA -p
+KRfunctions_FLAGS= -CFA -XCFA -p
+gmp_FLAGS= -lgmp
 
-gccExtensions : gccExtensions.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -CFA -XCFA -p $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+#------------------------------------------------------------------------------
+# Expected failures
+completeTypeError_FLAGS= -DERR1
 
-extension : extension.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -CFA -XCFA -p $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+#------------------------------------------------------------------------------
+# CUSTOM TARGET
+#------------------------------------------------------------------------------
+typedefRedef-ERR1: typedefRedef.cfa $(CFACC)
+	$(CFATEST_STDOUT) -DERR1
 
-attributes : attributes.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -CFA -XCFA -p $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+alloc-ERROR: alloc.cfa $(CFACC)
+	$(CFATEST_STDOUT) -DERR1
 
-functions: functions.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -CFA -XCFA -p $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+nested-types-ERR1: nested-types.cfa $(CFACC)
+	$(CFATEST_STDOUT) -DERR1
 
-KRfunctions : KRfunctions.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -CFA -XCFA -p $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+nested-types-ERR2: nested-types.cfa $(CFACC)
+	$(CFATEST_STDOUT) -DERR2
 
-sched-ext-parse : sched-ext-parse.c $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -CFA -XCFA -p $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+raii/dtor-early-exit-ERR1: raii/dtor-early-exit.cfa $(CFACC)
+	$(CFATEST_STDOUT) -DERR1
 
-gmp : gmp.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -lgmp $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+raii/dtor-early-exit-ERR2: raii/dtor-early-exit.cfa $(CFACC)
+	$(CFATEST_STDOUT) -DERR2
+
+raii/memberCtors-ERR1: raii/memberCtors.cfa $(CFACC)
+	$(CFATEST_STDOUT) -DERR1
+
+raii/ctor-autogen-ERR1: raii/ctor-autogen.cfa $(CFACC)
+	$(CFATEST_STDOUT) -DERR1
 
 #builtins
 builtins/sync: builtins/sync.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) 2> $(abspath ${@}) -fsyntax-only
-
-#------------------------------------------------------------------------------
-
-#To make errors path independent we need to cd into the correct directories
-completeTypeError : completeTypeError.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR1 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-typedefRedef-ERR1: typedefRedef.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR1 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-alloc-ERROR: alloc.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR1 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-fallthrough-ERROR: fallthrough.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR1 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-nested-types-ERR1: nested-types.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR1 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-nested-types-ERR2: nested-types.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR2 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-# Constructor/destructor tests
-raii/dtor-early-exit-ERR1: raii/dtor-early-exit.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR1 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-raii/dtor-early-exit-ERR2: raii/dtor-early-exit.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR2 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-raii/memberCtors-ERR1: raii/memberCtors.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR1 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
-
-raii/ctor-autogen-ERR1: raii/ctor-autogen.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) -DERR1 $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+	$(CFATEST_STDERR) -fsyntax-only
 
 # Warnings
 warnings/self-assignment: warnings/self-assignment.cfa $(CFACC)
-	$(PRETTY_PATH) $(CFACOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) 2> $(abspath ${@}) -fsyntax-only
+	$(CFATEST_STDERR) -fsyntax-only
