Skip to content

Commit

Permalink
Improve error messages in Elm Interactive tests
Browse files Browse the repository at this point in the history
+ Print the submission for the failed step.
+ Remove duplicate names from the report of available names.
  • Loading branch information
Viir committed Nov 6, 2020
1 parent 0adfc10 commit e3a483d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Pine exposing (..)

import BigInt
import Result.Extra
import Set


type PineExpression
Expand Down Expand Up @@ -132,12 +133,17 @@ lookUpNameInContext name context =

nameFirstElement :: nameRemainingElements ->
let
availableNames =
availableNamedValues =
context.commonModel
|> List.filterMap pineNamedValueFromValue

availableNames =
availableNamedValues
|> List.map Tuple.first
|> Set.fromList

maybeMatchingValue =
availableNames
availableNamedValues
|> List.filter (Tuple.first >> (==) nameFirstElement)
|> List.head
|> Maybe.map Tuple.second
Expand All @@ -148,9 +154,9 @@ lookUpNameInContext name context =
("Did not find '"
++ nameFirstElement
++ "'. "
++ (availableNames |> List.length |> String.fromInt)
++ (availableNames |> Set.size |> String.fromInt)
++ " names available: "
++ (availableNames |> List.map Tuple.first |> String.join ", ")
++ (availableNames |> Set.toList |> String.join ", ")
)

Just firstNameValue ->
Expand Down
10 changes: 7 additions & 3 deletions implement/test-elm-fullstack/TestElmInteractive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public void TestElmInteractiveScenarios()
{
var stepName = Path.GetFileName(stepDirectory);

string submission = null;

try
{
var submission =
submission =
File.ReadAllText(Path.Combine(stepDirectory, "submission"), System.Text.Encoding.UTF8);

var evalResult =
Expand All @@ -74,15 +76,17 @@ public void TestElmInteractiveScenarios()
{
var expectedValue = File.ReadAllText(expectedValueFilePath, System.Text.Encoding.UTF8);

Assert.IsNull(evalResult.Err, "Submission result has error: " + evalResult.Err);

Assert.AreEqual(
expectedValue,
evalResult.Ok?.valueAsElmExpressionText,
"Value from evaluation matches expected value in scenario '" + scenarioName + "'");
"Value from evaluation does not match expected value.");
}
}
catch (Exception e)
{
throw new Exception("Failed step '" + stepName + "' with exception.", e);
throw new Exception("Failed step '" + stepName + "' with exception.\nSubmission in this step:\n" + submission, e);
}
}
}
Expand Down

0 comments on commit e3a483d

Please sign in to comment.