vscode debug erlang

该文介绍了如何在VisualStudioCode(VSCode)的WindowsSubsystemforLinux(WSL)环境下安装Erlang和rebar3,然后创建一个新的Erlang应用。接着,展示了如何编写和配置launch.json及tasks.json文件来运行和调试CommonTest测试套件。文章还包含了一个简单的测试示例。
摘要由CSDN通过智能技术生成

一. 环境

  1. vscode
  2. WSL
  3. 安装erlang

sudo apt install erlang

  1. 安装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]}
]}.

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值