Commit Diff


commit - d728769d30366f48bd81c28233bd89c1b8f306b0
commit + 0b453b63092adb976784e2e908bed7618100dfc3
blob - 5b307502c6eac3f8790de1e1f6f485613daad9f7
blob + 6c5de914e4816aeddea7633deef21e3b8b3455d1
--- np.y
+++ np.y
@@ -65,6 +65,8 @@ int		 lgetc(int);
 void		 lungetc(int);
 int		 findeol(void);
 
+static int	shouldfail;
+
 typedef struct {
 	union {
 		struct op	*op;
@@ -89,7 +91,7 @@ typedef struct {
 %token	INCLUDE
 %token	PROC
 %token	REPEAT
-%token	STR
+%token	SHOULD_FAIL STR
 %token	TESTING
 %token	U8 U16 U32
 
@@ -251,9 +253,14 @@ asserti	: check			{ block_push(op_assert($1)); }
 
 test	: TESTING STRING DIR STRING {
 		prepare_test();
-	} '{' optnl block '}' {
-		test_done($2, $4);
+	} testopt '{' optnl block '}' {
+		test_done(shouldfail, $2, $4);
+		shouldfail = 0;
 	}
+	;
+
+testopt	: /* empty */
+	| SHOULD_FAIL	{ shouldfail = 1; }
 	;
 
 %%
@@ -296,6 +303,7 @@ lookup(char *s)
 		{"include",	INCLUDE},
 		{"proc",	PROC},
 		{"repeat",	REPEAT},
+		{"should-fail",	SHOULD_FAIL},
 		{"str",		STR},
 		{"testing",	TESTING},
 		{"u16",		U16},
blob - 5251641aa7b2b4facb6ef1e2bd999ebc4add67f8
blob + 9511faba88384dc377c67c82817d1fa8a44ce49e
--- script.c
+++ script.c
@@ -1022,11 +1022,12 @@ prepare_test(void)
 }
 
 void
-test_done(char *name, char *dir)
+test_done(int shouldfail, char *name, char *dir)
 {
 	struct test	*test;
 
 	test = xcalloc(1, sizeof(*test));
+	test->shouldfail = shouldfail;
 	test->name = name;
 	test->dir = dir;
 	test->body = finalize(&blocks, NULL);
@@ -1358,6 +1359,15 @@ run_test(struct test *t)
 
 	while (waitpid(pid, NULL, 0) != pid)
 		; /* nop */
+
+	if (t->shouldfail) {
+		if (ret == EVAL_OK) {
+			before_printing();
+			printf("test was expected to fail\n");
+			return EVAL_ERR;
+		} else if (ret == EVAL_ERR)
+			return EVAL_OK;
+	}
 
 	return ret;
 }
blob - ad15a7b8674cc8967bcb70b55cd19345f30ac9f7
blob + 3331b113f627d5fb4b3f87b1c0867389857e75aa
--- script.h
+++ script.h
@@ -142,6 +142,7 @@ struct proc {
 TAILQ_HEAD(tests, test);
 struct test {
 	TAILQ_ENTRY(test)	 entry;
+	int			 shouldfail;
 	char			*name;
 	char			*dir;
 	struct op		*body;
@@ -193,7 +194,7 @@ struct proc	*proc_by_name(const char *);
 
 /* testing */
 void		 prepare_test(void);
-void		 test_done(char *, char *);
+void		 test_done(int, char *, char *);
 
 /* np.y */
 void		 loadfile(const char *);