Skip to content

Commit

Permalink
Test that generated $$imports value has the right contents
Browse files Browse the repository at this point in the history
  • Loading branch information
akrmn committed Sep 28, 2021
1 parent c7d63dd commit 2ba0017
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Copyright (c) 2021, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

module ModuleImports_Datatype (T (..)) where

data T = T
9 changes: 9 additions & 0 deletions compiler/damlc/tests/daml-test-files/ModuleImports_Main.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Copyright (c) 2021, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

-- This test checks that we produce an $$imports value including all modules from which this one imports instances.
-- @QUERY-LF .modules[] | select(lf::get_dotted_name($pkg) == ["ModuleImports_Main"]) | .values[].name_with_type | select(lf::get_value_name($pkg) == ["$$$$imports"]) | lf::norm_imports($pkg) | any(. == {package: null, module: ["ModuleImports_OrphanInstance"]})

module ModuleImports_Main () where

import ModuleImports_OrphanInstance ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Copyright (c) 2021, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

{-# OPTIONS_GHC -Wno-orphans #-}

module ModuleImports_OrphanInstance (T (..)) where

import ModuleImports_Datatype (T (..))

instance Show T where
show T = "T"
21 changes: 21 additions & 0 deletions compiler/damlc/tests/src/query-lf-interned.jq
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,24 @@ def get_name(pkg): .name_interned_str | resolve_interned_string(pkg);
def get_text(pkg): .text_interned_str | resolve_interned_string(pkg);

def norm_ty(pkg): if has("interned") then pkg.interned_types[.interned] else . end;

def norm_imports(pkg):
.type | norm_ty(pkg) |
.struct.fields |
map(
.type | norm_ty(pkg) |
.struct.fields |
map(.type | norm_ty(pkg)) |
{ "package":
.[0] |
(try (.struct.fields[0] | get_field(pkg)) catch null)
, "module":
.[1] |
.struct.fields |
map (
.type | norm_ty(pkg) |
.struct.fields[] |
get_field(pkg)
)
}
);

0 comments on commit 2ba0017

Please sign in to comment.