2018-05-31 00:35:35 +02:00
|
|
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'package:test_descriptor/test_descriptor.dart' as d;
|
|
|
|
import 'package:test_process/test_process.dart';
|
|
|
|
|
|
|
|
/// Defines test that are shared between the Dart and Node.js CLI test suites.
|
|
|
|
void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
|
|
|
|
test("from invalid arguments", () async {
|
|
|
|
var sass = await runSass(["--asdf"]);
|
|
|
|
expect(
|
|
|
|
sass.stdout, emitsThrough(contains("Print this usage information.")));
|
|
|
|
await sass.shouldExit(64);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("from too many positional arguments", () async {
|
|
|
|
var sass = await runSass(["abc", "def", "ghi"]);
|
|
|
|
expect(
|
|
|
|
sass.stdout, emitsThrough(contains("Print this usage information.")));
|
|
|
|
await sass.shouldExit(64);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("from too many positional arguments with --stdin", () async {
|
|
|
|
var sass = await runSass(["--stdin", "abc", "def"]);
|
|
|
|
expect(
|
|
|
|
sass.stdout, emitsThrough(contains("Print this usage information.")));
|
|
|
|
await sass.shouldExit(64);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("from a file that doesn't exist", () async {
|
|
|
|
var sass = await runSass(["asdf"]);
|
|
|
|
expect(sass.stderr, emits(startsWith("Error reading asdf:")));
|
|
|
|
expect(sass.stderr, emitsDone);
|
|
|
|
await sass.shouldExit(66);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("from invalid syntax", () async {
|
|
|
|
await d.file("test.scss", "a {b: }").create();
|
|
|
|
|
2019-01-29 02:42:32 +01:00
|
|
|
var sass = await runSass(["--no-unicode", "test.scss"]);
|
2018-05-31 00:35:35 +02:00
|
|
|
expect(
|
|
|
|
sass.stderr,
|
|
|
|
emitsInOrder([
|
|
|
|
"Error: Expected expression.",
|
2019-01-29 02:42:32 +01:00
|
|
|
" ,",
|
|
|
|
"1 | a {b: }",
|
|
|
|
" | ^",
|
|
|
|
" '",
|
2018-05-31 00:35:35 +02:00
|
|
|
" test.scss 1:7 root stylesheet",
|
|
|
|
]));
|
|
|
|
await sass.shouldExit(65);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("from the runtime", () async {
|
|
|
|
await d.file("test.scss", "a {b: 1px + 1deg}").create();
|
|
|
|
|
2019-01-29 02:42:32 +01:00
|
|
|
var sass = await runSass(["--no-unicode", "test.scss"]);
|
2018-05-31 00:35:35 +02:00
|
|
|
expect(
|
|
|
|
sass.stderr,
|
|
|
|
emitsInOrder([
|
2020-12-29 05:38:46 +01:00
|
|
|
"Error: 1px and 1deg have incompatible units.",
|
2019-01-29 02:42:32 +01:00
|
|
|
" ,",
|
|
|
|
"1 | a {b: 1px + 1deg}",
|
|
|
|
" | ^^^^^^^^^^",
|
|
|
|
" '",
|
2018-05-31 00:35:35 +02:00
|
|
|
" test.scss 1:7 root stylesheet",
|
|
|
|
]));
|
|
|
|
await sass.shouldExit(65);
|
|
|
|
});
|
|
|
|
|
2019-11-14 02:56:35 +01:00
|
|
|
test("from an error encountered within a function", () async {
|
|
|
|
await d.file("test.scss", """
|
|
|
|
@function a() {
|
|
|
|
@error "Within A.";
|
|
|
|
}
|
|
|
|
|
|
|
|
.b {
|
|
|
|
c: a();
|
|
|
|
}
|
|
|
|
""").create();
|
|
|
|
|
|
|
|
var sass = await runSass(["--no-unicode", "test.scss"]);
|
|
|
|
expect(
|
|
|
|
sass.stderr,
|
|
|
|
emitsInOrder([
|
|
|
|
"Error: \"Within A.\"",
|
|
|
|
" ,",
|
|
|
|
"6 | c: a();",
|
|
|
|
" | ^^^",
|
|
|
|
" '",
|
|
|
|
" test.scss 6:6 root stylesheet",
|
|
|
|
]));
|
|
|
|
await sass.shouldExit(65);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("from an error encountered within a mixin", () async {
|
|
|
|
await d.file("test.scss", """
|
|
|
|
@mixin a() {
|
|
|
|
@error "Within A.";
|
|
|
|
}
|
|
|
|
|
|
|
|
.b {
|
|
|
|
@include a();
|
|
|
|
}
|
|
|
|
""").create();
|
|
|
|
|
|
|
|
var sass = await runSass(["--no-unicode", "test.scss"]);
|
|
|
|
expect(
|
|
|
|
sass.stderr,
|
|
|
|
emitsInOrder([
|
|
|
|
"Error: \"Within A.\"",
|
|
|
|
" ,",
|
|
|
|
"6 | @include a();",
|
|
|
|
" | ^^^^^^^^^^^^",
|
|
|
|
" '",
|
|
|
|
" test.scss 6:3 root stylesheet",
|
|
|
|
]));
|
|
|
|
await sass.shouldExit(65);
|
|
|
|
});
|
|
|
|
|
2018-05-31 00:35:35 +02:00
|
|
|
test("with colors with --color", () async {
|
|
|
|
await d.file("test.scss", "a {b: }").create();
|
|
|
|
|
2019-01-29 02:42:32 +01:00
|
|
|
var sass = await runSass(["--no-unicode", "--color", "test.scss"]);
|
2018-05-31 00:35:35 +02:00
|
|
|
expect(
|
|
|
|
sass.stderr,
|
|
|
|
emitsInOrder([
|
|
|
|
"Error: Expected expression.",
|
2019-01-29 02:42:32 +01:00
|
|
|
"\u001b[34m ,\u001b[0m",
|
|
|
|
"\u001b[34m1 |\u001b[0m a {b: \u001b[31m\u001b[0m}",
|
2020-01-15 01:54:23 +01:00
|
|
|
"\u001b[34m |\u001b[0m \u001b[31m ^\u001b[0m",
|
2019-01-29 02:42:32 +01:00
|
|
|
"\u001b[34m '\u001b[0m",
|
|
|
|
" test.scss 1:7 root stylesheet",
|
|
|
|
]));
|
|
|
|
await sass.shouldExit(65);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("with Unicode by default", () async {
|
|
|
|
await d.file("test.scss", "a {b: }").create();
|
|
|
|
|
|
|
|
var sass = await runSass(["test.scss"]);
|
|
|
|
expect(
|
|
|
|
sass.stderr,
|
|
|
|
emitsInOrder([
|
|
|
|
"Error: Expected expression.",
|
|
|
|
" ╷",
|
|
|
|
"1 │ a {b: }",
|
|
|
|
" │ ^",
|
|
|
|
" ╵",
|
2018-05-31 00:35:35 +02:00
|
|
|
" test.scss 1:7 root stylesheet",
|
|
|
|
]));
|
|
|
|
await sass.shouldExit(65);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("with full stack traces with --trace", () async {
|
|
|
|
await d.file("test.scss", "a {b: }").create();
|
|
|
|
|
|
|
|
var sass = await runSass(["--trace", "test.scss"]);
|
2021-10-05 05:53:31 +02:00
|
|
|
expect(sass.stderr, emitsThrough(contains(".dart")));
|
2018-05-31 00:35:35 +02:00
|
|
|
await sass.shouldExit(65);
|
|
|
|
});
|
|
|
|
}
|