/test/cli/shared/errors.dart

https://github.com/sass/dart-sass · Dart · 166 lines · 142 code · 20 blank · 4 comment · 0 complexity · 19222d43aaf198cac389b1c78e0550d3 MD5 · raw file

  1. // Copyright 2016 Google Inc. Use of this source code is governed by an
  2. // MIT-style license that can be found in the LICENSE file or at
  3. // https://opensource.org/licenses/MIT.
  4. import 'dart:async';
  5. import 'package:test/test.dart';
  6. import 'package:test_descriptor/test_descriptor.dart' as d;
  7. import 'package:test_process/test_process.dart';
  8. /// Defines test that are shared between the Dart and Node.js CLI test suites.
  9. void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
  10. test("from invalid arguments", () async {
  11. var sass = await runSass(["--asdf"]);
  12. expect(
  13. sass.stdout, emitsThrough(contains("Print this usage information.")));
  14. await sass.shouldExit(64);
  15. });
  16. test("from too many positional arguments", () async {
  17. var sass = await runSass(["abc", "def", "ghi"]);
  18. expect(
  19. sass.stdout, emitsThrough(contains("Print this usage information.")));
  20. await sass.shouldExit(64);
  21. });
  22. test("from too many positional arguments with --stdin", () async {
  23. var sass = await runSass(["--stdin", "abc", "def"]);
  24. expect(
  25. sass.stdout, emitsThrough(contains("Print this usage information.")));
  26. await sass.shouldExit(64);
  27. });
  28. test("from a file that doesn't exist", () async {
  29. var sass = await runSass(["asdf"]);
  30. expect(sass.stderr, emits(startsWith("Error reading asdf:")));
  31. expect(sass.stderr, emitsDone);
  32. await sass.shouldExit(66);
  33. });
  34. test("from invalid syntax", () async {
  35. await d.file("test.scss", "a {b: }").create();
  36. var sass = await runSass(["--no-unicode", "test.scss"]);
  37. expect(
  38. sass.stderr,
  39. emitsInOrder([
  40. "Error: Expected expression.",
  41. " ,",
  42. "1 | a {b: }",
  43. " | ^",
  44. " '",
  45. " test.scss 1:7 root stylesheet",
  46. ]));
  47. await sass.shouldExit(65);
  48. });
  49. test("from the runtime", () async {
  50. await d.file("test.scss", "a {b: 1px + 1deg}").create();
  51. var sass = await runSass(["--no-unicode", "test.scss"]);
  52. expect(
  53. sass.stderr,
  54. emitsInOrder([
  55. "Error: Incompatible units deg and px.",
  56. " ,",
  57. "1 | a {b: 1px + 1deg}",
  58. " | ^^^^^^^^^^",
  59. " '",
  60. " test.scss 1:7 root stylesheet",
  61. ]));
  62. await sass.shouldExit(65);
  63. });
  64. test("from an error encountered within a function", () async {
  65. await d.file("test.scss", """
  66. @function a() {
  67. @error "Within A.";
  68. }
  69. .b {
  70. c: a();
  71. }
  72. """).create();
  73. var sass = await runSass(["--no-unicode", "test.scss"]);
  74. expect(
  75. sass.stderr,
  76. emitsInOrder([
  77. "Error: \"Within A.\"",
  78. " ,",
  79. "6 | c: a();",
  80. " | ^^^",
  81. " '",
  82. " test.scss 6:6 root stylesheet",
  83. ]));
  84. await sass.shouldExit(65);
  85. });
  86. test("from an error encountered within a mixin", () async {
  87. await d.file("test.scss", """
  88. @mixin a() {
  89. @error "Within A.";
  90. }
  91. .b {
  92. @include a();
  93. }
  94. """).create();
  95. var sass = await runSass(["--no-unicode", "test.scss"]);
  96. expect(
  97. sass.stderr,
  98. emitsInOrder([
  99. "Error: \"Within A.\"",
  100. " ,",
  101. "6 | @include a();",
  102. " | ^^^^^^^^^^^^",
  103. " '",
  104. " test.scss 6:3 root stylesheet",
  105. ]));
  106. await sass.shouldExit(65);
  107. });
  108. test("with colors with --color", () async {
  109. await d.file("test.scss", "a {b: }").create();
  110. var sass = await runSass(["--no-unicode", "--color", "test.scss"]);
  111. expect(
  112. sass.stderr,
  113. emitsInOrder([
  114. "Error: Expected expression.",
  115. "\u001b[34m ,\u001b[0m",
  116. "\u001b[34m1 |\u001b[0m a {b: \u001b[31m\u001b[0m}",
  117. "\u001b[34m |\u001b[0m \u001b[31m ^\u001b[0m",
  118. "\u001b[34m '\u001b[0m",
  119. " test.scss 1:7 root stylesheet",
  120. ]));
  121. await sass.shouldExit(65);
  122. });
  123. test("with Unicode by default", () async {
  124. await d.file("test.scss", "a {b: }").create();
  125. var sass = await runSass(["test.scss"]);
  126. expect(
  127. sass.stderr,
  128. emitsInOrder([
  129. "Error: Expected expression.",
  130. " ╷",
  131. "1 │ a {b: }",
  132. " │ ^",
  133. " ╵",
  134. " test.scss 1:7 root stylesheet",
  135. ]));
  136. await sass.shouldExit(65);
  137. });
  138. test("with full stack traces with --trace", () async {
  139. await d.file("test.scss", "a {b: }").create();
  140. var sass = await runSass(["--trace", "test.scss"]);
  141. expect(sass.stderr, emitsThrough(contains("\.dart")));
  142. await sass.shouldExit(65);
  143. });
  144. }