Skip to content

Commit

Permalink
Run deno_std tests in github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Oct 9, 2019
1 parent 28293ac commit 93f7f00
Show file tree
Hide file tree
Showing 53 changed files with 675 additions and 884 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
cli/tests/error_syntax.js
std/deno.d.ts
std/prettier/vendor
std/**/testdata/
11 changes: 10 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
os: [macOS-10.14, windows-2016, ubuntu-16.04]
kind: ['test', 'bench', 'lint']
kind: ['test', 'test_std', 'bench', 'lint']
exclude:
- os: windows-2016
kind: 'bench'
Expand Down Expand Up @@ -102,6 +102,15 @@ jobs:
if: matrix.kind != 'lint'
run: cargo build --release --locked --all-targets

# TODO(ry) Remove this step, and move the following test to
# cli/tests/std_tests.rs
# TODO(ry) Remove the "cd std".
- name: std test
if: matrix.kind == 'test_std'
run: |
cd std
"../target/release/deno" test -A
- name: Test
if: matrix.kind == 'test'
run: cargo test --release --locked --all-targets
Expand Down
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
cli/tests/error_syntax.js
cli/tests/badly_formatted.js
cli/tests/badly_formatted.js
std/**/testdata
std/**/vendor
std/node_modules
25 changes: 25 additions & 0 deletions cli/tests/std_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// TODO(ry) Current std tests are run in .github/workflows/build.yml but ideally
// they would be called as part of "cargo test". "deno test" is too slow to do
// this desierable thing: https://github.com/denoland/deno/issues/3088
/*
#[macro_use]
extern crate lazy_static;
extern crate tempfile;
mod util;
use util::*;
#[test]
fn std_tests() {
let mut deno = deno_cmd()
.current_dir(root_path())
.arg("test")
.arg("-A")
.arg("std")
.spawn()
.expect("failed to spawn script");
let status = deno.wait().expect("failed to wait for the child process");
assert_eq!(Some(0), status.code());
assert!(status.success());
}
*/
14 changes: 6 additions & 8 deletions std/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Deno Standard Modules

[![Build Status](https://dev.azure.com/denoland/deno_std/_apis/build/status/denoland.deno_std?branchName=master)](https://dev.azure.com/denoland/deno_std/_build/latest?definitionId=2?branchName=master)

These modules do not have external dependencies and they are reviewed by the
Deno core team. The intention is to have a standard set of high quality code
that all Deno projects can use fearlessly.
Expand All @@ -11,8 +9,8 @@ Contributions are welcome!
## How to use

These modules are tagged in accordance with Deno releases. So, for example, the
v0.3.0 tag is guaranteed to work with deno v0.3.0.
You can link to v0.3.0 using the URL `https://deno.land/[email protected]/`
v0.3.0 tag is guaranteed to work with deno v0.3.0. You can link to v0.3.0 using
the URL `https://deno.land/[email protected]/`

It's strongly recommended that you link to tagged releases rather than the
master branch. The project is still young and we expect disruptive renames in
Expand Down Expand Up @@ -40,10 +38,10 @@ Here are the dedicated documentations of modules:
## Contributing

deno_std is a loose port of [Go's standard library](https://golang.org/pkg/).
When in doubt, simply port Go's source code, documentation, and tests. There
are many times when the nature of JavaScript, TypeScript, or Deno itself
justifies diverging from Go, but if possible we want to leverage the energy that
went into building Go. We generally welcome direct ports of Go's code.
When in doubt, simply port Go's source code, documentation, and tests. There are
many times when the nature of JavaScript, TypeScript, or Deno itself justifies
diverging from Go, but if possible we want to leverage the energy that went into
building Go. We generally welcome direct ports of Go's code.

Please ensure the copyright headers cite the code's origin.

Expand Down
64 changes: 35 additions & 29 deletions std/archive/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,26 +384,28 @@ export class Tar {
*/
getReader(): Deno.Reader {
const readers: Deno.Reader[] = [];
this.data.forEach((tarData): void => {
let { reader } = tarData;
const { filePath } = tarData;
const headerArr = formatHeader(tarData);
readers.push(new Deno.Buffer(headerArr));
if (!reader) {
reader = new FileReader(filePath!);
}
readers.push(reader);

// to the nearest multiple of recordSize
readers.push(
new Deno.Buffer(
clean(
recordSize -
(parseInt(tarData.fileSize!, 8) % recordSize || recordSize)
this.data.forEach(
(tarData): void => {
let { reader } = tarData;
const { filePath } = tarData;
const headerArr = formatHeader(tarData);
readers.push(new Deno.Buffer(headerArr));
if (!reader) {
reader = new FileReader(filePath!);
}
readers.push(reader);

// to the nearest multiple of recordSize
readers.push(
new Deno.Buffer(
clean(
recordSize -
(parseInt(tarData.fileSize!, 8) % recordSize || recordSize)
)
)
)
);
});
);
}
);

// append 2 empty records
readers.push(new Deno.Buffer(clean(recordSize * 2)));
Expand Down Expand Up @@ -460,18 +462,22 @@ export class Untar {
"mtime",
"uid",
"gid"
]).forEach((key): void => {
const arr = trim(header[key]);
if (arr.byteLength > 0) {
meta[key] = parseInt(decoder.decode(arr), 8);
]).forEach(
(key): void => {
const arr = trim(header[key]);
if (arr.byteLength > 0) {
meta[key] = parseInt(decoder.decode(arr), 8);
}
}
});
(["owner", "group"] as ["owner", "group"]).forEach((key): void => {
const arr = trim(header[key]);
if (arr.byteLength > 0) {
meta[key] = decoder.decode(arr);
);
(["owner", "group"] as ["owner", "group"]).forEach(
(key): void => {
const arr = trim(header[key]);
if (arr.byteLength > 0) {
meta[key] = decoder.decode(arr);
}
}
});
);

// read the file content
const len = parseInt(decoder.decode(header.fileSize), 8);
Expand Down
24 changes: 13 additions & 11 deletions std/bundle/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,20 @@ export function instantiate(
assert(module != null);
assert(module.factory != null);

const dependencies = module.dependencies.map((id): object => {
if (id === "require") {
// TODO(kitsonk) support dynamic import by passing a `require()` that
// can return a local module or dynamically import one.
return (): void => {};
} else if (id === "exports") {
return module.exports;
const dependencies = module.dependencies.map(
(id): object => {
if (id === "require") {
// TODO(kitsonk) support dynamic import by passing a `require()` that
// can return a local module or dynamically import one.
return (): void => {};
} else if (id === "exports") {
return module.exports;
}
const dep = modules.get(id)!;
assert(dep != null);
return dep.exports;
}
const dep = modules.get(id)!;
assert(dep != null);
return dep.exports;
});
);

if (typeof module.factory === "function") {
module.factory!(...dependencies);
Expand Down
6 changes: 4 additions & 2 deletions std/datetime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Simple helper to help parse date strings into `Date`, with additional functions.

### parseDate / parseDateTime

- `parseDate()` - Take an input string and a format to parse the date. Supported formats are exported in `DateFormat`.
- `parseDateTime()` - Take an input string and a format to parse the dateTime. Supported formats are exported in `DateTimeFormat`.
- `parseDate()` - Take an input string and a format to parse the date. Supported
formats are exported in `DateFormat`.
- `parseDateTime()` - Take an input string and a format to parse the dateTime.
Supported formats are exported in `DateTimeFormat`.

```ts
import { parseDate, parseDateTime } from 'https://deno.land/std/datetime/mod.ts'
Expand Down
30 changes: 16 additions & 14 deletions std/encoding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

- **`readAll(reader: BufReader, opt: ParseOptions = { comma: ",", trimLeadingSpace: false, lazyQuotes: false } ): Promise<[string[][], BufState]>`**:
Read the whole buffer and output the structured CSV datas
- **`parse(csvString: string, opt: ParseOption): Promise<unknown[]>`**:
See [parse](###Parse)
- **`parse(csvString: string, opt: ParseOption): Promise<unknown[]>`**: See
[parse](###Parse)

### Parse

Expand All @@ -17,18 +17,17 @@ Parse the CSV string with the options provided.

- **`header: boolean | string[] | HeaderOption[];`**: If a boolean is provided,
the first line will be used as Header definitions. If `string[]` or
`HeaderOption[]`
those names will be used for header definition.
`HeaderOption[]` those names will be used for header definition.
- **`parse?: (input: unknown) => unknown;`**: Parse function for the row, which
will be executed after parsing of all columns. Therefore if you don't provide
header and parse function with headers, input will be `string[]`.

##### HeaderOption

- **`name: string;`**: Name of the header to be used as property.
- **`parse?: (input: string) => unknown;`**: Parse function for the column.
This is executed on each entry of the header. This can be combined with the
Parse function of the rows.
- **`parse?: (input: string) => unknown;`**: Parse function for the column. This
is executed on each entry of the header. This can be combined with the Parse
function of the rows.

#### Usage

Expand Down Expand Up @@ -123,26 +122,29 @@ TypeScript side is a bit different.
- :heavy_check_mark: [Local Date](https://github.com/toml-lang/toml#local-date)
- :exclamation: [Local Time](https://github.com/toml-lang/toml#local-time)
- :heavy_check_mark: [Table](https://github.com/toml-lang/toml#table)
- :heavy_check_mark: [Inline Table](https://github.com/toml-lang/toml#inline-table)
- :exclamation: [Array of Tables](https://github.com/toml-lang/toml#array-of-tables)
- :heavy_check_mark:
[Inline Table](https://github.com/toml-lang/toml#inline-table)
- :exclamation:
[Array of Tables](https://github.com/toml-lang/toml#array-of-tables)

:exclamation: _Supported with warnings see [Warning](#Warning)._

#### :warning: Warning

##### String

- Regex : Due to the spec, there is no flag to detect regex properly
in a TOML declaration. So the regex is stored as string.
- Regex : Due to the spec, there is no flag to detect regex properly in a TOML
declaration. So the regex is stored as string.

##### Integer

For **Binary** / **Octal** / **Hexadecimal** numbers,
they are stored as string to be not interpreted as Decimal.
For **Binary** / **Octal** / **Hexadecimal** numbers, they are stored as string
to be not interpreted as Decimal.

##### Local Time

Because local time does not exist in JavaScript, the local time is stored as a string.
Because local time does not exist in JavaScript, the local time is stored as a
string.

##### Inline Table

Expand Down
66 changes: 35 additions & 31 deletions std/encoding/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,25 @@ async function read(
result = line.split(opt.comma!);

let quoteError = false;
result = result.map((r): string => {
if (opt.trimLeadingSpace) {
r = r.trimLeft();
}
if (r[0] === '"' && r[r.length - 1] === '"') {
r = r.substring(1, r.length - 1);
} else if (r[0] === '"') {
r = r.substring(1, r.length);
}
result = result.map(
(r): string => {
if (opt.trimLeadingSpace) {
r = r.trimLeft();
}
if (r[0] === '"' && r[r.length - 1] === '"') {
r = r.substring(1, r.length - 1);
} else if (r[0] === '"') {
r = r.substring(1, r.length);
}

if (!opt.lazyQuotes) {
if (r[0] !== '"' && r.indexOf('"') !== -1) {
quoteError = true;
if (!opt.lazyQuotes) {
if (r[0] !== '"' && r.indexOf('"') !== -1) {
quoteError = true;
}
}
return r;
}
return r;
});
);
if (quoteError) {
throw new ParseError(Startline, lineIndex, 'bare " in non-quoted-field');
}
Expand Down Expand Up @@ -224,25 +226,27 @@ export async function parse(
);
i++;
}
return r.map((e): unknown => {
if (e.length !== headers.length) {
throw `Error number of fields line:${i}`;
}
i++;
const out: Record<string, unknown> = {};
for (let j = 0; j < e.length; j++) {
const h = headers[j];
if (h.parse) {
out[h.name] = h.parse(e[j]);
} else {
out[h.name] = e[j];
return r.map(
(e): unknown => {
if (e.length !== headers.length) {
throw `Error number of fields line:${i}`;
}
i++;
const out: Record<string, unknown> = {};
for (let j = 0; j < e.length; j++) {
const h = headers[j];
if (h.parse) {
out[h.name] = h.parse(e[j]);
} else {
out[h.name] = e[j];
}
}
if (opt.parse) {
return opt.parse(out);
}
return out;
}
if (opt.parse) {
return opt.parse(out);
}
return out;
});
);
}
if (opt.parse) {
return r.map((e: string[]): unknown => opt.parse!(e));
Expand Down
Loading

0 comments on commit 93f7f00

Please sign in to comment.