Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: wesbillman/emu
base: 53fd4ebfa9
...
head fork: wesbillman/emu
compare: fad3c6810b
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
3  .gitignore
@@ -9,4 +9,5 @@ build/
*.perspectivev3
*.mode1v3
*.mode2v3
-emu.1
+emu.1
+xcuserdata
View
299 emu.c
@@ -27,8 +27,8 @@
#include "emu.h"
typedef struct {
- unsigned int num_suites;
- emu_suite* suites[MAX_SUITES_IN_REPO];
+ unsigned int num_suites;
+ emu_suite* suites[MAX_SUITES_IN_REPO];
} emu_repo;
static emu_repo _repo;
@@ -37,209 +37,208 @@ static emu_test* _current_test;
static char* _emu_strcpy(const char* old)
{
- int len = strlen(old);
- char* newStr = (char*)emu_malloc(sizeof(char) * (len + 1));
- strcpy(newStr, old);
- return newStr;
+ int len = strlen(old);
+ char* newStr = (char*)emu_malloc(sizeof(char) * (len + 1));
+ strcpy(newStr, old);
+ return newStr;
}
emu_test* emu_test_add(emu_suite* suite, const char* name, emu_test_func test_func)
{
- assert(suite != NULL);
- assert(suite->num_tests < MAX_TESTS_IN_SUITE);
- assert(name != NULL);
-
- emu_test* test = ((emu_test*) emu_malloc(sizeof(emu_test)));
- test->name = _emu_strcpy(name);
- test->message = NULL;
- test->passed = 0;
- test->ran = 0;
- test->test_func = test_func;
-
- //add this new suite to our repo
- suite->tests[suite->num_tests] = test;
- suite->num_tests++;
- return test;
+ assert(suite != NULL);
+ assert(suite->num_tests < MAX_TESTS_IN_SUITE);
+ assert(name != NULL);
+
+ emu_test* test = ((emu_test*) emu_malloc(sizeof(emu_test)));
+ test->name = _emu_strcpy(name);
+ test->message = NULL;
+ test->passed = 0;
+ test->ran = 0;
+ test->test_func = test_func;
+
+ //add this new suite to our repo
+ suite->tests[suite->num_tests] = test;
+ suite->num_tests++;
+ return test;
}
void emu_test_delete(emu_test* test)
{
- if (!test) return;
- emu_free(test->name);
- emu_free(test);
+ if (!test) return;
+ emu_free(test->name);
+ emu_free(test);
}
void emu_test_run(emu_test* test)
{
- if (test == NULL) return;
- _current_test = test;
- test->ran = 1;
-
- //clear previous run stats
- test->assertions = 0;
- test->failed_assertions = 0;
- test->passed = 0;
-
- if (test->test_func == NULL) return;
- test->passed = (test->test_func(test) == EMU_OK);
+ if (test == NULL) return;
+ _current_test = test;
+ test->ran = 1;
+
+ //clear previous run stats
+ test->assertions = 0;
+ test->failed_assertions = 0;
+ test->passed = 0;
+
+ if (test->test_func == NULL) return;
+ test->passed = (test->test_func(test) == EMU_OK);
}
void emu_test_display_summary(emu_test* test)
{
- int i;
- for (i = 0; i < (test->assertions - test->failed_assertions); i++) {
- emu_printf(".");
- }
- for (i = 0; i < test->failed_assertions; i++) {
- emu_printf("F");
- }
+ int i;
+ for (i = 0; i < (test->assertions - test->failed_assertions); i++) {
+ emu_printf(".");
+ }
+ for (i = 0; i < test->failed_assertions; i++) {
+ emu_printf("F");
+ }
}
void emu_test_display_details(emu_test* test)
{
- emu_printf("test %s\n", test->name);
- emu_printf(" assertions: %d (%d passed, %d failed)\n",
- test->assertions, (test->assertions - test->failed_assertions),
- test->failed_assertions);
+ emu_printf("test %s\n", test->name);
+ emu_printf(" assertions: %d (%d passed, %d failed)\n",
+ test->assertions, (test->assertions - test->failed_assertions),
+ test->failed_assertions);
}
emu_suite* emu_suite_add(const char* name, emu_setup setup, emu_teardown teardown)
{
- assert(name != NULL);
- emu_suite* suite = ((emu_suite*) emu_malloc(sizeof(emu_suite)));
- suite->name = _emu_strcpy(name);
- suite->num_tests = 0;
- suite->num_failed = 0;
- suite->setup = setup;
- suite->teardown = teardown;
- emu_memset(suite->tests, 0, sizeof(suite->tests));
-
- //add this new suite to our repo
- _repo.suites[_repo.num_suites] = suite;
- _repo.num_suites++;
- return suite;
+ assert(name != NULL);
+ emu_suite* suite = ((emu_suite*) emu_malloc(sizeof(emu_suite)));
+ suite->name = _emu_strcpy(name);
+ suite->num_tests = 0;
+ suite->num_failed = 0;
+ suite->setup = setup;
+ suite->teardown = teardown;
+ emu_memset(suite->tests, 0, sizeof(suite->tests));
+
+ //add this new suite to our repo
+ _repo.suites[_repo.num_suites] = suite;
+ _repo.num_suites++;
+ return suite;
}
void emu_suite_delete(emu_suite* suite)
{
- unsigned int i;
- for (i = 0; i < suite->num_tests; i++)
- {
- if (suite->tests[i])
- {
- emu_test_delete(suite->tests[i]);
- }
- }
- emu_free(suite);
- _repo.num_suites--;
+ unsigned int i;
+ for (i = 0; i < suite->num_tests; i++)
+ {
+ if (suite->tests[i])
+ {
+ emu_test_delete(suite->tests[i]);
+ }
+ }
+ emu_free(suite);
+ _repo.num_suites--;
}
void emu_suite_run(emu_suite* suite)
{
- unsigned int i;
-
- _current_suite = suite;
-
- //clear previous run stats
- suite->num_failed = 0;
-
- //run suite setup
- if (suite->setup) {
- if(suite->setup(suite) != EMU_OK) {
- emu_printf("%s setup failed\n",suite->name);
- }
- }
-
- //run the tests
- for (i = 0 ; i < suite->num_tests; ++i)
- {
- emu_test* test = suite->tests[i];
- if (test == NULL) continue;
-
- emu_test_run(test);
- if (!test->passed) suite->num_failed++;
- }
-
- //run suite teardown
- if (suite->teardown) {
- if(suite->teardown(suite) != EMU_OK) {
- emu_printf("%s teardown failed\n", suite->name);
- }
- }
+ unsigned int i;
+
+ _current_suite = suite;
+
+ //clear previous run stats
+ suite->num_failed = 0;
+
+ //run suite setup
+ if (suite->setup) {
+ if(suite->setup(suite) != EMU_OK) {
+ emu_printf("%s setup failed\n",suite->name);
+ }
+ }
+
+ //run the tests
+ for (i = 0 ; i < suite->num_tests; ++i) {
+ emu_test* test = suite->tests[i];
+ if (test == NULL) continue;
+
+ emu_test_run(test);
+ if (!test->passed) suite->num_failed++;
+ }
+
+ //run suite teardown
+ if (suite->teardown) {
+ if(suite->teardown(suite) != EMU_OK) {
+ emu_printf("%s teardown failed\n", suite->name);
+ }
+ }
}
void emu_suite_display_summary(emu_suite* suite)
{
- unsigned int i;
- for (i = 0; i < suite->num_tests; i++) {
- emu_test_display_summary(suite->tests[i]);
- }
+ unsigned int i;
+ for (i = 0; i < suite->num_tests; i++) {
+ emu_test_display_summary(suite->tests[i]);
+ }
}
void emu_suite_display_details(emu_suite* suite)
{
- unsigned int i;
-
- emu_printf("suite: %s\n", suite->name);
- emu_printf(" num_tests: %d\n", suite->num_tests);
- emu_printf(" num_failed: %d\n", suite->num_failed);
-
- if (suite->num_tests > 0) {
- emu_printf("%s test%s\n", suite->name,
- suite->num_tests == 0 ? "" : "s");
- emu_printf("--\n");
- }
-
- for (i = 0; i < suite->num_tests; i++) {
- emu_test_display_details(suite->tests[i]);
- }
+ unsigned int i;
+
+ emu_printf("suite: %s\n", suite->name);
+ emu_printf(" num_tests: %d\n", suite->num_tests);
+ emu_printf(" num_failed: %d\n", suite->num_failed);
+
+ if (suite->num_tests > 0) {
+ emu_printf("%s test%s\n", suite->name,
+ suite->num_tests == 0 ? "" : "s");
+ emu_printf("--\n");
+ }
+
+ for (i = 0; i < suite->num_tests; i++) {
+ emu_test_display_details(suite->tests[i]);
+ }
}
void emu_all_display(void)
{
- unsigned int i;
- for (i = 0; i < _repo.num_suites; i++) {
- if (_repo.suites[i]) {
- emu_suite_display_details(_repo.suites[i]);
- }
- }
+ unsigned int i;
+ for (i = 0; i < _repo.num_suites; i++) {
+ if (_repo.suites[i]) {
+ emu_suite_display_details(_repo.suites[i]);
+ }
+ }
}
void emu_display_summary(void)
{
- unsigned int i;
-
- emu_printf("\n");
- emu_printf("emu run summary\n");
- emu_printf("---------------\n");
- for (i = 0; i < _repo.num_suites; i++) {
- emu_suite_display_summary(_repo.suites[i]);
- }
- emu_printf("\n");
+ unsigned int i;
+
+ emu_printf("\n");
+ emu_printf("emu run summary\n");
+ emu_printf("---------------\n");
+ for (i = 0; i < _repo.num_suites; i++) {
+ emu_suite_display_summary(_repo.suites[i]);
+ }
+ emu_printf("\n");
}
void emu_display_details(void)
{
- unsigned int i;
-
- emu_printf("\n");
- emu_printf("emu run details\n");
- emu_printf("---------------\n");
- for (i = 0; i < _repo.num_suites; i++) {
- emu_suite_display_details(_repo.suites[i]);
- }
- emu_printf("\n");
+ unsigned int i;
+
+ emu_printf("\n");
+ emu_printf("emu run details\n");
+ emu_printf("---------------\n");
+ for (i = 0; i < _repo.num_suites; i++) {
+ emu_suite_display_details(_repo.suites[i]);
+ }
+ emu_printf("\n");
}
void _emu_internal_fail_unless(int result, const char* file, int line, const char* message)
{
- _current_test->assertions++;
- if (!result) {
- _current_test->passed = 0;
- _current_test->failed_assertions++;
- emu_printf("%s step %s\n", _current_test->name, message);
- emu_printf(" file: %s\n", file);
- emu_printf(" line: %d\n", line);
- }
+ _current_test->assertions++;
+ if (!result) {
+ _current_test->passed = 0;
+ _current_test->failed_assertions++;
+ emu_printf("%s step %s\n", _current_test->name, message);
+ emu_printf(" file: %s\n", file);
+ emu_printf(" line: %d\n", line);
+ }
}
View
34 emu.h
@@ -49,22 +49,22 @@ typedef emu_error (*emu_teardown)(emu_suite*);
typedef emu_error (*emu_test_func)(emu_test*);
struct emu_test {
- char* name;
- emu_test_func test_func;
- unsigned char passed;
- unsigned char ran;
- unsigned int assertions;
- unsigned int failed_assertions;
- const char* message;
+ char* name;
+ emu_test_func test_func;
+ unsigned char passed;
+ unsigned char ran;
+ unsigned int assertions;
+ unsigned int failed_assertions;
+ const char* message;
};
struct emu_suite{
- char* name;
- emu_setup setup;
- emu_teardown teardown;
- unsigned int num_tests;
- unsigned int num_failed;
- emu_test* tests[MAX_TESTS_IN_SUITE];
+ char* name;
+ emu_setup setup;
+ emu_teardown teardown;
+ unsigned int num_tests;
+ unsigned int num_failed;
+ emu_test* tests[MAX_TESTS_IN_SUITE];
};
//suite functions
@@ -88,10 +88,10 @@ void emu_display_details(void);
void _emu_internal_fail_unless(int result, const char* file, int line, const char* message);
//test macros
-#define emu_fail(message) _emu_internal_fail_unless((0), __FILE__, __LINE__, (message))
-#define emu_pass(message) _emu_internal_fail_unless((1), __FILE__, __LINE__, (message))
-#define emu_fail_if(test) _emu_internal_fail_unless((!test), __FILE__, __LINE__, ("fail if '"#test"' failed"))
-#define emu_fail_unless(test) _emu_internal_fail_unless((test), __FILE__, __LINE__, ("fail unless '"#test"' failed"))
+#define emu_fail(message) _emu_internal_fail_unless((0), __FILE__, __LINE__, (message))
+#define emu_pass(message) _emu_internal_fail_unless((1), __FILE__, __LINE__, (message))
+#define emu_fail_if(test) _emu_internal_fail_unless((!test), __FILE__, __LINE__, ("fail if '"#test"' failed"))
+#define emu_fail_unless(test) _emu_internal_fail_unless((test), __FILE__, __LINE__, ("fail unless '"#test"' failed"))
#ifdef __cplusplus
}
View
12 emu.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 45;
+ objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
@@ -107,10 +107,11 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
+ LastUpgradeCheck = 0410;
ORGANIZATIONNAME = "Wes Billman";
};
buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "emu" */;
- compatibilityVersion = "Xcode 3.1";
+ compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
@@ -147,7 +148,6 @@
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
- GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INSTALL_PATH = /usr/local/bin;
@@ -175,8 +175,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
- PREBINDING = NO;
- SDKROOT = macosx10.6;
+ SDKROOT = macosx;
};
name = Debug;
};
@@ -187,8 +186,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- PREBINDING = NO;
- SDKROOT = macosx10.6;
+ SDKROOT = macosx;
};
name = Release;
};
View
7 emu.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:emu.xcodeproj">
+ </FileRef>
+</Workspace>
View
68 emu_test.c
@@ -29,55 +29,55 @@
*/
emu_error setup(emu_suite* suite)
{
- printf("Running %s setup\n", suite->name);
- return EMU_OK;
+ printf("Running %s setup\n", suite->name);
+ return EMU_OK;
}
emu_error teardown(emu_suite* suite)
{
- printf("Running %s teardown\n", suite->name);
- return EMU_OK;
+ printf("Running %s teardown\n", suite->name);
+ return EMU_OK;
}
emu_error passing_test(emu_test* test)
{
- emu_pass("this should pass");
- emu_fail_if(0 != 0);
- emu_fail_unless(0 == 0);
- emu_fail_unless(test->assertions == 3);
- emu_fail_unless(test->failed_assertions == 0);
- return EMU_OK;
+ emu_pass("this should pass");
+ emu_fail_if(0 != 0);
+ emu_fail_unless(0 == 0);
+ emu_fail_unless(test->assertions == 3);
+ emu_fail_unless(test->failed_assertions == 0);
+ return EMU_OK;
}
emu_error failing_test(emu_test* test)
{
- emu_fail("this should fail");
- emu_fail_if(1 == 1);
- emu_fail_unless(0 == 1);
- emu_fail_if(test->assertions == 3);
- emu_fail_if(test->failed_assertions == 4);
- return EMU_OK;
+ emu_fail("this should fail");
+ emu_fail_if(1 == 1);
+ emu_fail_unless(0 == 1);
+ emu_fail_if(test->assertions == 3);
+ emu_fail_if(test->failed_assertions == 4);
+ return EMU_OK;
}
int main (int argc, const char * argv[])
{
- //create a new suite of tests
- emu_suite* suite = emu_suite_add("suite_a", setup, teardown);
-
- //add some tests to the suite
- emu_test* test = emu_test_add(suite, "passing_test", passing_test);
- emu_test_add(suite, "failing_test", failing_test);
-
- //run the whole suite
- emu_suite_run(suite);
-
- //display results
- emu_display_summary();
- emu_display_details();
-
- //run a specific test
- emu_test_run(test);
- emu_test_display_details(test);
-
+ //create a new suite of tests
+ emu_suite* suite = emu_suite_add("suite_a", setup, teardown);
+
+ //add some tests to the suite
+ emu_test* test = emu_test_add(suite, "passing_test", passing_test);
+ emu_test_add(suite, "failing_test", failing_test);
+
+ //run the whole suite
+ emu_suite_run(suite);
+
+ //display results
+ emu_display_summary();
+ emu_display_details();
+
+ //run a specific test
+ emu_test_run(test);
+ emu_test_display_details(test);
+
return 0;
}

No commit comments for this range

Something went wrong with that request. Please try again.