>>mkdir hg_hook >>cd hg_hook >>hg init >>touch main.c >>touch Sconstruct
然后我们修改main.c,代码如下:
#include <stdio.h>
int main(void)
{
printf("hello world!\r\n");
return 0;
}
import os
import sys
BUILD = 'debug'
# toolchains
CC = 'gcc'
if BUILD == 'debug':
CFLAGS = ' -Wall -g -O0'
else:
CFLAGS = ' -O2'
CFLAGS += ' -I'+os.getcwd() + '/'
TARGET = 'main.out'
env = Environment(CC=CC,
CCFLAGS=CFLAGS)
env.Program(TARGET, 'main.c')
env.Command('-r', TARGET, './'+TARGET)Scons是一个类似于makefile的自动编译工具,大家如果有什么以后可以网上google一下,很多Scons的使用介绍。
这里我主要介绍最后一行:
env.Command('-r', TARGET, './'+TARGET)这是自定义一个命令,在我们编译好以后自动执行我们生成的可执行文件。便于我们测试程序运行结果。
我们在终端输入:scons -r,可以看到输出结果。
>>hg add . >>hg commit -m "packed init"这样我们就有了一个版本库。
>>thg
[hooks] changegroup = update update = scons -r第一行表示当有用户提交代码的时候,自动调用update。
>>hg serve启动版本库服务器。
#include <stdio.h>
int main(void)
{
printf("hello world!\r\n");
x=6; // 添加的错误代码
return 0;
}
本地commit一下,然后pull到服务器,在log窗口可以看到如下信息:objs = Object(Glob('*.c'))
Return('objs')修改hg-hook目录下的Sconstruct文件,添加几行代码:import os
import sys
BUILD = 'debug'
# toolchains
CC = 'gcc'
if BUILD == 'debug':
CFLAGS = ' -Wall -g -O0'
else:
CFLAGS = ' -O2'
CFLAGS += ' -I'+os.getcwd() + <span style="font-family: Arial, Helvetica, sans-serif;">' -I'+os.getcwd() + ‘/unity’</span>
MY_ROOT = os.path.normpath(os.getcwd()) # 添加的代码:获取当前根目录
TARGET = 'main.out'
env = Environment(CC=CC,
CCFLAGS=CFLAGS)
objs = env.Object(Glob("*.c")) # 获取当前的源文件对象
objs += SConscript(['unity/Sconscript']) # 获取unity文件夹内的所有源文件对象
env.Program(TARGET, objs)
env.Command('-r', TARGET, './'+TARGET)
#include <hello-world.h>
#include <stdio.h>
void hello_world(void)
{
printf("hello world\r\n");
}hello-world.h#ifndef __HELLO_WORLD_H__ #define __HELLO_WORLD_H__ void hello_world(void); #endif然后我们修改main.c为:
#include <unity_fixture.h>
static void run_all_test(void)
{
RUN_TEST_GROUP(hello_world);
}
static char *arg_string[] =
{
"main",
"-v",
};
int main(int argc, char *argv[])
{
argc = sizeof(arg_string)/sizeof(char *);
argv = arg_string;
return UnityMain(argc, argv, run_all_test);
}
这个是我们测试夹具的框架。下面添加测试用例。#include "unity_fixture.h"
#include "hello-world.h"
TEST_GROUP(hello_world);
TEST_SETUP(hello_world)
{
printf("\r\nstart\r\n");
}
TEST_TEAR_DOWN(hello_world)
{
printf("end\r\n");
}
TEST(hello_world, test1)
{
hello_world();
}
添加hello-world-runner.c文件,用于测试夹具的启动:#include "unity_fixture.h"
TEST_GROUP_RUNNER(hello_world)
{
RUN_TEST_CASE(hello_world, test1);
}
接着我们运行hg commit,hg push,我们可以看到:原文:http://blog.csdn.net/utopiaprince/article/details/40297923