一. 环境
- vscode
- WSL
- 安装erlang
sudo apt install erlang
- 安装rebar3
sudo apt install rebar3
xiaqiu@xz:~/erlang$ rebar3 new app hello
===> Writing hello/src/hello_app.erl
===> Writing hello/src/hello_sup.erl
===> Writing hello/src/hello.app.src
===> Writing hello/rebar.config
===> Writing hello/.gitignore
===> Writing hello/LICENSE
===> Writing hello/README.md
xiaqiu@xz:~/erlang$
xiaqiu@xz:~/erlang$ ls
hello
xiaqiu@xz:~/erlang$
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch erlang",
"type": "erlang",
"request": "launch",
//这个cwd 的目录是_build 的目录,因为我的_build 就是生成在根目录下所以参数是${workspaceRoot}
"cwd": "${workspaceRoot}",
//两行都可以,arguments这行必须加,并且写对,不然程序运行起来一闪而过
//"arguments": "-s application start hello_app",
"arguments": "-eval \"application:start(hello_app)\"",
"preLaunchTask": "rebar3 compile"
}
]
}
.vscode/tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "rebar3 compile",
"type": "shell",
"command": "rebar3 compile",
"problemMatcher": ["$erlang"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
xiaqiu@xz:~/erlang/study$ rebar3 new app break_check
xiaqiu@xz:~/erlang/study$ ls
break_check
xiaqiu@xz:~/erlang/study$
test/basic_SUITE.erl
%%%-------------------------------------------------------------------
%%% @author Rafal Wolak
%%% @copyright (C) 2015, robo software innovations
%%% @doc
%%%
%%% @end
%%% Created : 02. Nov 2015 20:13
%%%-------------------------------------------------------------------
-module(basic_SUITE).
-author("Rafal Wolak").
-include_lib("common_test/include/ct.hrl").
-export([all/0]).
-export([test1/1, test2/1]).
all() -> [test1,test2].
test1(_Config) ->
1 = 1.
test2(_Config) ->
A = 0,
A/1.
test/start_SUITE.erl
-module(start_SUITE).
-compile(export_all).
all() ->
[mod_exists].
mod_exists(_) ->
{module,start_SUITE} = code:load_file(start_SUITE).
test/state_SUITE.erl
%%%-------------------------------------------------------------------
%%% @author Rafal Wolak
%%% @copyright (C) 2015, robo software innovations
%%% @doc
%%%
%%% @end
%%% Created : 02. lis 2015 20:26
%%%-------------------------------------------------------------------
-module(state_SUITE).
-author("Rafal Wolak").
-include_lib("common_test/include/ct.hrl").
-export([all/0, init_per_testcase/2, end_per_testcase/2]).
-export([ets_tests/1]).
all() -> [ets_tests].
init_per_testcase(ets_tests, Config) ->
TabId = ets:new(account, [ordered_set, public]),
ets:insert(TabId, {andy, 2131}),
ets:insert(TabId, {david, 12}),
ets:insert(TabId, {steve, 12943752}),
[{table,TabId} | Config].
end_per_testcase(ets_tests, Config) ->
ets:delete(?config(table, Config)).
ets_tests(Config) ->
TabId = ?config(table, Config),
[{david, 12}] = ets:lookup(TabId, david),
steve = ets:last(TabId),
true = ets:insert(TabId, {zachary, 99}),
zachary = ets:last(TabId).
rebar3 ct 编译common test
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch erlang",
"type": "erlang",
"request": "launch",
"cwd": "${workspaceRoot}",
// "arguments": "-s application start hello_app", //两行都可以
"arguments": "-eval \"application:start(break_check_app)\"",
"preLaunchTask": "rebar3 compile"
}
]
}
.vscode/tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "rebar3 compile",
"type": "shell",
"command": "rebar3 ct",
"problemMatcher": ["$erlang"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
rebar.config
{erl_opts, [debug_info]}.
{deps, []}.
{profiles, [
{test, [{erl_opts, [nowarn_export_all]}]}
]}.
{shell, [
% {config, "config/sys.config"},
{apps, [break_check]}
]}.