|
| 1 | +@license{ |
| 2 | +Copyright (c) 2018-2025, NWO-I CWI, Swat.engineering and Paul Klint |
| 3 | +All rights reserved. |
| 4 | +
|
| 5 | +Redistribution and use in source and binary forms, with or without |
| 6 | +modification, are permitted provided that the following conditions are met: |
| 7 | +
|
| 8 | +1. Redistributions of source code must retain the above copyright notice, |
| 9 | +this list of conditions and the following disclaimer. |
| 10 | +
|
| 11 | +2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +this list of conditions and the following disclaimer in the documentation |
| 13 | +and/or other materials provided with the distribution. |
| 14 | +
|
| 15 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 | +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 | +POSSIBILITY OF SUCH DAMAGE. |
| 26 | +} |
| 27 | +module lang::rascalcore::check::tests::PackagerTests |
| 28 | + |
| 29 | +import lang::rascalcore::check::Checker; |
| 30 | +import lang::rascalcore::check::RascalConfig; |
| 31 | +import lang::rascalcore::package::Packager; |
| 32 | + |
| 33 | +import Location; |
| 34 | +import Map; |
| 35 | +import IO; |
| 36 | +import ValueIO; |
| 37 | +import Message; |
| 38 | + |
| 39 | +import util::FileSystem; |
| 40 | +import util::PathConfig; |
| 41 | + |
| 42 | +private void runChecker(PathConfig pcfg, list[str] mnames) { |
| 43 | + result = checkModules(mnames, rascalCompilerConfig(pcfg)); |
| 44 | + for (/e:error(_,_) := result) { |
| 45 | + println(e); |
| 46 | + } |
| 47 | +} |
| 48 | +
|
| 49 | +test bool packagerRewritesTModelsCorrectly () { |
| 50 | + println("**** Checking List"); |
| 51 | + tplRoot = |memory:///|; |
| 52 | + originalBin = tplRoot + "rascal-lib"; |
| 53 | + rewrittenBin = tplRoot + "rascal-lib-rewritten"; |
| 54 | + rascalLibPcfg = |
| 55 | + pathConfig(srcs = [|mvn://org.rascalmpl--rascal--0.41.0-RC15/|], |
| 56 | + bin = originalBin); |
| 57 | + runChecker(rascalLibPcfg, ["List"]); |
| 58 | + assert validateTModels(rascalLibPcfg.bin) : "Tpls before packager are not correct"; |
| 59 | + println("**** Running packager"); |
| 60 | + lang::rascalcore::package::Packager::main(pcfg = rascalLibPcfg, |
| 61 | + sourceLookup=rascalLibPcfg.srcs[0], |
| 62 | + relocatedClasses=rewrittenBin); |
| 63 | + assert validateTModels(rewrittenBin): "Tpls after packager are not correct"; |
| 64 | + return true; |
| 65 | +} |
| 66 | + |
| 67 | +bool validateTModels(loc bin){ |
| 68 | + println("**** Validating TModels in <bin>"); |
| 69 | + bool result = true; |
| 70 | + for (loc file <- find(bin, "tpl")) { |
| 71 | + result = result && isValidTModel(readBinaryValueFile(file)); |
| 72 | + } |
| 73 | + return result; |
| 74 | +} |
| 75 | + |
| 76 | +// Validity check on TModels focussing on the occurrence of logical/physical locations |
| 77 | +bool isValidTModel(TModel tm){ |
| 78 | + bool result = true; |
| 79 | + |
| 80 | + void report(str msg){ |
| 81 | + result = false; |
| 82 | + println(msg); |
| 83 | + } |
| 84 | + visit(tm.paths){ |
| 85 | + case loc l: if(!isModuleId(l)) report("Paths: Expected moduleId, found <l>"); |
| 86 | + } |
| 87 | + visit(domain(tm.logical2physical)){ |
| 88 | + case loc l: if(!isRascalLogicalLoc(l)) report("logical2physical: Expected logical loc, found <l>"); |
| 89 | + } |
| 90 | + visit(range(tm.logical2physical)){ |
| 91 | + case loc l: if(isRascalLogicalLoc(l)) report("logical2physical: Expected physical loc, found <l>"); |
| 92 | + } |
| 93 | + |
| 94 | + visit(range(tm.moduleLocs)){ |
| 95 | + case loc l: if(!isRascalLogicalLoc(l)) report("moduleLocs: Expected logical loc, found <l>"); |
| 96 | + } |
| 97 | + |
| 98 | + visit(tm.messages){ |
| 99 | + case loc l: if(isRascalLogicalLoc(l)) report("messages: Expected physical loc, found <l>"); |
| 100 | + } |
| 101 | + |
| 102 | + return result; |
| 103 | +} |
0 commit comments