require

Catch 入门教程

我们两清 提交于 2019-11-26 14:24:21
Catch 使用教程(入门,官方文档翻译) 获得 Catch 如何使用? 编写测试用例 测试用例和测试区段 BDD-Style 小结 参数类型化测试 后续学习与使用 获得 Catch 最简单的方式是下载最新的 single header version 。这个头文件由若干其他独立的头文件合并而成。 你也可以使用其他方法获得Catch,例如使用CMake来构建编译版Catch,这可以提高软件的编译速度。 完整的Catch包含测试、说明文档等内容,可以从GitHub下载完整的Catch2。Catch2官方链接为: http://catch-lib.net ,此链接将重定向到GitHub。 如何使用 Catch? Catch是header-only的。你只需要将Catch的头文件放到编译器可以发现的路径既可。 下面的教程默认你的编译器可以发现并使用 Catch。 *如果你使用Catch的预编译形式,即已经编译并生成了Catch链接库(.lib 或者 .a 文件),你的Catch头文件包含形式应该形如: #include <catch2/catch.hpp> 编写测试用例 让我们从一个简单的示例开始(examples/010-TestCase.cpp)。假设你已经写了一个用于计算阶乘的函数,现在准备测试它。(TDD的基本准则是先写测试代码,这里先不管这个) unsigned int

Conditional build based on environment using Webpack

…衆ロ難τιáo~ 提交于 2019-11-26 12:55:01
问题 I have some things for development - e.g mocks which I would like to not bloat my distributed build file with. In RequireJS you can pass a config in a plugin file and conditonally require things in based on that. For webpack there doesn\'t seem to be a way of doing this. Firstly to create a runtime config for an environment I have used resolve.alias to repoint a require depending on the environment, e.g: // All settings. var all = { fish: \'salmon\' }; // `envsettings` is an alias resolved at

AST抽象语法树 Javascript版

空扰寡人 提交于 2019-11-26 12:08:37
在javascript世界中,你可以认为抽象语法树(AST)是最底层。 再往下,就是关于转换和编译的“黑魔法”领域了。 现在,我们拆解一个简单的add函数 function add(a, b) { return a + b } 首先,我们拿到的这个语法块,是一个FunctionDeclaration(函数定义)对象。 用力拆开,它成了三块: 一个id,就是它的名字,即add 两个params,就是它的参数,即[a, b] 一块body,也就是大括号内的一堆东西 add没办法继续拆下去了,它是一个最基础Identifier(标志)对象,用来作为函数的唯一标志。 { name: 'add' type: 'identifier' ... } params继续拆下去,其实是两个Identifier组成的数组。之后也没办法拆下去了。 [ { name: 'a' type: 'identifier' ... }, { name: 'b' type: 'identifier' ... } ] 接下来,我们继续拆开body 我们发现,body其实是一个BlockStatement(块状域)对象,用来表示是 {return a + b} 打开Blockstatement,里面藏着一个ReturnStatement(Return域)对象,用来表示 return a + b

How does require() in node.js work?

我与影子孤独终老i 提交于 2019-11-26 12:06:21
问题 I tried this: // mod.js var a = 1; this.b = 2; exports.c = 3; // test.js var mod = require(\'./mod.js\'); console.log(mod.a); // undefined console.log(mod.b); // 2 console.log(mod.c); // 3, so this === exports? So I image that require() may be implement like this: var require = function (file) { var exports = {}; var run = function (file) { // include \"file\" here and run }; run.apply(exports, [file]); return exports; } Is that right? Please help me to understand require(), or where can I

How to make node.js require absolute? (instead of relative)

你。 提交于 2019-11-26 11:59:29
I would like to require my files always by the root of my project and not relative to the current module. For example if you look at https://github.com/visionmedia/express/blob/2820f2227de0229c5d7f28009aa432f9f3a7b5f9/examples/downloads/app.js line 6 you will see express = require('../../') That's really bad IMO. Imagine I would like to put all my examples closer to the root only by one level. That would be impossible, because I would have to update more than 30 examples and many times within each example. To this: express = require('../') My solution would be to have a special case for root

When should I use require() and when to use define()?

烂漫一生 提交于 2019-11-26 11:43:35
问题 I have being playing around with requirejs for the last few days. I am trying to understand the differences between define and require. Define seems to allow for module separation and allow for dependency ordering to be adhere. But it downloads all the files it needs to begin with. Whilst require only loads what you need when you need it. Can these two be used together and for what purposes should each of them be used? 回答1: With define you register a module in require.js that you can then

What is the difference between include and require in Ruby?

a 夏天 提交于 2019-11-26 10:58:42
My question is similar to " What is the difference between include and extend in Ruby? ". What's the difference between require and include in Ruby? If I just want to use the methods from a module in my class, should I require it or include it? HanClinto What's the difference between "include" and "require" in Ruby? Answer: The include and require methods do very different things. The require method does what include does in most other programming languages: run another file. It also tracks what you've required in the past and won't require the same file twice. To run another file without this

Rails 3 library not loading until require

不想你离开。 提交于 2019-11-26 10:35:59
问题 I\'m trying to load the Tokbox SDK in rails 3. I\'ve placed the library in my /lib directory, so currently my directory structure looks like so: /lib opentok.rb /OpenTok Exceptions.rb OpenTokSDK.rb Session.rb I\'m loading all files in the /lib directory using the following in application.rb: config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += Dir[\"#{config.root}/lib/**/\"] Other files I have in the /lib directory are auto-loading just fine, but this library does not load

How to remove module after “require” in node.js?

主宰稳场 提交于 2019-11-26 10:27:43
问题 Let say, after I require a module and do something as below: var b = require(\'./b.js\'); --- do something with b --- Then I want to take away module b (i.e. clean up the cache). how I can do it? The reason is that I want to dynamically load/ remove or update the module without restarting node server. any idea? ------- more -------- based on the suggestion to delete require.cache, it still doesn\'t work... what I did are few things: 1) delete require.cache[require.resolve(\'./b.js\')]; 2)

node项目实战-用node-koa2-mysql-bootstrap搭建一个前端论坛

≡放荡痞女 提交于 2019-11-26 09:37:57
前言 在学习了koa2和express并写了一些demo后,打算自己写一个项目练练手,由于是在校生,没什么好的项目做,即以开发一个前端论坛为目标,功能需求参照一下一些社区拟定,主要有: 登录注册 个人信息维护、头像等基本信息 发表文章,富文本编辑器采用wangEditor插件,编辑、删除文章,文章分类等 文章评论、文章收藏、点赞等 支持文章分页、评论分页加载 关注取关用户 资源(文件)上传分享、下载、查看 学习资源推荐..... 作者个人日记 but。。。。由于种种原因,目前仅实现了部分功能,资源分享还没写 项目运行效果: http://120.77.211.212/home 项目技术栈应用:node-koa2-ejs-bootstrap3—jquery, github地址: https://github.com/Jay214/myb... ,如果觉得对你有帮助或者还看得下去,欢迎star~~鼓励鼓励我这前端渣渣辉。 开发环境 node: v8.3.0 koa: ^2.4.1 mysql: 5.7.1 npm: 5.3.0及以上 如何运行项目 将项目clone至本地 git clone git@github.com:Jay214/myblog-koa2.git 安装模块中间件 npm install 安装mysql mysql版本推荐使用5.7以下的,5.7的有个bug