Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix Cpp tests #90

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ef7a5ba
Add standard variable + use c++14
aminya Dec 3, 2020
a8296f1
Add MACOSX_DEPLOYMENT_TARGET variable
aminya Dec 3, 2020
d3f3d40
Add Release configurations and optimizations
aminya Dec 3, 2020
490e785
Use C++17 standard
aminya Dec 3, 2020
18aac65
Use Visual Studio 17 on AppVeyor
aminya Dec 3, 2020
efe74c6
Use Clang 9 on Travis
aminya Dec 4, 2020
f2129a2
Define uint
aminya Dec 5, 2020
a6908ca
Update catch test library
aminya Dec 5, 2020
0553eca
Use std::chrono and std::sleep_for instead of usleep
aminya Dec 5, 2020
f4a7d6c
Add u16string literals
aminya Dec 5, 2020
eb8eef6
Add u8 literal
aminya Dec 5, 2020
778111d
Fix tests not running becuase status is undefined
aminya Dec 5, 2020
dbdffac
Fix test:native script
aminya Dec 5, 2020
38128a3
Use Clang 9 on Travis
aminya Dec 5, 2020
9be829e
Revert "Remove other ci configs and update badge"
aminya Jul 4, 2022
65bd729
Merge branch 'master' into Release-optimizations
aminya Jul 4, 2022
d8de380
ci: update setup-node and actions/checkout
aminya Jul 4, 2022
3c50962
ci: use setup-cpp for the cpp environment
aminya Jul 4, 2022
cf24061
ci: use windows-2019 image
aminya Jul 4, 2022
214bec1
ci: run push CI only on master [skip ci]
aminya Jul 4, 2022
fefbaf0
Merge pull request #14 from atom-community/ci
aminya Jul 4, 2022
501336e
Merge branch 'master' into Release-optimizations
aminya Jul 4, 2022
8408009
Merge branch 'master' into fix-cpp-tests
aminya Jul 4, 2022
a38ec43
chore: report the status of the browser build
aminya Jul 4, 2022
c0591e6
build: increase the macos target to 10.15
aminya Jul 4, 2022
2b6943d
build: use -O3 instead of -Ofast
aminya Jul 4, 2022
90bc20c
Merge pull request #5 from atom-community/Release-optimizations
aminya Jul 4, 2022
b6d50ee
Merge branch 'master' into fix-cpp-tests
aminya Jul 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: ci
on:
- pull_request
- push
pull_request:
push:
branches: [master]

jobs:
Test:
Expand All @@ -13,24 +14,36 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest
- windows-2019
node_version:
- 10
- 12
- 14
name: Node ${{ matrix.node_version }} on ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
- name: Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
'node_modules'
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('package.json') }}

- name: Setup node
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v3
with:
node-version: 14
node-version: ${{ matrix.node_version }}
architecture: x64

- name: Setup Cpp
uses: aminya/setup-cpp@v1
with:
vcvarsall: true
architecture: x64
python: true

- name: Install dependencies
run: npm install
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Superstring
[![ci](https://github.com/atom/superstring/actions/workflows/ci.yml/badge.svg)](https://github.com/atom/superstring/actions/workflows/ci.yml)
[![macOS Build Status](https://circleci.com/gh/atom/superstring/tree/master.svg?style=shield)](https://circleci.com/gh/atom/superstring)
[![Dependency Status](https://david-dm.org/atom/superstring.svg)](https://david-dm.org/atom/superstring)



Native library at the core of Atom's text editor.

Expand Down
1 change: 1 addition & 0 deletions benchmark/native/marker-index-benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using namespace std::chrono;
using std::vector;
using uint = unsigned int;

Range get_random_range() {
Point start(rand() % 100, rand() % 100);
Expand Down
51 changes: 43 additions & 8 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
],

"variables": {
"tests": 0
"tests": 0,
"STANDARD": 17,
"MACOSX_DEPLOYMENT_TARGET": "10.15"
},

"conditions": [
Expand Down Expand Up @@ -100,25 +102,24 @@
"conditions": [
['OS=="mac"', {
'cflags': [
'-mmacosx-version-min=10.8'
"-mmacosx-version-min=<(MACOSX_DEPLOYMENT_TARGET)"
],
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
'MACOSX_DEPLOYMENT_TARGET': '10.8',
'MACOSX_DEPLOYMENT_TARGET': '<(MACOSX_DEPLOYMENT_TARGET)',
}
}]
]
}]
}]
],

"target_defaults": {
"cflags_cc": ["-std=c++11"],
"cflags_cc": [ "-std=c++<(STANDARD)" ],
"conditions": [
['OS=="mac"', {
"xcode_settings": {
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD':'c++11',
'CLANG_CXX_LANGUAGE_STANDARD':'c++(STANDARD)',
}
}],
['OS=="win"', {
Expand All @@ -129,6 +130,40 @@
"NOMINMAX"
],
}]
]
}
],
'default_configuration': 'Release',
'configurations': {
# Release Settings
'Release': {
'defines': [ 'NDEBUG' ],
"cflags": [ "-fno-exceptions", "-O3" ],
"cflags_cc": [ "-fno-exceptions", "-O3", "-std=c++<(STANDARD)" ],
"xcode_settings": {
'GCC_OPTIMIZATION_LEVEL': '3', # stop gyp from defaulting to -Os
"CLANG_CXX_LIBRARY": "libc++",
"CLANG_CXX_LANGUAGE_STANDARD": "c++<(STANDARD)",
'MACOSX_DEPLOYMENT_TARGET': "<(MACOSX_DEPLOYMENT_TARGET)"
}, # XCODE
"msvs_settings": {
"VCCLCompilerTool": {
'ExceptionHandling': 0, # /EHsc
'MultiProcessorCompilation': 'true',
'RuntimeTypeInfo': 'false',
'Optimization': 3, # full optimizations /O2 == /Og /Oi /Ot /Oy /Ob2 /GF /Gy
'StringPooling': 'true', # pool string literals
"AdditionalOptions": [
# C++ standard
"/std:c++<(STANDARD)",

# Optimizations
"/O2",
# "/Ob3", # aggressive inline
"/GL", # whole Program Optimization # /LTCG is implied with /GL.
"/DNDEBUG" # turn off asserts
],
}
} # MSVC
}, # Release
}, # configurations
} # target-defaults
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"browser": "./browser",
"scripts": {
"build:node": "node-gyp rebuild",
"build:browser": "script/build-browser-version.sh",
"build:browser": "bash -c script/build-browser-version.sh || echo 'the browser build is unsupported'",
"build": "npm run build:node && npm run build:browser",
"test:native": "node ./script/test-native.js",
"test:native": "node-gyp build --debug --tests && node script/test-native.js",
"test:node": "mocha test/js/*.js",
"test:browser": "SUPERSTRING_USE_BROWSER_VERSION=1 mocha test/js/*.js",
"test": "npm run test:node && npm run test:browser",
"test:browser": "cross-env SUPERSTRING_USE_BROWSER_VERSION=1 mocha test/js/*.js || echo 'the browser tests are unsupported'",
"test": "npm run test:node && npm run test:native && npm run test:browser",
"benchmark": "node benchmark/marker-index.benchmark.js",
"prepublishOnly": "git submodule update --init --recursive && npm run build:browser",
"standard": "standard --recursive src test"
Expand All @@ -35,6 +35,7 @@
},
"devDependencies": {
"chai": "^2.0.0",
"cross-env": "^7.0.3",
"mocha": "^2.3.4",
"random-seed": "^0.2.0",
"standard": "^4.5.4",
Expand Down
5 changes: 2 additions & 3 deletions script/test-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ switch (args[0]) {
}

function run(command, args = [], options = {stdio: 'inherit'}) {
const {status} = spawnSync(command, args, options)
if (status !== 0) process.exit(status)
}
spawnSync(command, args, options)
}
20 changes: 10 additions & 10 deletions test/native/encoding-conversion-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using std::u16string;

TEST_CASE("EncodingConversion::decode - basic UTF-8") {
auto conversion = transcoding_from("UTF-8");
string input("abγdefg\nhijklmnop");
string input(u8"abγdefg\nhijklmnop");

u16string string;
conversion->decode(string, input.data(), input.size());
Expand Down Expand Up @@ -42,7 +42,7 @@ TEST_CASE("EncodingConversion::decode - invalid byte sequences in the middle of

u16string string;
conversion->decode(string, input.data(), input.size());
REQUIRE(string == u"ab" "\ufffd" "\ufffd" "de");
REQUIRE(string == u"ab" u"\ufffd" u"\ufffd" u"de");
}

TEST_CASE("EncodingConversion::decode - invalid byte sequences at the end of the input") {
Expand All @@ -58,7 +58,7 @@ TEST_CASE("EncodingConversion::decode - invalid byte sequences at the end of the
string.clear();
bytes_encoded = conversion->decode(string, input.data(), input.size(), true);
REQUIRE(bytes_encoded == 4);
REQUIRE(string == u"ab" "\ufffd" "\ufffd");
REQUIRE(string == u"ab" u"\ufffd" u"\ufffd");
}

TEST_CASE("EncodingConversion::decode - four-byte UTF-16 characters") {
Expand All @@ -67,7 +67,7 @@ TEST_CASE("EncodingConversion::decode - four-byte UTF-16 characters") {

u16string string;
conversion->decode(string, input.data(), input.size());
REQUIRE(string == u"ab" "\xd83d" "\xde01" "cd");
REQUIRE(string == u"ab" u"\xd83d" u"\xde01" u"cd");
}

TEST_CASE("EncodingConversion::encode - basic") {
Expand All @@ -93,7 +93,7 @@ TEST_CASE("EncodingConversion::encode - basic") {

TEST_CASE("EncodingConversion::encode - four-byte UTF-16 characters") {
auto conversion = transcoding_to("UTF-8");
u16string string = u"ab" "\xd83d" "\xde01" "cd"; // 'ab😁cd'
u16string string = u"ab" u"\xd83d" u"\xde01" u"cd"; // 'ab😁cd'

vector<char> output(10);
size_t bytes_encoded = 0, start = 0;
Expand All @@ -116,32 +116,32 @@ TEST_CASE("EncodingConversion::encode - four-byte UTF-16 characters") {

TEST_CASE("EncodingConversion::encode - invalid characters in the middle of the string") {
auto conversion = transcoding_to("UTF-8");
u16string string = u"abc" "\xD800" "def";
u16string string = u"abc" u"\xD800" u"def";

vector<char> output(10);
size_t bytes_encoded = 0, start = 0;

bytes_encoded = conversion->encode(
string, &start, string.size(), output.data(), output.size());
REQUIRE(std::string(output.data(), bytes_encoded) == "abc" "\ufffd" "def");
REQUIRE(std::string(output.data(), bytes_encoded) == u8"abc" u8"\ufffd" u8"def");

// Here, the invalid character occurs at the end of a chunk.
start = 0;
bytes_encoded = conversion->encode(
string, &start, 4, output.data(), output.size());
bytes_encoded += conversion->encode(
string, &start, string.size(), output.data() + bytes_encoded, output.size() - bytes_encoded);
REQUIRE(std::string(output.data(), bytes_encoded) == "abc" "\ufffd" "def");
REQUIRE(std::string(output.data(), bytes_encoded) == u8"abc" u8"\ufffd" u8"def");
}

TEST_CASE("EncodingConversion::encode - invalid characters at the end of the string") {
auto conversion = transcoding_to("UTF-8");
u16string string = u"abc" "\xD800";
u16string string = u"abc" u"\xD800";

vector<char> output(10);
size_t bytes_encoded = 0, start = 0;

bytes_encoded = conversion->encode(
string, &start, string.size(), output.data(), output.size(), true);
REQUIRE(std::string(output.data(), bytes_encoded) == "abc" "\ufffd");
REQUIRE(std::string(output.data(), bytes_encoded) == u8"abc" u8"\ufffd");
}
1 change: 1 addition & 0 deletions test/native/test-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using std::cout;
using std::cerr;
using uint = unsigned int;

class TextBuffer;

Expand Down
7 changes: 4 additions & 3 deletions test/native/text-buffer-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "text-slice.h"
#include "regex.h"
#include <future>
#include <unistd.h>
#include <chrono>
#include <thread>

using std::move;
using std::pair;
Expand Down Expand Up @@ -466,7 +467,7 @@ TEST_CASE("TextBuffer::find_words_with_subsequence_in_range") {
}

TEST_CASE("TextBuffer::has_astral") {
REQUIRE(TextBuffer{u"ab" "\xd83d" "\xde01" "cd"}.has_astral());
REQUIRE(TextBuffer{u"ab" u"\xd83d" u"\xde01" u"cd"}.has_astral());
REQUIRE(!TextBuffer{u"abcd"}.has_astral());
}

Expand Down Expand Up @@ -535,7 +536,7 @@ TEST_CASE("TextBuffer - random edits and queries") {
Generator rand(seed);
vector<SnapshotData> results;
for (uint32_t k = 0; k < 5; k++) {
usleep(rand() % 1000);
std::this_thread::sleep_for(std::chrono::microseconds(rand() % 1000));
vector<Point> line_ending_positions;
for (uint32_t row = 0; row < snapshot->extent().row; row++) {
line_ending_positions.push_back({row, snapshot->line_length_for_row(row)});
Expand Down
Loading