{"action":"opened","issue":{"url":"https://api.github.com/repos/halide/Halide/issues/898","labels_url":"https://api.github.com/repos/halide/Halide/issues/898/labels{/name}","comments_url":"https://api.github.com/repos/halide/Halide/issues/898/comments","events_url":"https://api.github.com/repos/halide/Halide/issues/898/events","html_url":"https://github.com/halide/Halide/issues/898","id":99343057,"number":898,"title":"Testing utility library","user":{"login":"delcypher","id":511795,"avatar_url":"https://avatars.githubusercontent.com/u/511795?v=3","gravatar_id":"","url":"https://api.github.com/users/delcypher","html_url":"https://github.com/delcypher","followers_url":"https://api.github.com/users/delcypher/followers","following_url":"https://api.github.com/users/delcypher/following{/other_user}","gists_url":"https://api.github.com/users/delcypher/gists{/gist_id}","starred_url":"https://api.github.com/users/delcypher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delcypher/subscriptions","organizations_url":"https://api.github.com/users/delcypher/orgs","repos_url":"https://api.github.com/users/delcypher/repos","events_url":"https://api.github.com/users/delcypher/events{/privacy}","received_events_url":"https://api.github.com/users/delcypher/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-06T02:59:25Z","updated_at":"2015-08-06T02:59:25Z","closed_at":null,"body":"I've been taking a look at some of the test and I think we are in need of some sort of utility library to assert properties in tests.\r\n\r\nThere seems to be mix of different styles. Here are some examples\r\n\r\n```\r\n    if (result_f != 50) {\r\n        printf(\"Arg max of f is %d, but should have been 50\\n\", result_f);\r\n        return -1;\r\n    }\r\n```\r\n\r\n```\r\n    for (int i = 0; i < 3; i++) {\r\n        for (int j = 0; j < 5; j++) {\r\n            float in = input(i, j);\r\n            float expected = in * scale(0, 0) * (negate(0, 0) ? -1.0f : 1.0f);\r\n            assert(output(i, j) == expected);\r\n        }\r\n    }\r\n```\r\n\r\n```\r\n    if (!target.has_feature(Target::OpenGL))  {\r\n        fprintf(stderr,\"ERROR: This test must be run with an OpenGL target, e.g. by setting HL_JIT_TARGET=host-opengl.\\n\");\r\n        return 1;\r\n    }\r\n```\r\n\r\nHaving the tests like this present some problems\r\n\r\n* The ``assert()`` tests don't do anything on Release build because asserts are disabled!\r\n* ``return 1`` isn't so great for debugging in gdb because the process exits normally. ``abort()`` works better for this use case because gdb catches ``SIGABRT``.\r\n* (minor) Inconsistent style confuses new developers (i.e. me) because they don't really know which to use.\r\n\r\nSo I think we need some sort of utility library to assert properties so that it is done consistently and without the issues I mentioned above. I noticed that Halide has a built in assertion mechanism (e.g. ``internal_error()``) for doing this already is there a reason that is not being used for the tests?\r\n\r\nAlternatively we could use something like GTest to assert properties."}}