Prexonite, a .NET hosted scripting language with a focus on meta-programming and embedded DSLs
0

Configure Feed

Select the types of activity you want to include in your feed.

Upgrade NUnit

Christian Klauser (Jun 23, 2018, 12:38 PM +0200) b1c26520 6a3ccd60

+5137 -5099
+6
Prexonite.sln.DotSettings
··· 5 5 <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue">False</s:Boolean> 6 6 <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXPRESSION/@EntryValue">False</s:Boolean> 7 7 <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">False</s:Boolean> 8 + <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String> 8 9 9 10 <s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">$SOLUTION$&#xD; 10 11 &#xD; ··· 35 36 <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String> 36 37 <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=3d1afed0_002D8eeb_002D476b_002Db81f_002D68998a8855fe/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Private members"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;Kind Name="METHOD" /&gt;&lt;Kind Name="PROPERTY" /&gt;&lt;Kind Name="EVENT" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String> 37 38 <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0ea5b45_002Df3e8_002D489b_002Da1bf_002D6fe14030968c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Internal" Description="Internal methods and properties"&gt;&lt;ElementKinds&gt;&lt;Kind Name="METHOD" /&gt;&lt;Kind Name="PROPERTY" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String> 39 + <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean> 40 + <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean> 41 + <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean> 42 + <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean> 38 43 <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean> 44 + <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean> 39 45 <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean> 40 46 <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean> 41 47 <s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
+2 -2
Prexonite/Compiler/Lexer.cs
··· 1 - /* The following code was generated by CSFlex 1.4 on 27.05.2017 */ 1 + /* The following code was generated by CSFlex 1.4 on 16.04.2018 */ 2 2 3 3 #line 1 "Prexonite.lex" 4 4 /* ··· 41 41 /** 42 42 * This class is a scanner generated by <a href="http://www.sourceforge.net/projects/csflex/">C# Flex</a>, based on 43 43 * <a href="http://www.jflex.de/">JFlex</a>, version 1.4 44 - * on 27.05.2017 from the specification file 44 + * on 16.04.2018 from the specification file 45 45 * <tt>Prexonite.lex</tt> 46 46 */ 47 47 class Lexer: Prexonite.Internal.IScanner {
+16 -3
Prexonite/Prexonite.csproj
··· 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0"> 3 + <Import Project="..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props')" /> 3 4 <PropertyGroup> 4 5 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 5 6 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> ··· 20 21 <UpgradeBackupLocation> 21 22 </UpgradeBackupLocation> 22 23 <IsWebBootstrapper>false</IsWebBootstrapper> 23 - <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> 24 + <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> 24 25 <TargetFrameworkProfile> 25 26 </TargetFrameworkProfile> 26 27 <PublishUrl>publish\</PublishUrl> ··· 37 38 <ApplicationVersion>1.0.0.%2a</ApplicationVersion> 38 39 <UseApplicationTrust>false</UseApplicationTrust> 39 40 <BootstrapperEnabled>true</BootstrapperEnabled> 40 - <LangVersion>7</LangVersion> 41 + <LangVersion>7.2</LangVersion> 41 42 </PropertyGroup> 42 43 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 43 44 <DebugSymbols>true</DebugSymbols> ··· 94 95 <Prefer32Bit>false</Prefer32Bit> 95 96 </PropertyGroup> 96 97 <ItemGroup> 98 + <Reference Include="mscorlib" /> 97 99 <Reference Include="System" /> 98 100 <Reference Include="System.Core"> 99 101 <RequiredTargetFramework>3.5</RequiredTargetFramework> 100 102 </Reference> 103 + <Reference Include="System.Threading.Tasks.Extensions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"> 104 + <HintPath>..\packages\System.Threading.Tasks.Extensions.4.4.0\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath> 105 + <Private>True</Private> 106 + </Reference> 101 107 <Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"> 102 - <HintPath>..\packages\System.ValueTuple.4.4.0-preview1-25305-02\lib\net461\System.ValueTuple.dll</HintPath> 108 + <HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath> 109 + <Private>True</Private> 103 110 </Reference> 104 111 </ItemGroup> 105 112 <ItemGroup> ··· 648 655 </Target> 649 656 <Target Name="PrexoniteScanner"> 650 657 <Exec Command="&quot;$(ToolsDirectory)\csflex.exe&quot; --csharp --nested-default-skeleton --nobak $(PrexoniteScannerDefinition)" WorkingDirectory="$(ProjectDir)\Compiler" /> 658 + </Target> 659 + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> 660 + <PropertyGroup> 661 + <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText> 662 + </PropertyGroup> 663 + <Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props'))" /> 651 664 </Target> 652 665 </Project>
+1 -1
Prexonite/Prexonite.csproj.DotSettings
··· 1 1 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> 2 - <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String> 2 + 3 3 <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Helper/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
+3 -1
Prexonite/packages.config
··· 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <packages> 3 - <package id="System.ValueTuple" version="4.4.0-preview1-25305-02" targetFramework="net461" /> 3 + <package id="Microsoft.Net.Compilers" version="2.7.0" targetFramework="net462" developmentDependency="true" /> 4 + <package id="System.Threading.Tasks.Extensions" version="4.4.0" targetFramework="net462" /> 5 + <package id="System.ValueTuple" version="4.4.0" targetFramework="net461" /> 4 6 </packages>
+20 -12
Prexonite/prxlib/sh.pxs
··· 1 - // Runtime component of the Prexonite shell scripting extensions 2 - Name sh/0.0; 3 - References { 4 - sys/0.0 5 - }; 6 - 7 - namespace sh { 8 - 9 - function stdout = "sh.stdout"; 10 - function stdin = "sh.stdin"; 11 - function stderr = "sh.stderr"; 12 - } export(stdout, stdin, stderr, (|>), (<|.), (|>.), stream, lines, which, create_command, call\sh); 1 + // Runtime component of the Prexonite shell scripting extensions 2 + Name sh/0.0; 3 + References { 4 + sys/0.0 5 + }; 6 + 7 + namespace sh { 8 + 9 + function stdout = "sh.stdout"; 10 + function stdin = "sh.stdin"; 11 + function stderr = "sh.stderr"; 12 + } export(stdout, stdin, stderr, stream, lines, words, which, create_command, call\sh, (|>), (<|.), (|>.)); 13 + 14 + { 15 + var time = new command(which("time")); 16 + var grep = new command(which("grep")); 17 + var tr = new command(which("tr")); 18 + var cut = new command(which("cut")); 19 + } 20 +
+121 -152
PrexoniteTests/Meta.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using NUnit.Framework.Constraints; 28 - using Prexonite; 29 - 30 - namespace PrexoniteTests 31 - { 32 - public static class Meta 33 - { 34 - public static Constraint ContainsKey(string key) 35 - { 36 - return new ContainsKeyConstraint(key); 37 - } 38 - 39 - public static Constraint Contains(string key, MetaEntry value) 40 - { 41 - return new ExactEqualityConstraint(key, value); 42 - } 43 - 44 - public static Constraint ContainsExact(string key, MetaEntry value) 45 - { 46 - return 47 - new ContainsKeyConstraint(key).And.Matches(new ExactEqualityConstraint(key, value)); 48 - } 49 - 50 - private class ExactEqualityConstraint : Constraint 51 - { 52 - private readonly string _key; 53 - private readonly MetaEntry _expectedEntry; 54 - private MetaEntry _actualEntry; 55 - private bool _typeMismatch; 56 - 57 - public ExactEqualityConstraint(string key, MetaEntry expectedEntry) 58 - { 59 - if (key == null) 60 - throw new ArgumentNullException(nameof(key)); 61 - if (expectedEntry == null) 62 - throw new ArgumentNullException(nameof(expectedEntry)); 63 - 64 - _key = key; 65 - _expectedEntry = expectedEntry; 66 - } 67 - 68 - #region Overrides of Constraint 69 - 70 - public override bool Matches(object actual) 71 - { 72 - this.actual = actual; 73 - 74 - var ihmt = actual as IHasMetaTable; 75 - if (ihmt == null) 76 - { 77 - this.actual = null; 78 - return false; 79 - } 80 - 81 - _actualEntry = ihmt.Meta[_key]; 82 - 83 - if (_actualEntry.EntryType != _expectedEntry.EntryType) 84 - { 85 - _typeMismatch = true; 86 - return false; 87 - } 88 - 89 - _typeMismatch = false; 90 - return _actualEntry.Equals(_expectedEntry); 91 - } 92 - 93 - public override void WriteDescriptionTo(MessageWriter writer) 94 - { 95 - if (actual == null) 96 - { 97 - writer.WriteMessageLine("Actual value does not have a meta table."); 98 - } 99 - else if (_typeMismatch) 100 - { 101 - writer.WriteMessageLine("Meta entry type doesn't match."); 102 - writer.WriteExpectedValue(_expectedEntry.EntryType); 103 - writer.WriteActualValue(_actualEntry.EntryType); 104 - } 105 - else 106 - { 107 - writer.WriteMessageLine( 108 - "actual meta entry {0} should match expected entry {1}", _actualEntry, 109 - _expectedEntry); 110 - } 111 - } 112 - 113 - #endregion 114 - } 115 - 116 - private class ContainsKeyConstraint : Constraint 117 - { 118 - private readonly string _key; 119 - 120 - public ContainsKeyConstraint(string key) 121 - { 122 - if (key == null) 123 - throw new ArgumentNullException(nameof(key)); 124 - _key = key; 125 - } 126 - 127 - #region Overrides of Constraint 128 - 129 - public override bool Matches(object actual) 130 - { 131 - this.actual = actual; 132 - 133 - IHasMetaTable ihmt; 134 - MetaTable mt; 135 - if ((ihmt = actual as IHasMetaTable) != null) 136 - mt = ihmt.Meta; 137 - else 138 - return false; 139 - 140 - return mt.ContainsKey(_key); 141 - } 142 - 143 - public 144 - override void WriteDescriptionTo(MessageWriter writer) 145 - { 146 - writer.WriteMessageLine( 147 - "meta table of object {0} should contain an entry for key \"{1}\"", actual, _key); 148 - } 149 - 150 - #endregion 151 - } 152 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using NUnit.Framework.Constraints; 28 + using Prexonite; 29 + 30 + namespace PrexoniteTests 31 + { 32 + public static class Meta 33 + { 34 + public static Constraint ContainsKey(string key) 35 + { 36 + return new ContainsKeyConstraint(key); 37 + } 38 + 39 + public static Constraint Contains(string key, MetaEntry value) 40 + { 41 + return new ExactEqualityConstraint(key, value); 42 + } 43 + 44 + public static Constraint ContainsExact(string key, MetaEntry value) 45 + { 46 + return 47 + new ContainsKeyConstraint(key).And.Matches(new ExactEqualityConstraint(key, value)); 48 + } 49 + 50 + private class ExactEqualityConstraint : Constraint 51 + { 52 + private readonly string _key; 53 + private readonly MetaEntry _expectedEntry; 54 + 55 + public ExactEqualityConstraint(string key, MetaEntry expectedEntry) : base(key, expectedEntry) 56 + { 57 + if (expectedEntry == null) 58 + throw new ArgumentNullException(nameof(expectedEntry)); 59 + 60 + _key = key ?? throw new ArgumentNullException(nameof(key)); 61 + _expectedEntry = expectedEntry; 62 + } 63 + 64 + #region Overrides of Constraint 65 + 66 + public override ConstraintResult ApplyTo<TActual>(TActual actual) 67 + { 68 + object actualObj = actual; 69 + return new ConstraintResult(this, actualObj, _matches(actualObj)); 70 + } 71 + 72 + private bool _matches(object actual) 73 + { 74 + var ihmt = actual as IHasMetaTable; 75 + if (ihmt == null) 76 + { 77 + return false; 78 + } 79 + 80 + var actualEntry = ihmt.Meta[_key]; 81 + 82 + return actualEntry.EntryType == _expectedEntry.EntryType && actualEntry.Equals(_expectedEntry); 83 + } 84 + 85 + #endregion 86 + } 87 + 88 + private class ContainsKeyConstraint : Constraint 89 + { 90 + private readonly string _key; 91 + 92 + public ContainsKeyConstraint(string key) : base(key) 93 + { 94 + if (key == null) 95 + throw new ArgumentNullException(nameof(key)); 96 + _key = key; 97 + } 98 + 99 + #region Overrides of Constraint 100 + 101 + public override ConstraintResult ApplyTo<TActual>(TActual actual) 102 + { 103 + var actualValue = actual; 104 + return new ConstraintResult(this, actualValue, _matches(actualValue)); 105 + } 106 + 107 + private bool _matches(object actual) 108 + { 109 + IHasMetaTable ihmt; 110 + MetaTable mt; 111 + if ((ihmt = actual as IHasMetaTable) != null) 112 + mt = ihmt.Meta; 113 + else 114 + return false; 115 + 116 + return mt.ContainsKey(_key); 117 + } 118 + 119 + #endregion 120 + } 121 + } 153 122 }
+245 -220
PrexoniteTests/PrexoniteTests.csproj
··· 1 - <?xml version="1.0" encoding="utf-8"?> 2 - <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0"> 3 - <PropertyGroup> 4 - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 5 - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 6 - <ProductVersion>9.0.21022</ProductVersion> 7 - <SchemaVersion>2.0</SchemaVersion> 8 - <ProjectGuid>{9491D2F5-6758-44CF-9CB9-9F488145F9A3}</ProjectGuid> 9 - <OutputType>Exe</OutputType> 10 - <AppDesignerFolder>Properties</AppDesignerFolder> 11 - <RootNamespace>PrexoniteTests</RootNamespace> 12 - <AssemblyName>PrexoniteTests</AssemblyName> 13 - <FileUpgradeFlags> 14 - </FileUpgradeFlags> 15 - <OldToolsVersion>3.5</OldToolsVersion> 16 - <UpgradeBackupLocation> 17 - </UpgradeBackupLocation> 18 - <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> 19 - <TargetFrameworkProfile> 20 - </TargetFrameworkProfile> 21 - <PublishUrl>publish\</PublishUrl> 22 - <Install>true</Install> 23 - <InstallFrom>Disk</InstallFrom> 24 - <UpdateEnabled>false</UpdateEnabled> 25 - <UpdateMode>Foreground</UpdateMode> 26 - <UpdateInterval>7</UpdateInterval> 27 - <UpdateIntervalUnits>Days</UpdateIntervalUnits> 28 - <UpdatePeriodically>false</UpdatePeriodically> 29 - <UpdateRequired>false</UpdateRequired> 30 - <MapFileExtensions>true</MapFileExtensions> 31 - <ApplicationRevision>0</ApplicationRevision> 32 - <ApplicationVersion>1.0.0.%2a</ApplicationVersion> 33 - <IsWebBootstrapper>false</IsWebBootstrapper> 34 - <UseApplicationTrust>false</UseApplicationTrust> 35 - <BootstrapperEnabled>true</BootstrapperEnabled> 36 - <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> 37 - <RestorePackages>true</RestorePackages> 38 - </PropertyGroup> 39 - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 40 - <DebugSymbols>true</DebugSymbols> 41 - <DebugType>full</DebugType> 42 - <Optimize>false</Optimize> 43 - <OutputPath>bin\Debug\</OutputPath> 44 - <DefineConstants>TRACE;DEBUG;allowIndex,forceIndex</DefineConstants> 45 - <ErrorReport>prompt</ErrorReport> 46 - <WarningLevel>4</WarningLevel> 47 - <Prefer32Bit>false</Prefer32Bit> 48 - </PropertyGroup> 49 - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 50 - <DebugType>pdbonly</DebugType> 51 - <Optimize>true</Optimize> 52 - <OutputPath>bin\Release\</OutputPath> 53 - <DefineConstants>TRACE</DefineConstants> 54 - <ErrorReport>prompt</ErrorReport> 55 - <WarningLevel>4</WarningLevel> 56 - <Prefer32Bit>false</Prefer32Bit> 57 - </PropertyGroup> 58 - <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 59 - <DebugSymbols>true</DebugSymbols> 60 - <OutputPath>bin\x86\Debug\</OutputPath> 61 - <DefineConstants>TRACE;DEBUG;allowIndex,forceIndex</DefineConstants> 62 - <DebugType>full</DebugType> 63 - <PlatformTarget>x86</PlatformTarget> 64 - <CodeAnalysisLogFile>bin\Debug\PrexoniteTests.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> 65 - <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> 66 - <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> 67 - <ErrorReport>prompt</ErrorReport> 68 - <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 69 - <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> 70 - <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> 71 - <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> 72 - <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> 73 - <Prefer32Bit>false</Prefer32Bit> 74 - </PropertyGroup> 75 - <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 76 - <OutputPath>bin\x86\Release\</OutputPath> 77 - <DefineConstants>TRACE</DefineConstants> 78 - <Optimize>true</Optimize> 79 - <DebugType>pdbonly</DebugType> 80 - <PlatformTarget>x86</PlatformTarget> 81 - <CodeAnalysisLogFile>bin\Release\PrexoniteTests.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> 82 - <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> 83 - <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> 84 - <ErrorReport>prompt</ErrorReport> 85 - <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 86 - <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> 87 - <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> 88 - <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> 89 - <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> 90 - <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules> 91 - <Prefer32Bit>false</Prefer32Bit> 92 - </PropertyGroup> 93 - <PropertyGroup> 94 - <SignAssembly>true</SignAssembly> 95 - </PropertyGroup> 96 - <PropertyGroup> 97 - <AssemblyOriginatorKeyFile>Prexonite.snk</AssemblyOriginatorKeyFile> 98 - </PropertyGroup> 99 - <ItemGroup> 100 - <Reference Include="Microsoft.CSharp" /> 101 - <Reference Include="Moq"> 102 - <HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath> 103 - </Reference> 104 - <Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> 105 - <SpecificVersion>False</SpecificVersion> 106 - <HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath> 107 - </Reference> 108 - <Reference Include="System" /> 109 - </ItemGroup> 110 - <ItemGroup> 111 - <Compile Include="Meta.cs" /> 112 - <Compile Include="Program.cs" /> 113 - <Compile Include="Properties\AssemblyInfo.cs" /> 114 - <Compile Include="Tests\ApplicationLinking.cs" /> 115 - <Compile Include="Tests\AstTests.cs" /> 116 - <Compile Include="Tests\CilCompilerTests.cs" /> 117 - <Compile Include="Tests\CilRuntime.cs" /> 118 - <Compile Include="Tests\Compiler.cs" /> 119 - <Compile Include="Tests\Compiler.Global.cs" /> 120 - <Compile Include="Tests\Compiler.Parser.cs" /> 121 - <Compile Include="Tests\Configurations\ModuleCache.cs" /> 122 - <Compile Include="Tests\Configurations\PsrUnitTests.cs"> 123 - <AutoGen>True</AutoGen> 124 - <DesignTime>True</DesignTime> 125 - <DependentUpon>PsrUnitTests.tt</DependentUpon> 126 - </Compile> 127 - <Compile Include="Tests\Configurations\TestModel.cs" /> 128 - <Compile Include="Tests\Configurations\UnitTestConfiguration.cs" /> 129 - <Content Include="psr-tests\testconfig.txt" /> 130 - <Compile Include="Tests\Configurations\ScriptedUnitTestContainer.cs" /> 131 - <Compile Include="Tests\Configurations\VMTestConfigurations.cs"> 132 - <AutoGen>True</AutoGen> 133 - <DesignTime>True</DesignTime> 134 - <DependentUpon>VMTestConfigurations.tt</DependentUpon> 135 - </Compile> 136 - <Compile Include="Tests\Internal\DependingOnConstraint.cs" /> 137 - <Compile Include="Tests\MemberCallable.cs" /> 138 - <Compile Include="Tests\MExprTests.cs" /> 139 - <Compile Include="Tests\NamespaceInfrastructureTests.cs" /> 140 - <Compile Include="Tests\SelfAssemblingPlanTests.cs" /> 141 - <Compile Include="Tests\ShellExtensions.cs" /> 142 - <Compile Include="Tests\Translation.cs" /> 143 - <Compile Include="Tests\VMTests.Macro.cs" /> 144 - <Compile Include="Tests\VMTests.Exception.cs" /> 145 - <Compile Include="Tests\VMTests.Commands.cs" /> 146 - <Compile Include="Tests\Lazy.cs" /> 147 - <Compile Include="Tests\PartialApplication.cs" /> 148 - <Compile Include="Tests\RandomAccessQueue.cs" /> 149 - <Compile Include="Tests\Storage.cs" /> 150 - <Compile Include="Tests\TestObject.cs" /> 151 - <Compile Include="Tests\TestStackContext.cs" /> 152 - <Compile Include="Tests\TypeSystem.cs" /> 153 - <Compile Include="Tests\VMTests.Basic.cs" /> 154 - <Compile Include="Tests\VMTests.cs" /> 155 - <Compile Include="Tests\VMTestsBase.cs" /> 156 - </ItemGroup> 157 - <ItemGroup> 158 - <ProjectReference Include="..\Prexonite\Prexonite.csproj"> 159 - <Project>{2FE722CA-B671-4EE8-9BF1-9F3ACFACD24D}</Project> 160 - <Name>Prexonite</Name> 161 - </ProjectReference> 162 - </ItemGroup> 163 - <ItemGroup> 164 - <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> 165 - <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> 166 - <Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" /> 167 - </ItemGroup> 168 - <ItemGroup> 169 - <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> 170 - <Visible>False</Visible> 171 - <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> 172 - <Install>false</Install> 173 - </BootstrapperPackage> 174 - <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> 175 - <Visible>False</Visible> 176 - <ProductName>.NET Framework 3.5 SP1</ProductName> 177 - <Install>true</Install> 178 - </BootstrapperPackage> 179 - <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> 180 - <Visible>False</Visible> 181 - <ProductName>Windows Installer 3.1</ProductName> 182 - <Install>true</Install> 183 - </BootstrapperPackage> 184 - </ItemGroup> 185 - <ItemGroup> 186 - <None Include="app.config" /> 187 - <None Include="packages.config" /> 188 - <None Include="Prexonite.snk" /> 189 - <None Include="psr-tests\ast.test.pxs" /> 190 - <None Include="psr-tests\find-deficiencies.pxs" /> 191 - <None Include="psr-tests\lang-ext.test.pxs" /> 192 - <None Include="psr-tests\macro.test.pxs" /> 193 - <None Include="psr-tests\make_test_configuration.pxs" /> 194 - <None Include="psr-tests\misc.test.pxs" /> 195 - <None Include="psr-tests\run_tests.pxs" /> 196 - <None Include="psr-tests\struct.test.pxs" /> 197 - <None Include="Tests\Configurations\LoadConfiguration.t4"> 198 - <LastGenOutput>LoadConfiguration1.cs</LastGenOutput> 199 - </None> 200 - <None Include="Tests\Configurations\PsrUnitTests.tt"> 201 - <Generator>TextTemplatingFileGenerator</Generator> 202 - <LastGenOutput>PsrUnitTests.cs</LastGenOutput> 203 - </None> 204 - <None Include="Tests\Configurations\VMTestConfigurations.tt"> 205 - <Generator>TextTemplatingFileGenerator</Generator> 206 - <LastGenOutput>VMTestConfigurations.cs</LastGenOutput> 207 - </None> 208 - </ItemGroup> 209 - <ItemGroup> 210 - <Folder Include="Internal\" /> 211 - </ItemGroup> 212 - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 213 - <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> 214 - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 215 - Other similar extension points exist, see Microsoft.Common.targets. 216 - <Target Name="BeforeBuild"> 217 - </Target> 218 - <Target Name="AfterBuild"> 219 - </Target> 220 - --> 1 + <?xml version="1.0" encoding="utf-8"?> 2 + <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0"> 3 + <Import Project="..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props')" /> 4 + <Import Project="..\packages\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" /> 5 + <PropertyGroup> 6 + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> 7 + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 8 + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 9 + <ProductVersion>9.0.21022</ProductVersion> 10 + <SchemaVersion>2.0</SchemaVersion> 11 + <ProjectGuid>{9491D2F5-6758-44CF-9CB9-9F488145F9A3}</ProjectGuid> 12 + <OutputType>Exe</OutputType> 13 + <AppDesignerFolder>Properties</AppDesignerFolder> 14 + <RootNamespace>PrexoniteTests</RootNamespace> 15 + <AssemblyName>PrexoniteTests</AssemblyName> 16 + <FileUpgradeFlags> 17 + </FileUpgradeFlags> 18 + <OldToolsVersion>3.5</OldToolsVersion> 19 + <UpgradeBackupLocation> 20 + </UpgradeBackupLocation> 21 + <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> 22 + <TargetFrameworkProfile> 23 + </TargetFrameworkProfile> 24 + <PublishUrl>publish\</PublishUrl> 25 + <Install>true</Install> 26 + <InstallFrom>Disk</InstallFrom> 27 + <UpdateEnabled>false</UpdateEnabled> 28 + <UpdateMode>Foreground</UpdateMode> 29 + <UpdateInterval>7</UpdateInterval> 30 + <UpdateIntervalUnits>Days</UpdateIntervalUnits> 31 + <UpdatePeriodically>false</UpdatePeriodically> 32 + <UpdateRequired>false</UpdateRequired> 33 + <MapFileExtensions>true</MapFileExtensions> 34 + <ApplicationRevision>0</ApplicationRevision> 35 + <ApplicationVersion>1.0.0.%2a</ApplicationVersion> 36 + <IsWebBootstrapper>false</IsWebBootstrapper> 37 + <UseApplicationTrust>false</UseApplicationTrust> 38 + <BootstrapperEnabled>true</BootstrapperEnabled> 39 + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> 40 + <RestorePackages>true</RestorePackages> 41 + <LangVersion>7.2</LangVersion> 42 + </PropertyGroup> 43 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 44 + <DebugSymbols>true</DebugSymbols> 45 + <DebugType>full</DebugType> 46 + <Optimize>false</Optimize> 47 + <OutputPath>bin\Debug\</OutputPath> 48 + <DefineConstants>TRACE;DEBUG;allowIndex,forceIndex</DefineConstants> 49 + <ErrorReport>prompt</ErrorReport> 50 + <WarningLevel>4</WarningLevel> 51 + <Prefer32Bit>false</Prefer32Bit> 52 + </PropertyGroup> 53 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 54 + <DebugType>pdbonly</DebugType> 55 + <Optimize>true</Optimize> 56 + <OutputPath>bin\Release\</OutputPath> 57 + <DefineConstants>TRACE</DefineConstants> 58 + <ErrorReport>prompt</ErrorReport> 59 + <WarningLevel>4</WarningLevel> 60 + <Prefer32Bit>false</Prefer32Bit> 61 + </PropertyGroup> 62 + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 63 + <DebugSymbols>true</DebugSymbols> 64 + <OutputPath>bin\x86\Debug\</OutputPath> 65 + <DefineConstants>TRACE;DEBUG;allowIndex,forceIndex</DefineConstants> 66 + <DebugType>full</DebugType> 67 + <PlatformTarget>x86</PlatformTarget> 68 + <CodeAnalysisLogFile>bin\Debug\PrexoniteTests.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> 69 + <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> 70 + <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> 71 + <ErrorReport>prompt</ErrorReport> 72 + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 73 + <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> 74 + <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> 75 + <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> 76 + <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> 77 + <Prefer32Bit>false</Prefer32Bit> 78 + </PropertyGroup> 79 + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 80 + <OutputPath>bin\x86\Release\</OutputPath> 81 + <DefineConstants>TRACE</DefineConstants> 82 + <Optimize>true</Optimize> 83 + <DebugType>pdbonly</DebugType> 84 + <PlatformTarget>x86</PlatformTarget> 85 + <CodeAnalysisLogFile>bin\Release\PrexoniteTests.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> 86 + <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> 87 + <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> 88 + <ErrorReport>prompt</ErrorReport> 89 + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 90 + <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> 91 + <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> 92 + <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> 93 + <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> 94 + <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules> 95 + <Prefer32Bit>false</Prefer32Bit> 96 + </PropertyGroup> 97 + <PropertyGroup> 98 + <SignAssembly>true</SignAssembly> 99 + </PropertyGroup> 100 + <PropertyGroup> 101 + <AssemblyOriginatorKeyFile>Prexonite.snk</AssemblyOriginatorKeyFile> 102 + </PropertyGroup> 103 + <ItemGroup> 104 + <Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc"> 105 + <HintPath>..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath> 106 + <Private>True</Private> 107 + </Reference> 108 + <Reference Include="Microsoft.CSharp" /> 109 + <Reference Include="Moq, Version=4.8.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920"> 110 + <HintPath>..\packages\Moq.4.8.2\lib\net45\Moq.dll</HintPath> 111 + <Private>True</Private> 112 + </Reference> 113 + <Reference Include="mscorlib" /> 114 + <Reference Include="nunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb"> 115 + <HintPath>..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath> 116 + <Private>True</Private> 117 + </Reference> 118 + <Reference Include="System" /> 119 + <Reference Include="System.Configuration" /> 120 + <Reference Include="System.Threading.Tasks.Extensions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"> 121 + <HintPath>..\packages\System.Threading.Tasks.Extensions.4.4.0\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath> 122 + </Reference> 123 + <Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"> 124 + <HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath> 125 + <Private>True</Private> 126 + </Reference> 127 + </ItemGroup> 128 + <ItemGroup> 129 + <Compile Include="Meta.cs" /> 130 + <Compile Include="Program.cs" /> 131 + <Compile Include="Properties\AssemblyInfo.cs" /> 132 + <Compile Include="Tests\ApplicationLinking.cs" /> 133 + <Compile Include="Tests\AstTests.cs" /> 134 + <Compile Include="Tests\CilCompilerTests.cs" /> 135 + <Compile Include="Tests\CilRuntime.cs" /> 136 + <Compile Include="Tests\Compiler.cs" /> 137 + <Compile Include="Tests\Compiler.Global.cs" /> 138 + <Compile Include="Tests\Compiler.Parser.cs" /> 139 + <Compile Include="Tests\Configurations\ModuleCache.cs" /> 140 + <Compile Include="Tests\Configurations\PsrUnitTests.cs"> 141 + <AutoGen>True</AutoGen> 142 + <DesignTime>True</DesignTime> 143 + <DependentUpon>PsrUnitTests.tt</DependentUpon> 144 + </Compile> 145 + <Compile Include="Tests\Configurations\TestModel.cs" /> 146 + <Compile Include="Tests\Configurations\UnitTestConfiguration.cs" /> 147 + <Content Include="psr-tests\testconfig.txt" /> 148 + <Compile Include="Tests\Configurations\ScriptedUnitTestContainer.cs" /> 149 + <Compile Include="Tests\Configurations\VMTestConfigurations.cs"> 150 + <AutoGen>True</AutoGen> 151 + <DesignTime>True</DesignTime> 152 + <DependentUpon>VMTestConfigurations.tt</DependentUpon> 153 + </Compile> 154 + <Compile Include="Tests\Internal\DependingOnConstraint.cs" /> 155 + <Compile Include="Tests\MemberCallable.cs" /> 156 + <Compile Include="Tests\MExprTests.cs" /> 157 + <Compile Include="Tests\NamespaceInfrastructureTests.cs" /> 158 + <Compile Include="Tests\SelfAssemblingPlanTests.cs" /> 159 + <Compile Include="Tests\ShellExtensions.cs" /> 160 + <Compile Include="Tests\Translation.cs" /> 161 + <Compile Include="Tests\VMTests.Macro.cs" /> 162 + <Compile Include="Tests\VMTests.Exception.cs" /> 163 + <Compile Include="Tests\VMTests.Commands.cs" /> 164 + <Compile Include="Tests\Lazy.cs" /> 165 + <Compile Include="Tests\PartialApplication.cs" /> 166 + <Compile Include="Tests\RandomAccessQueue.cs" /> 167 + <Compile Include="Tests\Storage.cs" /> 168 + <Compile Include="Tests\TestObject.cs" /> 169 + <Compile Include="Tests\TestStackContext.cs" /> 170 + <Compile Include="Tests\TypeSystem.cs" /> 171 + <Compile Include="Tests\VMTests.Basic.cs" /> 172 + <Compile Include="Tests\VMTests.cs" /> 173 + <Compile Include="Tests\VMTestsBase.cs" /> 174 + </ItemGroup> 175 + <ItemGroup> 176 + <ProjectReference Include="..\Prexonite\Prexonite.csproj"> 177 + <Project>{2FE722CA-B671-4EE8-9BF1-9F3ACFACD24D}</Project> 178 + <Name>Prexonite</Name> 179 + </ProjectReference> 180 + </ItemGroup> 181 + <ItemGroup> 182 + <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> 183 + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> 184 + <Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" /> 185 + </ItemGroup> 186 + <ItemGroup> 187 + <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> 188 + <Visible>False</Visible> 189 + <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> 190 + <Install>false</Install> 191 + </BootstrapperPackage> 192 + <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> 193 + <Visible>False</Visible> 194 + <ProductName>.NET Framework 3.5 SP1</ProductName> 195 + <Install>true</Install> 196 + </BootstrapperPackage> 197 + <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> 198 + <Visible>False</Visible> 199 + <ProductName>Windows Installer 3.1</ProductName> 200 + <Install>true</Install> 201 + </BootstrapperPackage> 202 + </ItemGroup> 203 + <ItemGroup> 204 + <None Include="app.config" /> 205 + <None Include="packages.config" /> 206 + <None Include="Prexonite.snk" /> 207 + <None Include="psr-tests\ast.test.pxs" /> 208 + <None Include="psr-tests\find-deficiencies.pxs" /> 209 + <None Include="psr-tests\lang-ext.test.pxs" /> 210 + <None Include="psr-tests\macro.test.pxs" /> 211 + <None Include="psr-tests\make_test_configuration.pxs" /> 212 + <None Include="psr-tests\misc.test.pxs" /> 213 + <None Include="psr-tests\run_tests.pxs" /> 214 + <None Include="psr-tests\struct.test.pxs" /> 215 + <None Include="Tests\Configurations\LoadConfiguration.t4"> 216 + <LastGenOutput>LoadConfiguration1.cs</LastGenOutput> 217 + </None> 218 + <None Include="Tests\Configurations\PsrUnitTests.tt"> 219 + <Generator>TextTemplatingFileGenerator</Generator> 220 + <LastGenOutput>PsrUnitTests.cs</LastGenOutput> 221 + </None> 222 + <None Include="Tests\Configurations\VMTestConfigurations.tt"> 223 + <Generator>TextTemplatingFileGenerator</Generator> 224 + <LastGenOutput>VMTestConfigurations.cs</LastGenOutput> 225 + </None> 226 + </ItemGroup> 227 + <ItemGroup> 228 + <Folder Include="Internal\" /> 229 + </ItemGroup> 230 + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 231 + <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> 232 + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> 233 + <PropertyGroup> 234 + <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText> 235 + </PropertyGroup> 236 + <Error Condition="!Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.10.1\build\NUnit.props'))" /> 237 + <Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props'))" /> 238 + </Target> 239 + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 240 + Other similar extension points exist, see Microsoft.Common.targets. 241 + <Target Name="BeforeBuild"> 242 + </Target> 243 + <Target Name="AfterBuild"> 244 + </Target> 245 + --> 221 246 </Project>
+1 -1
PrexoniteTests/PrexoniteTests.csproj.DotSettings
··· 1 1 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> 2 2 <s:String x:Key="/Default/CodeEditing/Localization/Localizable/@EntryValue">No</s:String> 3 - <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String></wpf:ResourceDictionary> 3 + </wpf:ResourceDictionary>
+271 -273
PrexoniteTests/Tests/ApplicationLinking.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Collections; 28 - using System.Diagnostics; 29 - using System.Linq; 30 - using NUnit.Framework; 31 - using Prexonite; 32 - using Prexonite.Commands.Core; 33 - using Prexonite.Compiler; 34 - using Prexonite.Compiler.Symbolic; 35 - using Prexonite.Modular; 36 - 37 - namespace PrexoniteTests.Tests 38 - { 39 - [TestFixture] 40 - public class ApplicationLinking : AssertionHelper 41 - { 42 - [Test] 43 - public void NoLocalButCount() 44 - { 45 - var s1 = SymbolStore.Create(); 46 - var s = Symbol.CreateCall(EntityRef.Command.Create("print"), NoSourcePosition.Instance); 47 - s1.Declare("print",s); 48 - var s2 = SymbolStore.Create(s1); 49 - Assert.That(s2.IsEmpty,Is.False,"Expected s2.IsEmpty to be false."); 50 - } 51 - 52 - [Test] 53 - public void SimpleLinkUnlink() 54 - { 55 - var a1 = new Application(); 56 - var a2 = new Application(); 57 - 58 - Assert.That(a1.IsLinked,Is.False,"a1 should not be linked initially"); 59 - Assert.That(a2.IsLinked, Is.False,"a2 should not be linked initially"); 60 - 61 - Application.Link(a1,a2); 62 - 63 - Assert.That(a1.IsLinked, Is.True,"a1 should be linked"); 64 - Assert.That(a2.IsLinked, Is.True,"a2 should be linked"); 65 - 66 - a1.Unlink(); 67 - 68 - Assert.That(a1.IsLinked,Is.False,"a1 should not be linked afterwards"); 69 - Assert.That(a2.IsLinked, Is.False, "a2 should not be linked afterwards"); 70 - } 71 - 72 - [Test] 73 - public void CompoundLinking() 74 - { 75 - var aps = 76 - Enumerable.Range(1, 3) 77 - .Select(i => new Application("a" + i)) 78 - .ToList(); 79 - 80 - var bps = 81 - Enumerable.Range(1, 4) 82 - .Select(i => new Application("b" + i)) 83 - .ToList(); 84 - 85 - var ps = aps.Append(bps).ToList(); 86 - 87 - foreach (var a in ps) 88 - Assert.That(a.IsLinked, Is.False, 89 - string.Format("Application {0} should not be linked initially.", a)); 90 - 91 - //Link a's and b's, respectively 92 - foreach (var a in aps.Skip(1)) 93 - Application.Link(a, aps[0]); 94 - foreach (var a in bps.Skip(1)) 95 - Application.Link(a, bps[0]); 96 - 97 - Assert.That(aps[0].Compound,Is.Not.Contains(bps[0])); 98 - Assert.That(bps[0].Compound, Is.Not.Contains(aps[0])); 99 - 100 - Application.Link(aps[0],bps[1]); 101 - 102 - foreach (var a in ps) 103 - Assert.That(a.IsLinked, Is.True, 104 - string.Format("Application {0} should be linked afterwards.", a)); 105 - 106 - var c = aps[0].Compound; 107 - foreach (var a in ps) 108 - { 109 - Assert.That(a.Compound, Is.SameAs(c), 110 - string.Format( 111 - "Compound object of application {0} should be " + 112 - "identical with that of application {1}.", 113 - a, aps[0])); 114 - } 115 - 116 - Assert.That(aps[0].Compound.Count,Is.EqualTo(aps.Count + bps.Count)); 117 - 118 - Assert.That(aps[0].Compound,Is.SubsetOf(ps), "Compound contains elements not in the original set."); 119 - Assert.That(ps, Is.SubsetOf(aps[0].Compound), "Not all elements of the original set are in the compound."); 120 - 121 - var p = aps[0]; 122 - p.Unlink(); 123 - Assert.That(p.IsLinked,Is.False,"p should now be unlinked."); 124 - Assert.That(aps[1].Compound.Count,Is.EqualTo(aps.Count + bps.Count - 1),"Compound is not the right size."); 125 - 126 - foreach (var a in ps.Where(x => x != p)) 127 - Assert.That(a.IsLinked, Is.True, 128 - string.Format("Application {0} should still be linked afterwards.", a)); 129 - c = aps[1].Compound; 130 - foreach (var a in ps.Where(x => x != p)) 131 - { 132 - Assert.That(a.Compound, Is.SameAs(c), 133 - string.Format( 134 - "Compound object of application {0} should be " + 135 - "identical with that of application {1}.", 136 - a, aps[1])); 137 - } 138 - } 139 - 140 - [Test] 141 - public void MergeLinking() 142 - { 143 - var cps = 144 - Enumerable.Range(1, 3) 145 - .Select(i => new Application("common" + i)) 146 - .ToList(); 147 - 148 - var aps = 149 - Enumerable.Range(1, 3) 150 - .Select(i => new Application("a" + i)) 151 - .Append(cps) 152 - .ToList(); 153 - 154 - var bps = 155 - Enumerable.Range(1, 4) 156 - .Select(i => new Application("b" + i)) 157 - .Append(cps) 158 - .ToList(); 159 - 160 - var ps = aps.Union(bps).ToList(); 161 - 162 - foreach (var a in ps) 163 - Assert.That(a.IsLinked, Is.False, 164 - string.Format("Application {0} should not be linked initially.", a)); 165 - 166 - //Link a's and b's, respectively 167 - foreach (var a in aps.Skip(1)) 168 - Application.Link(a, aps[0]); 169 - foreach (var a in bps.Skip(1)) 170 - Application.Link(a, bps[0]); 171 - 172 - Assert.That(aps[0].Compound, Not.Member(bps)); 173 - Assert.That(bps[0].Compound, Not.Member(aps)); 174 - 175 - Application.Link(aps[0],bps[1]); 176 - 177 - foreach (var a in ps) 178 - Assert.That(a.IsLinked, Is.True, 179 - string.Format("Application {0} should be linked afterwards.", a.Module.Name)); 180 - 181 - var c = aps[0].Compound; 182 - foreach (var a in ps) 183 - { 184 - Assert.That(a.Compound, Is.SameAs(c), 185 - string.Format( 186 - "Compound object of application {0} should be " + 187 - "identical with that of application {1}.", 188 - a, aps[0])); 189 - } 190 - 191 - Assert.That(aps[0].Compound.Count,Is.EqualTo(ps.Count)); 192 - 193 - Assert.That(aps[0].Compound,Is.EquivalentTo(ps), "Compound is not equivalent to aps ∪ bps."); 194 - 195 - var p = cps[0]; 196 - p.Unlink(); 197 - Assert.That(p.IsLinked,Is.False,"p should now be unlinked."); 198 - Assert.That(aps[1].Compound.Count,Is.EqualTo(ps.Count - 1),"Compound is not the right size."); 199 - 200 - foreach (var a in ps.Where(x => x != p)) 201 - Assert.That(a.IsLinked, Is.True, 202 - string.Format("Application {0} should still be linked afterwards.", a)); 203 - c = aps[1].Compound; 204 - foreach (var a in ps.Where(x => x != p)) 205 - { 206 - Assert.That(a.Compound, Is.SameAs(c), 207 - string.Format( 208 - "Compound object of application {0} should be " + 209 - "identical with that of application {1}.", 210 - a, aps[1])); 211 - } 212 - } 213 - 214 - [Test] 215 - public void DryCrossModuleCall() 216 - { 217 - var m1 = Module.Create(new ModuleName("dragon", new Version(1, 2))); 218 - var m2 = Module.Create(new ModuleName("std", new Version(1, 3, 1))); 219 - 220 - var a1 = new Application(m1); 221 - var a2 = new Application(m2); 222 - 223 - var f1 = a1.CreateFunction(Application.DefaultEntryFunction); 224 - 225 - var f2 = a2.CreateFunction("sayHello"); 226 - 227 - f1.Code.Add(new Instruction(OpCode.func, 0, f2.Id, m2.Name)); 228 - f1.Code.Add(new Instruction(OpCode.ret_value)); 229 - 230 - const string helloModules = "Hello Modules"; 231 - f2.Code.Add(new Instruction(OpCode.ldc_string,helloModules)); 232 - f2.Code.Add(new Instruction(OpCode.ret_value)); 233 - 234 - Console.WriteLine("=========== Module {0} ==========", m1.Name); 235 - a1.Store(Console.Out); 236 - Console.WriteLine(); 237 - Console.WriteLine("=========== Module {0} ==========", m2.Name); 238 - a2.Store(Console.Out); 239 - 240 - var eng = new Engine(); 241 - 242 - try 243 - { 244 - a1.Run(eng); 245 - Assert.Fail("Should not succeed as applications are not linked."); 246 - } 247 - catch (PrexoniteRuntimeException e) 248 - { 249 - Console.WriteLine("EXPECTED EXCEPTION"); 250 - Console.WriteLine(e.Message); 251 - Console.WriteLine("END OF EXPECTED EXCEPTION"); 252 - } 253 - 254 - Application.Link(a1, a2); 255 - var r = a1.Run(eng); 256 - Expect(r.Value,Is.InstanceOf<string>()); 257 - Expect(r.Value,Is.EqualTo(helloModules)); 258 - } 259 - 260 - [Test] 261 - public void CreateModuleNameCommand() 262 - { 263 - var cmd = CreateModuleName.Instance; 264 - var eng = new Engine(); 265 - var app = new Application("cmnc"); 266 - var sctx = new NullContext(eng, app, Enumerable.Empty<string>()); 267 - var rawMn = cmd.Run(sctx, new[] {sctx.CreateNativePValue(new MetaEntry(new MetaEntry[]{"sys","1.0"}))}); 268 - Assert.That(rawMn.Value,Is.InstanceOf<ModuleName>()); 269 - var mn = (ModuleName) rawMn.Value; 270 - Assert.That(mn.Id,Is.EqualTo("sys")); 271 - Assert.That(mn.Version,Is.EqualTo(new Version(1,0))); 272 - } 273 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Linq; 28 + using NUnit.Framework; 29 + using Prexonite; 30 + using Prexonite.Commands.Core; 31 + using Prexonite.Compiler; 32 + using Prexonite.Compiler.Symbolic; 33 + using Prexonite.Modular; 34 + 35 + namespace PrexoniteTests.Tests 36 + { 37 + [TestFixture] 38 + public class ApplicationLinking 39 + { 40 + [Test] 41 + public void NoLocalButCount() 42 + { 43 + var s1 = SymbolStore.Create(); 44 + var s = Symbol.CreateCall(EntityRef.Command.Create("print"), NoSourcePosition.Instance); 45 + s1.Declare("print",s); 46 + var s2 = SymbolStore.Create(s1); 47 + Assert.That(s2.IsEmpty,Is.False,"Expected s2.IsEmpty to be false."); 48 + } 49 + 50 + [Test] 51 + public void SimpleLinkUnlink() 52 + { 53 + var a1 = new Application(); 54 + var a2 = new Application(); 55 + 56 + Assert.That(a1.IsLinked,Is.False,"a1 should not be linked initially"); 57 + Assert.That(a2.IsLinked, Is.False,"a2 should not be linked initially"); 58 + 59 + Application.Link(a1,a2); 60 + 61 + Assert.That(a1.IsLinked, Is.True,"a1 should be linked"); 62 + Assert.That(a2.IsLinked, Is.True,"a2 should be linked"); 63 + 64 + a1.Unlink(); 65 + 66 + Assert.That(a1.IsLinked,Is.False,"a1 should not be linked afterwards"); 67 + Assert.That(a2.IsLinked, Is.False, "a2 should not be linked afterwards"); 68 + } 69 + 70 + [Test] 71 + public void CompoundLinking() 72 + { 73 + var aps = 74 + Enumerable.Range(1, 3) 75 + .Select(i => new Application("a" + i)) 76 + .ToList(); 77 + 78 + var bps = 79 + Enumerable.Range(1, 4) 80 + .Select(i => new Application("b" + i)) 81 + .ToList(); 82 + 83 + var ps = aps.Append(bps).ToList(); 84 + 85 + foreach (var a in ps) 86 + Assert.That(a.IsLinked, Is.False, 87 + string.Format("Application {0} should not be linked initially.", a)); 88 + 89 + //Link a's and b's, respectively 90 + foreach (var a in aps.Skip(1)) 91 + Application.Link(a, aps[0]); 92 + foreach (var a in bps.Skip(1)) 93 + Application.Link(a, bps[0]); 94 + 95 + Assert.That(aps[0].Compound,Is.Not.Contains(bps[0])); 96 + Assert.That(bps[0].Compound, Is.Not.Contains(aps[0])); 97 + 98 + Application.Link(aps[0],bps[1]); 99 + 100 + foreach (var a in ps) 101 + Assert.That(a.IsLinked, Is.True, 102 + string.Format("Application {0} should be linked afterwards.", a)); 103 + 104 + var c = aps[0].Compound; 105 + foreach (var a in ps) 106 + { 107 + Assert.That(a.Compound, Is.SameAs(c), 108 + string.Format( 109 + "Compound object of application {0} should be " + 110 + "identical with that of application {1}.", 111 + a, aps[0])); 112 + } 113 + 114 + Assert.That(aps[0].Compound.Count,Is.EqualTo(aps.Count + bps.Count)); 115 + 116 + Assert.That(aps[0].Compound,Is.SubsetOf(ps), "Compound contains elements not in the original set."); 117 + Assert.That(ps, Is.SubsetOf(aps[0].Compound), "Not all elements of the original set are in the compound."); 118 + 119 + var p = aps[0]; 120 + p.Unlink(); 121 + Assert.That(p.IsLinked,Is.False,"p should now be unlinked."); 122 + Assert.That(aps[1].Compound.Count,Is.EqualTo(aps.Count + bps.Count - 1),"Compound is not the right size."); 123 + 124 + foreach (var a in ps.Where(x => x != p)) 125 + Assert.That(a.IsLinked, Is.True, 126 + string.Format("Application {0} should still be linked afterwards.", a)); 127 + c = aps[1].Compound; 128 + foreach (var a in ps.Where(x => x != p)) 129 + { 130 + Assert.That(a.Compound, Is.SameAs(c), 131 + string.Format( 132 + "Compound object of application {0} should be " + 133 + "identical with that of application {1}.", 134 + a, aps[1])); 135 + } 136 + } 137 + 138 + [Test] 139 + public void MergeLinking() 140 + { 141 + var cps = 142 + Enumerable.Range(1, 3) 143 + .Select(i => new Application("common" + i)) 144 + .ToList(); 145 + 146 + var aps = 147 + Enumerable.Range(1, 3) 148 + .Select(i => new Application("a" + i)) 149 + .Append(cps) 150 + .ToList(); 151 + 152 + var bps = 153 + Enumerable.Range(1, 4) 154 + .Select(i => new Application("b" + i)) 155 + .Append(cps) 156 + .ToList(); 157 + 158 + var ps = aps.Union(bps).ToList(); 159 + 160 + foreach (var a in ps) 161 + Assert.That(a.IsLinked, Is.False, 162 + string.Format("Application {0} should not be linked initially.", a)); 163 + 164 + //Link a's and b's, respectively 165 + foreach (var a in aps.Skip(1)) 166 + Application.Link(a, aps[0]); 167 + foreach (var a in bps.Skip(1)) 168 + Application.Link(a, bps[0]); 169 + 170 + Assert.That(aps[0].Compound, !Contains.Item(bps)); 171 + Assert.That(bps[0].Compound, !Contains.Item(aps)); 172 + 173 + Application.Link(aps[0],bps[1]); 174 + 175 + foreach (var a in ps) 176 + Assert.That(a.IsLinked, Is.True, 177 + string.Format("Application {0} should be linked afterwards.", a.Module.Name)); 178 + 179 + var c = aps[0].Compound; 180 + foreach (var a in ps) 181 + { 182 + Assert.That(a.Compound, Is.SameAs(c), 183 + string.Format( 184 + "Compound object of application {0} should be " + 185 + "identical with that of application {1}.", 186 + a, aps[0])); 187 + } 188 + 189 + Assert.That(aps[0].Compound.Count,Is.EqualTo(ps.Count)); 190 + 191 + Assert.That(aps[0].Compound,Is.EquivalentTo(ps), "Compound is not equivalent to aps ∪ bps."); 192 + 193 + var p = cps[0]; 194 + p.Unlink(); 195 + Assert.That(p.IsLinked,Is.False,"p should now be unlinked."); 196 + Assert.That(aps[1].Compound.Count,Is.EqualTo(ps.Count - 1),"Compound is not the right size."); 197 + 198 + foreach (var a in ps.Where(x => x != p)) 199 + Assert.That(a.IsLinked, Is.True, 200 + string.Format("Application {0} should still be linked afterwards.", a)); 201 + c = aps[1].Compound; 202 + foreach (var a in ps.Where(x => x != p)) 203 + { 204 + Assert.That(a.Compound, Is.SameAs(c), 205 + string.Format( 206 + "Compound object of application {0} should be " + 207 + "identical with that of application {1}.", 208 + a, aps[1])); 209 + } 210 + } 211 + 212 + [Test] 213 + public void DryCrossModuleCall() 214 + { 215 + var m1 = Module.Create(new ModuleName("dragon", new Version(1, 2))); 216 + var m2 = Module.Create(new ModuleName("std", new Version(1, 3, 1))); 217 + 218 + var a1 = new Application(m1); 219 + var a2 = new Application(m2); 220 + 221 + var f1 = a1.CreateFunction(Application.DefaultEntryFunction); 222 + 223 + var f2 = a2.CreateFunction("sayHello"); 224 + 225 + f1.Code.Add(new Instruction(OpCode.func, 0, f2.Id, m2.Name)); 226 + f1.Code.Add(new Instruction(OpCode.ret_value)); 227 + 228 + const string helloModules = "Hello Modules"; 229 + f2.Code.Add(new Instruction(OpCode.ldc_string,helloModules)); 230 + f2.Code.Add(new Instruction(OpCode.ret_value)); 231 + 232 + Console.WriteLine("=========== Module {0} ==========", m1.Name); 233 + a1.Store(Console.Out); 234 + Console.WriteLine(); 235 + Console.WriteLine("=========== Module {0} ==========", m2.Name); 236 + a2.Store(Console.Out); 237 + 238 + var eng = new Engine(); 239 + 240 + try 241 + { 242 + a1.Run(eng); 243 + Assert.Fail("Should not succeed as applications are not linked."); 244 + } 245 + catch (PrexoniteRuntimeException e) 246 + { 247 + Console.WriteLine("EXPECTED EXCEPTION"); 248 + Console.WriteLine(e.Message); 249 + Console.WriteLine("END OF EXPECTED EXCEPTION"); 250 + } 251 + 252 + Application.Link(a1, a2); 253 + var r = a1.Run(eng); 254 + Assert.That(r.Value,Is.InstanceOf<string>()); 255 + Assert.That(r.Value,Is.EqualTo(helloModules)); 256 + } 257 + 258 + [Test] 259 + public void CreateModuleNameCommand() 260 + { 261 + var cmd = CreateModuleName.Instance; 262 + var eng = new Engine(); 263 + var app = new Application("cmnc"); 264 + var sctx = new NullContext(eng, app, Enumerable.Empty<string>()); 265 + var rawMn = cmd.Run(sctx, new[] {sctx.CreateNativePValue(new MetaEntry(new MetaEntry[]{"sys","1.0"}))}); 266 + Assert.That(rawMn.Value,Is.InstanceOf<ModuleName>()); 267 + var mn = (ModuleName) rawMn.Value; 268 + Assert.That(mn.Id,Is.EqualTo("sys")); 269 + Assert.That(mn.Version,Is.EqualTo(new Version(1,0))); 270 + } 271 + } 274 272 }
+165 -163
PrexoniteTests/Tests/AstTests.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Collections.Generic; 28 - using System.Linq; 29 - using NUnit.Framework; 30 - using Prexonite; 31 - using Prexonite.Compiler.Ast; 32 - 33 - namespace PrexoniteTests.Tests 34 - { 35 - [TestFixture] 36 - public class AstTests 37 - { 38 - private static AstPlaceholder _createPlaceholder(int? index = null) 39 - { 40 - return new AstPlaceholder("-file", -1, -2) {Index = index}; 41 - } 42 - 43 - [Test] 44 - public void DeterminePlaceholderIndicesNormalTets() 45 - { 46 - //(?,?2,?,?2,?1) 47 - var placeholders = new List<AstPlaceholder> 48 - { 49 - _createPlaceholder(), 50 - _createPlaceholder(1), 51 - _createPlaceholder(), 52 - _createPlaceholder(1), 53 - _createPlaceholder(0) 54 - }; 55 - 56 - var copy = placeholders.ToList(); 57 - Assert.AreNotSame(copy, placeholders); 58 - 59 - AstPlaceholder.DeterminePlaceholderIndices(placeholders); 60 - 61 - //First assert that the list itself has not been altered 62 - Assert.AreEqual(placeholders.Count, copy.Count); 63 - for (var i = 0; i < placeholders.Count; i++) 64 - Assert.AreSame(copy[i], placeholders[i], "List itself must not be altered."); 65 - 66 - //Expexted mapping (0-based): 67 - // ?2, ?1, ?3, ?1, ?0 68 - foreach (var placeholder in placeholders) 69 - Assert.IsTrue(placeholder.Index.HasValue, 70 - "All placeholders should be assigned afterwards."); 71 - 72 - // ReSharper disable PossibleInvalidOperationException 73 - Assert.AreEqual(2, placeholders[0].Index.Value, 74 - "Placeholder at source position 0 is not mapped correctly"); 75 - Assert.AreEqual(1, placeholders[1].Index.Value, 76 - "Placeholder at source position 1 is not mapped correctly"); 77 - Assert.AreEqual(3, placeholders[2].Index.Value, 78 - "Placeholder at source position 2 is not mapped correctly"); 79 - Assert.AreEqual(1, placeholders[3].Index.Value, 80 - "Placeholder at source position 3 is not mapped correctly"); 81 - Assert.AreEqual(0, placeholders[4].Index.Value, 82 - "Placeholder at source position 4 is not mapped correctly"); 83 - // ReSharper restore PossibleInvalidOperationException 84 - } 85 - 86 - [Test] 87 - public void DeterminePlaceholderIndicesEmptyTets() 88 - { 89 - AstPlaceholder.DeterminePlaceholderIndices(Enumerable.Empty<AstPlaceholder>()); 90 - } 91 - 92 - [Test, ExpectedException(typeof (NullReferenceException))] 93 - public void DeterminePlaceholderIndicesRejectNullTets() 94 - { 95 - AstPlaceholder.DeterminePlaceholderIndices(Extensions.Singleton<AstPlaceholder>(null)); 96 - } 97 - 98 - [Test] 99 - public void RemoveRedundant1() 100 - { 101 - const string file = "THE_FILE"; 102 - const int line = 666; 103 - const int col = 555; 104 - //test case from MissingMapped 105 - var subject = new AstNull(file, line, col); 106 - var argv = new List<AstExpr> 107 - { 108 - subject, 109 - _createPlaceholder(1), 110 - _createPlaceholder(2) 111 - }; 112 - var originalArgv = argv.ToList(); 113 - 114 - _placeholderArgvProcessing(argv); 115 - 116 - Assert.AreEqual(3, argv.Count, "argc changed"); 117 - for (var i = 0; i < argv.Count; i++) 118 - Assert.AreSame(originalArgv[i], argv[i]); 119 - } 120 - 121 - private static void _placeholderArgvProcessing(List<AstExpr> argv) 122 - { 123 - Console.WriteLine("ARGV implicit:"); 124 - foreach (var expr in argv) 125 - Console.WriteLine("\t{0}", expr); 126 - 127 - AstPlaceholder.DeterminePlaceholderIndices(argv.MapMaybe(x => x as AstPlaceholder)); 128 - 129 - Console.WriteLine("ARGV explicit:"); 130 - foreach (var expr in argv) 131 - Console.WriteLine("\t{0}", expr); 132 - 133 - AstPartiallyApplicable.RemoveRedundantPlaceholders(argv); 134 - 135 - Console.WriteLine("ARGV minimal:"); 136 - foreach (var expr in argv) 137 - Console.WriteLine("\t{0}", expr); 138 - } 139 - 140 - [Test] 141 - public void RemoveRedundant2() 142 - { 143 - const string file = "THE_FILE"; 144 - const int line = 666; 145 - const int col = 555; 146 - //test case from MissingMapped 147 - var subject = new AstNull(file, line, col); 148 - var argv = new List<AstExpr> 149 - { 150 - subject, 151 - _createPlaceholder(2), 152 - _createPlaceholder(), 153 - _createPlaceholder(1) 154 - }; 155 - var originalArgv = argv.GetRange(0, 2); 156 - 157 - _placeholderArgvProcessing(argv); 158 - 159 - Assert.AreEqual(originalArgv.Count, argv.Count, "argc not correct"); 160 - for (var i = 0; i < originalArgv.Count; i++) 161 - Assert.AreSame(originalArgv[i], argv[i]); 162 - } 163 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Collections.Generic; 28 + using System.Linq; 29 + using NUnit.Framework; 30 + using Prexonite; 31 + using Prexonite.Compiler.Ast; 32 + 33 + namespace PrexoniteTests.Tests 34 + { 35 + [TestFixture] 36 + public class AstTests 37 + { 38 + private static AstPlaceholder _createPlaceholder(int? index = null) 39 + { 40 + return new AstPlaceholder("-file", -1, -2) {Index = index}; 41 + } 42 + 43 + [Test] 44 + public void DeterminePlaceholderIndicesNormalTets() 45 + { 46 + //(?,?2,?,?2,?1) 47 + var placeholders = new List<AstPlaceholder> 48 + { 49 + _createPlaceholder(), 50 + _createPlaceholder(1), 51 + _createPlaceholder(), 52 + _createPlaceholder(1), 53 + _createPlaceholder(0) 54 + }; 55 + 56 + var copy = placeholders.ToList(); 57 + Assert.AreNotSame(copy, placeholders); 58 + 59 + AstPlaceholder.DeterminePlaceholderIndices(placeholders); 60 + 61 + //First assert that the list itself has not been altered 62 + Assert.AreEqual(placeholders.Count, copy.Count); 63 + for (var i = 0; i < placeholders.Count; i++) 64 + Assert.AreSame(copy[i], placeholders[i], "List itself must not be altered."); 65 + 66 + //Expexted mapping (0-based): 67 + // ?2, ?1, ?3, ?1, ?0 68 + foreach (var placeholder in placeholders) 69 + Assert.IsTrue(placeholder.Index.HasValue, 70 + "All placeholders should be assigned afterwards."); 71 + 72 + // ReSharper disable PossibleInvalidOperationException 73 + Assert.AreEqual(2, placeholders[0].Index.Value, 74 + "Placeholder at source position 0 is not mapped correctly"); 75 + Assert.AreEqual(1, placeholders[1].Index.Value, 76 + "Placeholder at source position 1 is not mapped correctly"); 77 + Assert.AreEqual(3, placeholders[2].Index.Value, 78 + "Placeholder at source position 2 is not mapped correctly"); 79 + Assert.AreEqual(1, placeholders[3].Index.Value, 80 + "Placeholder at source position 3 is not mapped correctly"); 81 + Assert.AreEqual(0, placeholders[4].Index.Value, 82 + "Placeholder at source position 4 is not mapped correctly"); 83 + // ReSharper restore PossibleInvalidOperationException 84 + } 85 + 86 + [Test] 87 + public void DeterminePlaceholderIndicesEmptyTets() 88 + { 89 + AstPlaceholder.DeterminePlaceholderIndices(Enumerable.Empty<AstPlaceholder>()); 90 + } 91 + 92 + [Test] 93 + public void DeterminePlaceholderIndicesRejectNullTets() 94 + { 95 + Assert.Throws<NullReferenceException>(() => 96 + AstPlaceholder.DeterminePlaceholderIndices(Extensions.Singleton<AstPlaceholder>(null)) 97 + ); 98 + } 99 + 100 + [Test] 101 + public void RemoveRedundant1() 102 + { 103 + const string file = "THE_FILE"; 104 + const int line = 666; 105 + const int col = 555; 106 + //test case from MissingMapped 107 + var subject = new AstNull(file, line, col); 108 + var argv = new List<AstExpr> 109 + { 110 + subject, 111 + _createPlaceholder(1), 112 + _createPlaceholder(2) 113 + }; 114 + var originalArgv = argv.ToList(); 115 + 116 + _placeholderArgvProcessing(argv); 117 + 118 + Assert.AreEqual(3, argv.Count, "argc changed"); 119 + for (var i = 0; i < argv.Count; i++) 120 + Assert.AreSame(originalArgv[i], argv[i]); 121 + } 122 + 123 + private static void _placeholderArgvProcessing(List<AstExpr> argv) 124 + { 125 + Console.WriteLine("ARGV implicit:"); 126 + foreach (var expr in argv) 127 + Console.WriteLine("\t{0}", expr); 128 + 129 + AstPlaceholder.DeterminePlaceholderIndices(argv.MapMaybe(x => x as AstPlaceholder)); 130 + 131 + Console.WriteLine("ARGV explicit:"); 132 + foreach (var expr in argv) 133 + Console.WriteLine("\t{0}", expr); 134 + 135 + AstPartiallyApplicable.RemoveRedundantPlaceholders(argv); 136 + 137 + Console.WriteLine("ARGV minimal:"); 138 + foreach (var expr in argv) 139 + Console.WriteLine("\t{0}", expr); 140 + } 141 + 142 + [Test] 143 + public void RemoveRedundant2() 144 + { 145 + const string file = "THE_FILE"; 146 + const int line = 666; 147 + const int col = 555; 148 + //test case from MissingMapped 149 + var subject = new AstNull(file, line, col); 150 + var argv = new List<AstExpr> 151 + { 152 + subject, 153 + _createPlaceholder(2), 154 + _createPlaceholder(), 155 + _createPlaceholder(1) 156 + }; 157 + var originalArgv = argv.GetRange(0, 2); 158 + 159 + _placeholderArgvProcessing(argv); 160 + 161 + Assert.AreEqual(originalArgv.Count, argv.Count, "argc not correct"); 162 + for (var i = 0; i < originalArgv.Count; i++) 163 + Assert.AreSame(originalArgv[i], argv[i]); 164 + } 165 + } 164 166 }
+647 -645
PrexoniteTests/Tests/CilCompilerTests.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System.Collections.Generic; 27 - using System.Linq; 28 - using NUnit.Framework; 29 - using Prexonite; 30 - using Prexonite.Compiler; 31 - using Prexonite.Compiler.Cil; 32 - 33 - namespace PrexoniteTests.Tests 34 - { 35 - [TestFixture] 36 - public class CilCompilerTests : VMTestsBase 37 - { 38 - [Test] 39 - public void SetCilHintTest() 40 - { 41 - Compile(@" 42 - function main() { 43 - foreach(var x in var args) 44 - println(x); 45 - }"); 46 - 47 - var main = target.Functions["main"]; 48 - 49 - var cilExt1 = new CilExtensionHint(new List<int> {1, 5, 9}); 50 - var existingHints = _getCilHints(main, true); 51 - Assert.AreEqual(1, existingHints.Length); 52 - 53 - //Add, none existing 54 - Compiler.SetCilHint(main, cilExt1); 55 - var hints1 = _getCilHints(main, true); 56 - Assert.AreNotSame(existingHints, hints1); 57 - Assert.AreEqual(2, hints1.Length); 58 - Assert.IsTrue(hints1[1].IsList); 59 - var cilExt1P = CilExtensionHint.FromMetaEntry(hints1[1].List); 60 - Assert.IsTrue( 61 - cilExt1P.Offsets.All(offset => cilExt1.Offsets.Contains(offset)), 62 - "deserialized contains elements not in original"); 63 - Assert.IsTrue(cilExt1.Offsets.All(offset => cilExt1P.Offsets.Contains(offset)), 64 - "original contains elements not in deserialized"); 65 - 66 - //Add, one existing 67 - var cilExt2 = new CilExtensionHint(new List<int> {2, 4, 8, 16}); 68 - Compiler.SetCilHint(main, cilExt2); 69 - var hints2 = _getCilHints(main, true); 70 - Assert.AreSame(hints1, hints2); 71 - Assert.AreEqual(2, hints2.Length); 72 - Assert.IsTrue(hints2[1].IsList); 73 - var cilExt2P = CilExtensionHint.FromMetaEntry(hints2[1].List); 74 - Assert.IsTrue( 75 - cilExt2P.Offsets.All(offset => cilExt2.Offsets.Contains(offset)), 76 - "deserialized contains elements not in original"); 77 - Assert.IsTrue(cilExt2.Offsets.All(offset => cilExt2P.Offsets.Contains(offset)), 78 - "original contains elements not in deserialized"); 79 - 80 - //Add, many existing 81 - var cilExts = new List<CilExtensionHint> 82 - { 83 - new CilExtensionHint(new List<int> {1, 6, 16, 66}), 84 - new CilExtensionHint(new List<int> {7, 77, 777}), 85 - new CilExtensionHint(new List<int> {9, 88, 777, 6666}), 86 - }; 87 - foreach (var cilExt in cilExts) 88 - Compiler.AddCilHint(main, cilExt); 89 - var hints3 = _getCilHints(main, true); 90 - Assert.AreNotSame(hints2, hints3); 91 - Assert.AreEqual(5, hints3.Length); 92 - var cilExt3 = new CilExtensionHint(new List<int> {44, 55, 66, 77, 88}); 93 - Compiler.SetCilHint(main, cilExt3); 94 - var hints4 = _getCilHints(main, true); 95 - Assert.AreNotSame(hints3, hints4); 96 - Assert.AreEqual(2, hints4.Length); 97 - Assert.IsTrue(hints4[1].IsList); 98 - var cilExt3P = CilExtensionHint.FromMetaEntry(hints4[1].List); 99 - Assert.IsTrue( 100 - cilExt3P.Offsets.All(offset => cilExt3.Offsets.Contains(offset)), 101 - "deserialized contains elements not in original"); 102 - Assert.IsTrue(cilExt3.Offsets.All(offset => cilExt3P.Offsets.Contains(offset)), 103 - "original contains elements not in deserialized"); 104 - 105 - 106 - //Add, no cil hints key yet 107 - var emptyFunc = target.CreateFunction(); 108 - emptyFunc.Meta[PFunction.IdKey] = "empty"; 109 - Compiler.SetCilHint(main, cilExt3); 110 - var hints5 = _getCilHints(main, true); 111 - Assert.AreEqual(2, hints5.Length); 112 - Assert.IsTrue(hints5[0].IsList); 113 - var cilExt4P = CilExtensionHint.FromMetaEntry(hints5[1].List); 114 - Assert.IsTrue( 115 - cilExt4P.Offsets.All(offset => cilExt3.Offsets.Contains(offset)), 116 - "deserialized contains elements not in original"); 117 - Assert.IsTrue(cilExt3.Offsets.All(offset => cilExt4P.Offsets.Contains(offset)), 118 - "original contains elements not in deserialized"); 119 - } 120 - 121 - private static MetaEntry[] _getCilHints(IHasMetaTable table, bool keyMustExist) 122 - { 123 - MetaEntry cilHintsEntry; 124 - if (table.Meta.TryGetValue(Loader.CilHintsKey, out cilHintsEntry)) 125 - { 126 - Assert.IsTrue(cilHintsEntry.IsList, "CIL hints entry must be a list."); 127 - return cilHintsEntry.List; 128 - } 129 - else if (keyMustExist) 130 - { 131 - Assert.Fail("Meta table of {0} does not contain cil hints.", table); 132 - return null; 133 - } 134 - else 135 - { 136 - table.Meta[Loader.CilHintsKey] = (MetaEntry) new MetaEntry[0]; 137 - return _getCilHints(table, true); 138 - } 139 - } 140 - 141 - [Test] 142 - public void UnbindCommandTest() 143 - { 144 - Compile( 145 - @" 146 - function main() 147 - { 148 - var result = []; 149 - var x = 1; 150 - ref y = ->x; 151 - result[] = x == 1; 152 - result[] = ->x == ->y; 153 - new var x; 154 - result[] = x == 1; 155 - result[] = not System::Object.ReferenceEquals(->x, ->y); 156 - 157 - result[] = var x == new var x; 158 - result[] = x == 1; 159 - result[] = not System::Object.ReferenceEquals(->x, ->y); 160 - 161 - //behave like ordinary command 162 - result[] = unbind(->x) is null; 163 - result[] = x == 1; 164 - result[] = not System::Object.ReferenceEquals(->x, ->y); 165 - 166 - return result; 167 - } 168 - "); 169 - _expectCil(); 170 - Expect(Enumerable.Range(1, 10).Select(_ => (PValue) true).ToList()); 171 - } 172 - 173 - 174 - [Test] 175 - public void JumpBreaksCilExtensions() 176 - { 177 - Compile( 178 - @" 179 - function main(b) 180 - {asm{ 181 - ldloc b 182 - ldc.int 4 183 - cmd.2 (==) 184 - jump.f L_else 185 - label L_if ldc.string ""IF"" 186 - jump L_endif 187 - label L_else ldc.string ""ELSE"" 188 - label L_endif ldc.string ""-branch"" 189 - cmd.2 (+) 190 - ret 191 - }} 192 - "); 193 - Assert.AreEqual(1, _getCilHints(target.Functions["main"], true).Length); 194 - _expectCil(); 195 - Expect("IF-branch", 4); 196 - Expect("ELSE-branch", 3); 197 - Expect("ELSE-branch", 5); 198 - } 199 - 200 - [Test] 201 - public void TryCatchFinallyCompiles() 202 - { 203 - Compile( 204 - @" 205 - var t = """"; 206 - function trace(x) = t+=x; 207 - 208 - function main() 209 - { 210 - try { 211 - trace(""t""); 212 - throw ""e""; 213 - }catch(var exc){ 214 - trace(""c""); 215 - trace(exc.Message); 216 - }finally{ 217 - trace(""f""); 218 - } 219 - 220 - return t; 221 - } 222 - "); 223 - _expectCil(); 224 - Expect("tfce"); 225 - } 226 - 227 - private void _expectCil(string functionId = "main") 228 - { 229 - var func = target.Functions[functionId]; 230 - Assert.IsNotNull(func, "Function " + functionId + " must exist"); 231 - Assert.IsFalse(func.Meta[PFunction.VolatileKey].Switch, 232 - functionId + " must not be volatile."); 233 - } 234 - 235 - [Test, ExpectedException(typeof (PrexoniteRuntimeException))] 236 - public void TryFinallyCondCompiles() 237 - { 238 - Compile( 239 - @" 240 - var t = """"; 241 - function trace(x) = t+=x; 242 - 243 - function main(x) 244 - { 245 - try { 246 - trace(""t""); 247 - if(x) 248 - throw ""e""; 249 - }finally{ 250 - trace(""f""); 251 - } 252 - 253 - return t; 254 - } 255 - "); 256 - _expectCil(); 257 - Expect("tf", true); 258 - } 259 - 260 - [Test] 261 - public void TryCatchCondCompiles() 262 - { 263 - Compile( 264 - @" 265 - var t = """"; 266 - function trace(x) = t+=x; 267 - 268 - function main(x) 269 - { 270 - try { 271 - trace(""t""); 272 - if(x) 273 - throw ""e""; 274 - }catch(var exc){ 275 - trace(""c""); 276 - trace(exc.Message); 277 - } 278 - 279 - return t; 280 - } 281 - "); 282 - _expectCil(); 283 - Expect("tce", true); 284 - } 285 - 286 - [Test] 287 - public void CatchInFinally1() 288 - { 289 - Compile( 290 - @" 291 - var t = """"; 292 - function trace(x) = t+=x; 293 - 294 - function main(x) 295 - { 296 - try { 297 - try { 298 - trace(""t""); 299 - if(x) 300 - throw ""e""; 301 - }catch(var exc){ 302 - trace(""c""); 303 - trace(exc.Message); 304 - } 305 - } finally { 306 - trace(""f""); 307 - } 308 - 309 - return t; 310 - } 311 - "); 312 - _expectCil(); 313 - Expect("tcef", true); 314 - } 315 - 316 - [Test] 317 - public void CatchInFinally2() 318 - { 319 - Compile( 320 - @" 321 - var t = """"; 322 - function trace(x) = t+=x; 323 - 324 - function main(x) 325 - { 326 - try { 327 - try { 328 - trace(""t""); 329 - throw ""e""; 330 - }catch(var exc){ 331 - if(x) 332 - trace(""x""); 333 - } 334 - } finally { 335 - trace(""f""); 336 - } 337 - 338 - return t; 339 - } 340 - "); 341 - 342 - _expectCil(); 343 - Expect("txf", true); 344 - } 345 - 346 - [Test] 347 - public void CatchInFinally3() 348 - { 349 - Compile( 350 - @" 351 - var t = """"; 352 - function trace(x) = t+=x; 353 - 354 - function main(x) 355 - { 356 - try { 357 - try { 358 - trace(""t""); 359 - throw ""e""; 360 - }catch(var exc){ 361 - if(x) 362 - trace(""x""); 363 - } 364 - } catch(var exc){ 365 - trace(""e""); 366 - } finally { 367 - trace(""f""); 368 - } 369 - 370 - return t; 371 - } 372 - "); 373 - _expectCil(); 374 - Expect("txf", true); 375 - } 376 - 377 - [Test] 378 - public void CatchInFinally4() 379 - { 380 - Compile( 381 - @" 382 - var t = """"; 383 - function trace(x) = t+=x; 384 - 385 - function main(x) [store_debug_implementation enabled;] 386 - { 387 - for(var i = 1; i < 6; i++) 388 - try 389 - { 390 - try 391 - { 392 - throw i; 393 - } 394 - catch(var exc) 395 - { 396 - if(x) 397 - throw exc; 398 - } 399 - } 400 - catch(var exc) 401 - { 402 - trace(""e""); 403 - } 404 - finally 405 - { 406 - trace(""f""); 407 - } 408 - return t; 409 - } 410 - "); 411 - _expectCil(); 412 - Expect("fefefefefe", true); 413 - } 414 - 415 - [Test] 416 - public void CatchInFinally5() 417 - { 418 - Compile( 419 - @" 420 - var t = """"; 421 - function trace(x) = t+=x; 422 - 423 - function main(x,y) [store_debug_implementation enabled;] 424 - { 425 - try 426 - { 427 - try 428 - { 429 - throw ""i""; //this must be a throw; won't work with trace 430 - } 431 - catch(var exc) 432 - { 433 - if(not x) //needs to be false (it's a runtime error after all) 434 - throw exc; 435 - } 436 - } //must be a nested block 437 - finally 438 - { 439 - trace(""f""); 440 - } 441 - return t; 442 - } 443 - "); 444 - _expectCil(); 445 - Expect("f", true, true); 446 - } 447 - 448 - [Test] 449 - public void TryCatchFinallyCondCompiles() 450 - { 451 - Compile( 452 - @" 453 - var t = """"; 454 - function trace(x) = t+=x; 455 - 456 - function main(x) //[store_debug_implementation enabled;] 457 - { 458 - try { 459 - trace(""t""); 460 - if(x) 461 - throw ""e""; 462 - }catch(var exc){ 463 - trace(""c""); 464 - trace(exc.Message); 465 - }finally{ 466 - trace(""f""); 467 - } 468 - 469 - return t; 470 - } 471 - "); 472 - _expectCil(); 473 - Expect("tfce", true); 474 - } 475 - 476 - [Test, 477 - ExpectedException(typeof (PrexoniteRuntimeException), 478 - ExpectedMessage = 479 - @"Unexpected leave instruction. This happens when jumping to an instruction in a try block from the outside." 480 - )] 481 - public void LabelOnFirstNeLabelOnTry() 482 - { 483 - Compile( 484 - @" 485 - var t = """"; 486 - function trace(x) = t+=x; 487 - 488 - function main(x) //[store_debug_implementation enabled;] 489 - { 490 - try { 491 - trace(""t""); 492 - goto L1; 493 - trace(""z""); 494 - } finally { 495 - trace(""f""); 496 - } 497 - 498 - try { 499 - trace(""g""); 500 - try { 501 - L1: trace(""b""); 502 - } finally { 503 - trace(""r""); 504 - } 505 - } finally { 506 - trace(""v""); 507 - } 508 - 509 - return t; 510 - } 511 - "); 512 - _expectSehDeficiency(); 513 - Expect("undefined", true); 514 - } 515 - 516 - [Test] 517 - public void TryFinallyShadowingNoBridge() 518 - { 519 - Compile( 520 - @" 521 - var t = """"; 522 - function trace(x) = t+=x; 523 - 524 - //This tets is expected not to compile to CIL 525 - function main(x) //[store_debug_implementation enabled;] 526 - { 527 - try { 528 - trace(""t""); 529 - goto L1; 530 - trace(""z""); 531 - } finally { 532 - trace(""f""); 533 - } 534 - 535 - try { 536 - trace(""g""); 537 - L1: try { 538 - trace(""b""); 539 - } finally { 540 - trace(""r""); 541 - } 542 - } finally { 543 - trace(""v""); 544 - } 545 - 546 - return t; 547 - } 548 - "); 549 - _expectSehDeficiency(); 550 - Expect("tbrv", true); 551 - } 552 - 553 - [Test] 554 - public void TryFinallyShadowingBridge() 555 - { 556 - Compile( 557 - @" 558 - var t = """"; 559 - function trace(x) = t+=x; 560 - 561 - function main(x) //[store_debug_implementation enabled;] 562 - { 563 - try { 564 - trace(""k""); 565 - try { 566 - trace(""t""); 567 - goto L1; 568 - trace(""z""); 569 - } finally { 570 - trace(""f""); 571 - } 572 - 573 - trace(""g""); 574 - L1: try { 575 - trace(""b""); 576 - } finally { 577 - trace(""r""); 578 - } 579 - } finally { 580 - trace(""v""); 581 - } 582 - 583 - return t; 584 - } 585 - "); 586 - _expectCil(); 587 - Expect("ktfbrv", true); 588 - } 589 - 590 - [Test] 591 - public void ReturnFromFinally() 592 - { 593 - Compile( 594 - @" 595 - var t = """"; 596 - function trace(x) = t+=x; 597 - 598 - function main(x) //[store_debug_implementation enabled;] 599 - { 600 - try { 601 - trace(""k""); 602 - } finally { 603 - trace(""f""); 604 - return t; 605 - trace(""v""); 606 - } 607 - 608 - return t; 609 - } 610 - "); 611 - _expectSehDeficiency(); 612 - Expect("kf", true); 613 - } 614 - 615 - private void _expectSehDeficiency(string name = "main") 616 - { 617 - _expectSehDeficiency(target.Functions[name]); 618 - } 619 - 620 - private static void _expectSehDeficiency(PFunction function) 621 - { 622 - Assert.IsNotNull(function, "function not found"); 623 - Assert.IsTrue(function.Meta[PFunction.VolatileKey].Switch, 624 - "Function is expected to be volatile."); 625 - Assert.IsTrue(function.Meta[PFunction.DeficiencyKey].Text.Contains("SEH"), 626 - "CIL deficiency is expected to be related to SEH."); 627 - } 628 - 629 - [Test] 630 - public void MinimalTryCatch() 631 - { 632 - Compile( 633 - @" 634 - var t; 635 - function trace(x) = t+=x~String; 636 - function main(x) [store_debug_implementation enabled;] 637 - { 638 - try {trace(1);} 639 - finally{trace(2);} 640 - return t; 641 - }"); 642 - 643 - Expect("12", true); 644 - } 645 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System.Collections.Generic; 27 + using System.Linq; 28 + using NUnit.Framework; 29 + using Prexonite; 30 + using Prexonite.Compiler; 31 + using Prexonite.Compiler.Cil; 32 + 33 + namespace PrexoniteTests.Tests 34 + { 35 + [TestFixture] 36 + public class CilCompilerTests : VMTestsBase 37 + { 38 + [Test] 39 + public void SetCilHintTest() 40 + { 41 + Compile(@" 42 + function main() { 43 + foreach(var x in var args) 44 + println(x); 45 + }"); 46 + 47 + var main = target.Functions["main"]; 48 + 49 + var cilExt1 = new CilExtensionHint(new List<int> {1, 5, 9}); 50 + var existingHints = _getCilHints(main, true); 51 + Assert.AreEqual(1, existingHints.Length); 52 + 53 + //Add, none existing 54 + Compiler.SetCilHint(main, cilExt1); 55 + var hints1 = _getCilHints(main, true); 56 + Assert.AreNotSame(existingHints, hints1); 57 + Assert.AreEqual(2, hints1.Length); 58 + Assert.IsTrue(hints1[1].IsList); 59 + var cilExt1P = CilExtensionHint.FromMetaEntry(hints1[1].List); 60 + Assert.IsTrue( 61 + cilExt1P.Offsets.All(offset => cilExt1.Offsets.Contains(offset)), 62 + "deserialized contains elements not in original"); 63 + Assert.IsTrue(cilExt1.Offsets.All(offset => cilExt1P.Offsets.Contains(offset)), 64 + "original contains elements not in deserialized"); 65 + 66 + //Add, one existing 67 + var cilExt2 = new CilExtensionHint(new List<int> {2, 4, 8, 16}); 68 + Compiler.SetCilHint(main, cilExt2); 69 + var hints2 = _getCilHints(main, true); 70 + Assert.AreSame(hints1, hints2); 71 + Assert.AreEqual(2, hints2.Length); 72 + Assert.IsTrue(hints2[1].IsList); 73 + var cilExt2P = CilExtensionHint.FromMetaEntry(hints2[1].List); 74 + Assert.IsTrue( 75 + cilExt2P.Offsets.All(offset => cilExt2.Offsets.Contains(offset)), 76 + "deserialized contains elements not in original"); 77 + Assert.IsTrue(cilExt2.Offsets.All(offset => cilExt2P.Offsets.Contains(offset)), 78 + "original contains elements not in deserialized"); 79 + 80 + //Add, many existing 81 + var cilExts = new List<CilExtensionHint> 82 + { 83 + new CilExtensionHint(new List<int> {1, 6, 16, 66}), 84 + new CilExtensionHint(new List<int> {7, 77, 777}), 85 + new CilExtensionHint(new List<int> {9, 88, 777, 6666}), 86 + }; 87 + foreach (var cilExt in cilExts) 88 + Compiler.AddCilHint(main, cilExt); 89 + var hints3 = _getCilHints(main, true); 90 + Assert.AreNotSame(hints2, hints3); 91 + Assert.AreEqual(5, hints3.Length); 92 + var cilExt3 = new CilExtensionHint(new List<int> {44, 55, 66, 77, 88}); 93 + Compiler.SetCilHint(main, cilExt3); 94 + var hints4 = _getCilHints(main, true); 95 + Assert.AreNotSame(hints3, hints4); 96 + Assert.AreEqual(2, hints4.Length); 97 + Assert.IsTrue(hints4[1].IsList); 98 + var cilExt3P = CilExtensionHint.FromMetaEntry(hints4[1].List); 99 + Assert.IsTrue( 100 + cilExt3P.Offsets.All(offset => cilExt3.Offsets.Contains(offset)), 101 + "deserialized contains elements not in original"); 102 + Assert.IsTrue(cilExt3.Offsets.All(offset => cilExt3P.Offsets.Contains(offset)), 103 + "original contains elements not in deserialized"); 104 + 105 + 106 + //Add, no cil hints key yet 107 + var emptyFunc = target.CreateFunction(); 108 + emptyFunc.Meta[PFunction.IdKey] = "empty"; 109 + Compiler.SetCilHint(main, cilExt3); 110 + var hints5 = _getCilHints(main, true); 111 + Assert.AreEqual(2, hints5.Length); 112 + Assert.IsTrue(hints5[0].IsList); 113 + var cilExt4P = CilExtensionHint.FromMetaEntry(hints5[1].List); 114 + Assert.IsTrue( 115 + cilExt4P.Offsets.All(offset => cilExt3.Offsets.Contains(offset)), 116 + "deserialized contains elements not in original"); 117 + Assert.IsTrue(cilExt3.Offsets.All(offset => cilExt4P.Offsets.Contains(offset)), 118 + "original contains elements not in deserialized"); 119 + } 120 + 121 + private static MetaEntry[] _getCilHints(IHasMetaTable table, bool keyMustExist) 122 + { 123 + MetaEntry cilHintsEntry; 124 + if (table.Meta.TryGetValue(Loader.CilHintsKey, out cilHintsEntry)) 125 + { 126 + Assert.IsTrue(cilHintsEntry.IsList, "CIL hints entry must be a list."); 127 + return cilHintsEntry.List; 128 + } 129 + else if (keyMustExist) 130 + { 131 + Assert.Fail("Meta table of {0} does not contain cil hints.", table); 132 + return null; 133 + } 134 + else 135 + { 136 + table.Meta[Loader.CilHintsKey] = (MetaEntry) new MetaEntry[0]; 137 + return _getCilHints(table, true); 138 + } 139 + } 140 + 141 + [Test] 142 + public void UnbindCommandTest() 143 + { 144 + Compile( 145 + @" 146 + function main() 147 + { 148 + var result = []; 149 + var x = 1; 150 + ref y = ->x; 151 + result[] = x == 1; 152 + result[] = ->x == ->y; 153 + new var x; 154 + result[] = x == 1; 155 + result[] = not System::Object.ReferenceEquals(->x, ->y); 156 + 157 + result[] = var x == new var x; 158 + result[] = x == 1; 159 + result[] = not System::Object.ReferenceEquals(->x, ->y); 160 + 161 + //behave like ordinary command 162 + result[] = unbind(->x) is null; 163 + result[] = x == 1; 164 + result[] = not System::Object.ReferenceEquals(->x, ->y); 165 + 166 + return result; 167 + } 168 + "); 169 + _expectCil(); 170 + Expect(Enumerable.Range(1, 10).Select(_ => (PValue) true).ToList()); 171 + } 172 + 173 + 174 + [Test] 175 + public void JumpBreaksCilExtensions() 176 + { 177 + Compile( 178 + @" 179 + function main(b) 180 + {asm{ 181 + ldloc b 182 + ldc.int 4 183 + cmd.2 (==) 184 + jump.f L_else 185 + label L_if ldc.string ""IF"" 186 + jump L_endif 187 + label L_else ldc.string ""ELSE"" 188 + label L_endif ldc.string ""-branch"" 189 + cmd.2 (+) 190 + ret 191 + }} 192 + "); 193 + Assert.AreEqual(1, _getCilHints(target.Functions["main"], true).Length); 194 + _expectCil(); 195 + Expect("IF-branch", 4); 196 + Expect("ELSE-branch", 3); 197 + Expect("ELSE-branch", 5); 198 + } 199 + 200 + [Test] 201 + public void TryCatchFinallyCompiles() 202 + { 203 + Compile( 204 + @" 205 + var t = """"; 206 + function trace(x) = t+=x; 207 + 208 + function main() 209 + { 210 + try { 211 + trace(""t""); 212 + throw ""e""; 213 + }catch(var exc){ 214 + trace(""c""); 215 + trace(exc.Message); 216 + }finally{ 217 + trace(""f""); 218 + } 219 + 220 + return t; 221 + } 222 + "); 223 + _expectCil(); 224 + Expect("tfce"); 225 + } 226 + 227 + private void _expectCil(string functionId = "main") 228 + { 229 + var func = target.Functions[functionId]; 230 + Assert.IsNotNull(func, "Function " + functionId + " must exist"); 231 + Assert.IsFalse(func.Meta[PFunction.VolatileKey].Switch, 232 + functionId + " must not be volatile."); 233 + } 234 + 235 + [Test] 236 + public void TryFinallyCondCompiles() 237 + { 238 + Assert.Throws<PrexoniteRuntimeException>(() => 239 + { 240 + Compile( 241 + @" 242 + var t = """"; 243 + function trace(x) = t+=x; 244 + 245 + function main(x) 246 + { 247 + try { 248 + trace(""t""); 249 + if(x) 250 + throw ""e""; 251 + }finally{ 252 + trace(""f""); 253 + } 254 + 255 + return t; 256 + } 257 + "); 258 + _expectCil(); 259 + Expect("tf", true); 260 + }); 261 + } 262 + 263 + [Test] 264 + public void TryCatchCondCompiles() 265 + { 266 + Compile( 267 + @" 268 + var t = """"; 269 + function trace(x) = t+=x; 270 + 271 + function main(x) 272 + { 273 + try { 274 + trace(""t""); 275 + if(x) 276 + throw ""e""; 277 + }catch(var exc){ 278 + trace(""c""); 279 + trace(exc.Message); 280 + } 281 + 282 + return t; 283 + } 284 + "); 285 + _expectCil(); 286 + Expect("tce", true); 287 + } 288 + 289 + [Test] 290 + public void CatchInFinally1() 291 + { 292 + Compile( 293 + @" 294 + var t = """"; 295 + function trace(x) = t+=x; 296 + 297 + function main(x) 298 + { 299 + try { 300 + try { 301 + trace(""t""); 302 + if(x) 303 + throw ""e""; 304 + }catch(var exc){ 305 + trace(""c""); 306 + trace(exc.Message); 307 + } 308 + } finally { 309 + trace(""f""); 310 + } 311 + 312 + return t; 313 + } 314 + "); 315 + _expectCil(); 316 + Expect("tcef", true); 317 + } 318 + 319 + [Test] 320 + public void CatchInFinally2() 321 + { 322 + Compile( 323 + @" 324 + var t = """"; 325 + function trace(x) = t+=x; 326 + 327 + function main(x) 328 + { 329 + try { 330 + try { 331 + trace(""t""); 332 + throw ""e""; 333 + }catch(var exc){ 334 + if(x) 335 + trace(""x""); 336 + } 337 + } finally { 338 + trace(""f""); 339 + } 340 + 341 + return t; 342 + } 343 + "); 344 + 345 + _expectCil(); 346 + Expect("txf", true); 347 + } 348 + 349 + [Test] 350 + public void CatchInFinally3() 351 + { 352 + Compile( 353 + @" 354 + var t = """"; 355 + function trace(x) = t+=x; 356 + 357 + function main(x) 358 + { 359 + try { 360 + try { 361 + trace(""t""); 362 + throw ""e""; 363 + }catch(var exc){ 364 + if(x) 365 + trace(""x""); 366 + } 367 + } catch(var exc){ 368 + trace(""e""); 369 + } finally { 370 + trace(""f""); 371 + } 372 + 373 + return t; 374 + } 375 + "); 376 + _expectCil(); 377 + Expect("txf", true); 378 + } 379 + 380 + [Test] 381 + public void CatchInFinally4() 382 + { 383 + Compile( 384 + @" 385 + var t = """"; 386 + function trace(x) = t+=x; 387 + 388 + function main(x) [store_debug_implementation enabled;] 389 + { 390 + for(var i = 1; i < 6; i++) 391 + try 392 + { 393 + try 394 + { 395 + throw i; 396 + } 397 + catch(var exc) 398 + { 399 + if(x) 400 + throw exc; 401 + } 402 + } 403 + catch(var exc) 404 + { 405 + trace(""e""); 406 + } 407 + finally 408 + { 409 + trace(""f""); 410 + } 411 + return t; 412 + } 413 + "); 414 + _expectCil(); 415 + Expect("fefefefefe", true); 416 + } 417 + 418 + [Test] 419 + public void CatchInFinally5() 420 + { 421 + Compile( 422 + @" 423 + var t = """"; 424 + function trace(x) = t+=x; 425 + 426 + function main(x,y) [store_debug_implementation enabled;] 427 + { 428 + try 429 + { 430 + try 431 + { 432 + throw ""i""; //this must be a throw; won't work with trace 433 + } 434 + catch(var exc) 435 + { 436 + if(not x) //needs to be false (it's a runtime error after all) 437 + throw exc; 438 + } 439 + } //must be a nested block 440 + finally 441 + { 442 + trace(""f""); 443 + } 444 + return t; 445 + } 446 + "); 447 + _expectCil(); 448 + Expect("f", true, true); 449 + } 450 + 451 + [Test] 452 + public void TryCatchFinallyCondCompiles() 453 + { 454 + Compile( 455 + @" 456 + var t = """"; 457 + function trace(x) = t+=x; 458 + 459 + function main(x) //[store_debug_implementation enabled;] 460 + { 461 + try { 462 + trace(""t""); 463 + if(x) 464 + throw ""e""; 465 + }catch(var exc){ 466 + trace(""c""); 467 + trace(exc.Message); 468 + }finally{ 469 + trace(""f""); 470 + } 471 + 472 + return t; 473 + } 474 + "); 475 + _expectCil(); 476 + Expect("tfce", true); 477 + } 478 + 479 + [Test] 480 + public void LabelOnFirstNeLabelOnTry() 481 + { 482 + Assert.Throws<PrexoniteRuntimeException>(() => 483 + { 484 + Compile( 485 + @" 486 + var t = """"; 487 + function trace(x) = t+=x; 488 + 489 + function main(x) //[store_debug_implementation enabled;] 490 + { 491 + try { 492 + trace(""t""); 493 + goto L1; 494 + trace(""z""); 495 + } finally { 496 + trace(""f""); 497 + } 498 + 499 + try { 500 + trace(""g""); 501 + try { 502 + L1: trace(""b""); 503 + } finally { 504 + trace(""r""); 505 + } 506 + } finally { 507 + trace(""v""); 508 + } 509 + 510 + return t; 511 + } 512 + "); 513 + _expectSehDeficiency(); 514 + Expect("undefined", true); 515 + }, @"Unexpected leave instruction. This happens when jumping to an instruction in a try block from the outside."); 516 + } 517 + 518 + [Test] 519 + public void TryFinallyShadowingNoBridge() 520 + { 521 + Compile( 522 + @" 523 + var t = """"; 524 + function trace(x) = t+=x; 525 + 526 + //This tets is expected not to compile to CIL 527 + function main(x) //[store_debug_implementation enabled;] 528 + { 529 + try { 530 + trace(""t""); 531 + goto L1; 532 + trace(""z""); 533 + } finally { 534 + trace(""f""); 535 + } 536 + 537 + try { 538 + trace(""g""); 539 + L1: try { 540 + trace(""b""); 541 + } finally { 542 + trace(""r""); 543 + } 544 + } finally { 545 + trace(""v""); 546 + } 547 + 548 + return t; 549 + } 550 + "); 551 + _expectSehDeficiency(); 552 + Expect("tbrv", true); 553 + } 554 + 555 + [Test] 556 + public void TryFinallyShadowingBridge() 557 + { 558 + Compile( 559 + @" 560 + var t = """"; 561 + function trace(x) = t+=x; 562 + 563 + function main(x) //[store_debug_implementation enabled;] 564 + { 565 + try { 566 + trace(""k""); 567 + try { 568 + trace(""t""); 569 + goto L1; 570 + trace(""z""); 571 + } finally { 572 + trace(""f""); 573 + } 574 + 575 + trace(""g""); 576 + L1: try { 577 + trace(""b""); 578 + } finally { 579 + trace(""r""); 580 + } 581 + } finally { 582 + trace(""v""); 583 + } 584 + 585 + return t; 586 + } 587 + "); 588 + _expectCil(); 589 + Expect("ktfbrv", true); 590 + } 591 + 592 + [Test] 593 + public void ReturnFromFinally() 594 + { 595 + Compile( 596 + @" 597 + var t = """"; 598 + function trace(x) = t+=x; 599 + 600 + function main(x) //[store_debug_implementation enabled;] 601 + { 602 + try { 603 + trace(""k""); 604 + } finally { 605 + trace(""f""); 606 + return t; 607 + trace(""v""); 608 + } 609 + 610 + return t; 611 + } 612 + "); 613 + _expectSehDeficiency(); 614 + Expect("kf", true); 615 + } 616 + 617 + private void _expectSehDeficiency(string name = "main") 618 + { 619 + _expectSehDeficiency(target.Functions[name]); 620 + } 621 + 622 + private static void _expectSehDeficiency(PFunction function) 623 + { 624 + Assert.IsNotNull(function, "function not found"); 625 + Assert.IsTrue(function.Meta[PFunction.VolatileKey].Switch, 626 + "Function is expected to be volatile."); 627 + Assert.IsTrue(function.Meta[PFunction.DeficiencyKey].Text.Contains("SEH"), 628 + "CIL deficiency is expected to be related to SEH."); 629 + } 630 + 631 + [Test] 632 + public void MinimalTryCatch() 633 + { 634 + Compile( 635 + @" 636 + var t; 637 + function trace(x) = t+=x~String; 638 + function main(x) [store_debug_implementation enabled;] 639 + { 640 + try {trace(1);} 641 + finally{trace(2);} 642 + return t; 643 + }"); 644 + 645 + Expect("12", true); 646 + } 647 + } 646 648 }
+559 -559
PrexoniteTests/Tests/Configurations/PsrUnitTests.cs
··· 1 -  2 - // ReSharper disable RedundantUsingDirective 3 - using System; 4 - using System.Reflection; 5 - using System.Collections.Generic; 6 - using Prexonite.Types; 7 - using Prexonite.Compiler.Cil; 8 - using NUnit.Framework; 9 - // ReSharper restore RedundantUsingDirective 10 - 11 - // ReSharper disable RedundantExplicitArrayCreation 12 - // ReSharper disable InconsistentNaming 13 - // ReSharper disable RedundantCommaInArrayInitializer 14 - 15 - namespace PrexoniteTests.Tests.Configurations 16 - { 17 - internal abstract class Unit_ast : ScriptedUnitTestContainer 18 - { 19 - [TestFixtureSetUp] 20 - public void SetupTestFile() 21 - { 22 - var model = new TestModel 23 - { 24 - TestSuiteScript = @".\ast.test.pxs", 25 - UnitsUnderTest = new TestDependency[]{ 26 - new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 27 - }}, 28 - 29 - }, 30 - TestDependencies = new TestDependency[]{ 31 - 32 - } 33 - }; 34 - Initialize(); 35 - Runner.Configure(model, this); 36 - } 37 - 38 - [Test] 39 - public void compiler_is_loaded() 40 - { 41 - RunUnitTest(@"compiler_is_loaded"); 42 - } 43 - [Test] 44 - public void test_ast_withpos_null() 45 - { 46 - RunUnitTest(@"test_ast_withpos_null"); 47 - } 48 - [Test] 49 - public void test_ast_withpos_memcall() 50 - { 51 - RunUnitTest(@"test_ast_withpos_memcall"); 52 - } 53 - [Test] 54 - public void test_ast_simple_memcall() 55 - { 56 - RunUnitTest(@"test_ast_simple_memcall"); 57 - } 58 - [Test] 59 - public void test_ast_memcall() 60 - { 61 - RunUnitTest(@"test_ast_memcall"); 62 - } 63 - [Test] 64 - public void test_unique_id_counter() 65 - { 66 - RunUnitTest(@"test_unique_id_counter"); 67 - } 68 - [Test] 69 - public void test_is_member_access() 70 - { 71 - RunUnitTest(@"test_is_member_access"); 72 - } 73 - [Test] 74 - public void test_local_meta() 75 - { 76 - RunUnitTest(@"test_local_meta"); 77 - } 78 - [Test] 79 - public void test_si_fields() 80 - { 81 - RunUnitTest(@"test_si_fields"); 82 - } 83 - [Test] 84 - public void test_si_is_star() 85 - { 86 - RunUnitTest(@"test_si_is_star"); 87 - } 88 - [Test] 89 - public void test_si_make_star() 90 - { 91 - RunUnitTest(@"test_si_make_star"); 92 - } 93 - [Test] 94 - public void test_si_m_is_star() 95 - { 96 - RunUnitTest(@"test_si_m_is_star"); 97 - } 98 - [Test] 99 - public void test_sub_blocks() 100 - { 101 - RunUnitTest(@"test_sub_blocks"); 102 - } 103 - } 104 - internal abstract class Unit_lang_ext : ScriptedUnitTestContainer 105 - { 106 - [TestFixtureSetUp] 107 - public void SetupTestFile() 108 - { 109 - var model = new TestModel 110 - { 111 - TestSuiteScript = @".\lang-ext.test.pxs", 112 - UnitsUnderTest = new TestDependency[]{ 113 - new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 114 - }}, 115 - new TestDependency { ScriptName = @"psr\impl\macro.pxs", Dependencies = new string[] { 116 - @"psr\impl\ast.pxs", 117 - }}, 118 - new TestDependency { ScriptName = @"psr\impl\struct.pxs", Dependencies = new string[] { 119 - @"psr\impl\ast.pxs", 120 - @"psr\impl\macro.pxs", 121 - }}, 122 - new TestDependency { ScriptName = @"psr\impl\pattern.pxs", Dependencies = new string[] { 123 - @"psr\impl\ast.pxs", 124 - @"psr\impl\macro.pxs", 125 - @"psr\impl\struct.pxs", 126 - }}, 127 - new TestDependency { ScriptName = @"psr\impl\prop.pxs", Dependencies = new string[] { 128 - @"psr\impl\ast.pxs", 129 - @"psr\impl\macro.pxs", 130 - }}, 131 - 132 - }, 133 - TestDependencies = new TestDependency[]{ 134 - new TestDependency { ScriptName = @"psr\test\meta_macro.pxs", Dependencies = new string[] { 135 - PrexoniteUnitTestFramework 136 - }}, 137 - 138 - } 139 - }; 140 - Initialize(); 141 - Runner.Configure(model, this); 142 - } 143 - 144 - [Test] 145 - public void test_con() 146 - { 147 - RunUnitTest(@"test_con"); 148 - } 149 - [Test] 150 - public void test_dcon() 151 - { 152 - RunUnitTest(@"test_dcon"); 153 - } 154 - [Test] 155 - public void test_prop_simple() 156 - { 157 - RunUnitTest(@"test_prop_simple"); 158 - } 159 - [Test] 160 - public void test_prop_proxy() 161 - { 162 - RunUnitTest(@"test_prop_proxy"); 163 - } 164 - [Test] 165 - public void test_prop_complex() 166 - { 167 - RunUnitTest(@"test_prop_complex"); 168 - } 169 - [Test] 170 - public void test_prop_simple_glob() 171 - { 172 - RunUnitTest(@"test_prop_simple_glob"); 173 - } 174 - } 175 - internal abstract class Unit_macro : ScriptedUnitTestContainer 176 - { 177 - [TestFixtureSetUp] 178 - public void SetupTestFile() 179 - { 180 - var model = new TestModel 181 - { 182 - TestSuiteScript = @".\macro.test.pxs", 183 - UnitsUnderTest = new TestDependency[]{ 184 - new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 185 - }}, 186 - new TestDependency { ScriptName = @"psr\impl\macro.pxs", Dependencies = new string[] { 187 - @"psr\impl\ast.pxs", 188 - }}, 189 - 190 - }, 191 - TestDependencies = new TestDependency[]{ 192 - new TestDependency { ScriptName = @"psr\test\meta_macro.pxs", Dependencies = new string[] { 193 - PrexoniteUnitTestFramework 194 - }}, 195 - 196 - } 197 - }; 198 - Initialize(); 199 - Runner.Configure(model, this); 200 - } 201 - 202 - [Test] 203 - public void test_file() 204 - { 205 - RunUnitTest(@"test_file"); 206 - } 207 - [Test] 208 - public void test_pos() 209 - { 210 - RunUnitTest(@"test_pos"); 211 - } 212 - [Test] 213 - public void test_is_in_macro() 214 - { 215 - RunUnitTest(@"test_is_in_macro"); 216 - } 217 - [Test] 218 - public void test_establish_macro_context() 219 - { 220 - RunUnitTest(@"test_establish_macro_context"); 221 - } 222 - [Test] 223 - public void test_reports() 224 - { 225 - RunUnitTest(@"test_reports"); 226 - } 227 - [Test] 228 - public void test_ast_is_expression() 229 - { 230 - RunUnitTest(@"test_ast_is_expression"); 231 - } 232 - [Test] 233 - public void test_ast_is_effect() 234 - { 235 - RunUnitTest(@"test_ast_is_effect"); 236 - } 237 - [Test] 238 - public void test_ast_is_partially_applicable() 239 - { 240 - RunUnitTest(@"test_ast_is_partially_applicable"); 241 - } 242 - [Test] 243 - public void test_ast_is_partial_application() 244 - { 245 - RunUnitTest(@"test_ast_is_partial_application"); 246 - } 247 - [Test] 248 - public void test_ast_is_CreateClosure() 249 - { 250 - RunUnitTest(@"test_ast_is_CreateClosure"); 251 - } 252 - [Test] 253 - public void test_ast_is_node() 254 - { 255 - RunUnitTest(@"test_ast_is_node"); 256 - } 257 - [Test] 258 - public void test_temp() 259 - { 260 - RunUnitTest(@"test_temp"); 261 - } 262 - [Test] 263 - public void test_optimize() 264 - { 265 - RunUnitTest(@"test_optimize"); 266 - } 267 - [Test] 268 - public void test_read() 269 - { 270 - RunUnitTest(@"test_read"); 271 - } 272 - [Test] 273 - public void test_macro_internal_id_static() 274 - { 275 - RunUnitTest(@"test_macro_internal_id_static"); 276 - } 277 - [Test] 278 - public void test_macro_internal_id() 279 - { 280 - RunUnitTest(@"test_macro_internal_id"); 281 - } 282 - [Test] 283 - public void test_macro_entity_static() 284 - { 285 - RunUnitTest(@"test_macro_entity_static"); 286 - } 287 - [Test] 288 - public void test_expand_macro() 289 - { 290 - RunUnitTest(@"test_expand_macro"); 291 - } 292 - [Test] 293 - public void test_ast_symbol() 294 - { 295 - RunUnitTest(@"test_ast_symbol"); 296 - } 297 - [Test] 298 - public void test_ast_member() 299 - { 300 - RunUnitTest(@"test_ast_member"); 301 - } 302 - [Test] 303 - public void test_ast_const() 304 - { 305 - RunUnitTest(@"test_ast_const"); 306 - } 307 - [Test] 308 - public void test_ast_ret() 309 - { 310 - RunUnitTest(@"test_ast_ret"); 311 - } 312 - [Test] 313 - public void test_ast_with_arguments() 314 - { 315 - RunUnitTest(@"test_ast\with_arguments"); 316 - } 317 - [Test] 318 - public void test_ast_new() 319 - { 320 - RunUnitTest(@"test_ast\new"); 321 - } 322 - [Test] 323 - public void test_ast_null() 324 - { 325 - RunUnitTest(@"test_ast\null"); 326 - } 327 - } 328 - internal abstract class Unit_misc : ScriptedUnitTestContainer 329 - { 330 - [TestFixtureSetUp] 331 - public void SetupTestFile() 332 - { 333 - var model = new TestModel 334 - { 335 - TestSuiteScript = @".\misc.test.pxs", 336 - UnitsUnderTest = new TestDependency[]{ 337 - new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 338 - }}, 339 - new TestDependency { ScriptName = @"psr\impl\macro.pxs", Dependencies = new string[] { 340 - @"psr\impl\ast.pxs", 341 - }}, 342 - new TestDependency { ScriptName = @"psr\impl\struct.pxs", Dependencies = new string[] { 343 - @"psr\impl\ast.pxs", 344 - @"psr\impl\macro.pxs", 345 - }}, 346 - new TestDependency { ScriptName = @"psr\impl\misc.pxs", Dependencies = new string[] { 347 - @"psr\impl\struct.pxs", 348 - @"psr\impl\ast.pxs", 349 - @"psr\impl\macro.pxs", 350 - }}, 351 - 352 - }, 353 - TestDependencies = new TestDependency[]{ 354 - 355 - } 356 - }; 357 - Initialize(); 358 - Runner.Configure(model, this); 359 - } 360 - 361 - [Test] 362 - public void test_cmp() 363 - { 364 - RunUnitTest(@"test_cmp"); 365 - } 366 - [Test] 367 - public void test_cmp_values() 368 - { 369 - RunUnitTest(@"test_cmp_values"); 370 - } 371 - [Test] 372 - public void test_cmp_keys() 373 - { 374 - RunUnitTest(@"test_cmp_keys"); 375 - } 376 - [Test] 377 - public void test_cmp_with() 378 - { 379 - RunUnitTest(@"test_cmp_with"); 380 - } 381 - [Test] 382 - public void test_cmp_then() 383 - { 384 - RunUnitTest(@"test_cmp_then"); 385 - } 386 - [Test] 387 - public void test_cmpr() 388 - { 389 - RunUnitTest(@"test_cmpr"); 390 - } 391 - [Test] 392 - public void test_ieq() 393 - { 394 - RunUnitTest(@"test_ieq"); 395 - } 396 - [Test] 397 - public void test_ieq_any() 398 - { 399 - RunUnitTest(@"test_ieq_any"); 400 - } 401 - [Test] 402 - public void test_ieq_all() 403 - { 404 - RunUnitTest(@"test_ieq_all"); 405 - } 406 - [Test] 407 - public void test_refeq() 408 - { 409 - RunUnitTest(@"test_refeq"); 410 - } 411 - [Test] 412 - public void test_nrefeq() 413 - { 414 - RunUnitTest(@"test_nrefeq"); 415 - } 416 - [Test] 417 - public void test_create_terminator() 418 - { 419 - RunUnitTest(@"test_create_terminator"); 420 - } 421 - [Test] 422 - public void test_swap() 423 - { 424 - RunUnitTest(@"test_swap"); 425 - } 426 - } 427 - internal abstract class Unit_struct : ScriptedUnitTestContainer 428 - { 429 - [TestFixtureSetUp] 430 - public void SetupTestFile() 431 - { 432 - var model = new TestModel 433 - { 434 - TestSuiteScript = @".\struct.test.pxs", 435 - UnitsUnderTest = new TestDependency[]{ 436 - new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 437 - }}, 438 - new TestDependency { ScriptName = @"psr\impl\macro.pxs", Dependencies = new string[] { 439 - @"psr\impl\ast.pxs", 440 - }}, 441 - new TestDependency { ScriptName = @"psr\impl\struct.pxs", Dependencies = new string[] { 442 - @"psr\impl\ast.pxs", 443 - @"psr\impl\macro.pxs", 444 - }}, 445 - new TestDependency { ScriptName = @"psr\impl\set.pxs", Dependencies = new string[] { 446 - @"psr\impl\struct.pxs", 447 - }}, 448 - new TestDependency { ScriptName = @"psr\impl\queue.pxs", Dependencies = new string[] { 449 - @"psr\impl\struct.pxs", 450 - }}, 451 - new TestDependency { ScriptName = @"psr\impl\stack.pxs", Dependencies = new string[] { 452 - @"psr\impl\struct.pxs", 453 - }}, 454 - 455 - }, 456 - TestDependencies = new TestDependency[]{ 457 - 458 - } 459 - }; 460 - Initialize(); 461 - Runner.Configure(model, this); 462 - } 463 - 464 - [Test] 465 - public void test_struct() 466 - { 467 - RunUnitTest(@"test_struct"); 468 - } 469 - [Test] 470 - public void tsm_create() 471 - { 472 - RunUnitTest(@"tsm_create"); 473 - } 474 - [Test] 475 - public void tsm_add_remove() 476 - { 477 - RunUnitTest(@"tsm_add_remove"); 478 - } 479 - [Test] 480 - public void tsi_create() 481 - { 482 - RunUnitTest(@"tsi_create"); 483 - } 484 - [Test] 485 - public void tsi_add_remove() 486 - { 487 - RunUnitTest(@"tsi_add_remove"); 488 - } 489 - [Test] 490 - public void tqm_count() 491 - { 492 - RunUnitTest(@"tqm_count"); 493 - } 494 - [Test] 495 - public void tqm_peek() 496 - { 497 - RunUnitTest(@"tqm_peek"); 498 - } 499 - [Test] 500 - public void tqm_dequeue() 501 - { 502 - RunUnitTest(@"tqm_dequeue"); 503 - } 504 - [Test] 505 - public void tqi_create() 506 - { 507 - RunUnitTest(@"tqi_create"); 508 - } 509 - [Test] 510 - public void tqi_enqueuedequeue() 511 - { 512 - RunUnitTest(@"tqi_enqueuedequeue"); 513 - } 514 - [Test] 515 - public void tqi_nonserial() 516 - { 517 - RunUnitTest(@"tqi_nonserial"); 518 - } 519 - [Test] 520 - public void tm_count() 521 - { 522 - RunUnitTest(@"tm_count"); 523 - } 524 - [Test] 525 - public void tm_peek() 526 - { 527 - RunUnitTest(@"tm_peek"); 528 - } 529 - [Test] 530 - public void tm_pop() 531 - { 532 - RunUnitTest(@"tm_pop"); 533 - } 534 - [Test] 535 - public void tm_enumarte_pops() 536 - { 537 - RunUnitTest(@"tm_enumarte_pops"); 538 - } 539 - [Test] 540 - public void ti_create() 541 - { 542 - RunUnitTest(@"ti_create"); 543 - } 544 - [Test] 545 - public void ti_pushpop() 546 - { 547 - RunUnitTest(@"ti_pushpop"); 548 - } 549 - [Test] 550 - public void ti_nonserial() 551 - { 552 - RunUnitTest(@"ti_nonserial"); 553 - } 554 - } 555 - } 556 - 557 - // ReSharper restore RedundantExplicitArrayCreation 558 - // ReSharper restore InconsistentNaming 559 - 1 +  2 + // ReSharper disable RedundantUsingDirective 3 + using System; 4 + using System.Reflection; 5 + using System.Collections.Generic; 6 + using Prexonite.Types; 7 + using Prexonite.Compiler.Cil; 8 + using NUnit.Framework; 9 + // ReSharper restore RedundantUsingDirective 10 + 11 + // ReSharper disable RedundantExplicitArrayCreation 12 + // ReSharper disable InconsistentNaming 13 + // ReSharper disable RedundantCommaInArrayInitializer 14 + 15 + namespace PrexoniteTests.Tests.Configurations 16 + { 17 + internal abstract class Unit_ast : ScriptedUnitTestContainer 18 + { 19 + [OneTimeSetUp] 20 + public void SetupTestFile() 21 + { 22 + var model = new TestModel 23 + { 24 + TestSuiteScript = @".\ast.test.pxs", 25 + UnitsUnderTest = new TestDependency[]{ 26 + new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 27 + }}, 28 + 29 + }, 30 + TestDependencies = new TestDependency[]{ 31 + 32 + } 33 + }; 34 + Initialize(); 35 + Runner.Configure(model, this); 36 + } 37 + 38 + [Test] 39 + public void compiler_is_loaded() 40 + { 41 + RunUnitTest(@"compiler_is_loaded"); 42 + } 43 + [Test] 44 + public void test_ast_withpos_null() 45 + { 46 + RunUnitTest(@"test_ast_withpos_null"); 47 + } 48 + [Test] 49 + public void test_ast_withpos_memcall() 50 + { 51 + RunUnitTest(@"test_ast_withpos_memcall"); 52 + } 53 + [Test] 54 + public void test_ast_simple_memcall() 55 + { 56 + RunUnitTest(@"test_ast_simple_memcall"); 57 + } 58 + [Test] 59 + public void test_ast_memcall() 60 + { 61 + RunUnitTest(@"test_ast_memcall"); 62 + } 63 + [Test] 64 + public void test_unique_id_counter() 65 + { 66 + RunUnitTest(@"test_unique_id_counter"); 67 + } 68 + [Test] 69 + public void test_is_member_access() 70 + { 71 + RunUnitTest(@"test_is_member_access"); 72 + } 73 + [Test] 74 + public void test_local_meta() 75 + { 76 + RunUnitTest(@"test_local_meta"); 77 + } 78 + [Test] 79 + public void test_si_fields() 80 + { 81 + RunUnitTest(@"test_si_fields"); 82 + } 83 + [Test] 84 + public void test_si_is_star() 85 + { 86 + RunUnitTest(@"test_si_is_star"); 87 + } 88 + [Test] 89 + public void test_si_make_star() 90 + { 91 + RunUnitTest(@"test_si_make_star"); 92 + } 93 + [Test] 94 + public void test_si_m_is_star() 95 + { 96 + RunUnitTest(@"test_si_m_is_star"); 97 + } 98 + [Test] 99 + public void test_sub_blocks() 100 + { 101 + RunUnitTest(@"test_sub_blocks"); 102 + } 103 + } 104 + internal abstract class Unit_lang_ext : ScriptedUnitTestContainer 105 + { 106 + [OneTimeSetUp] 107 + public void SetupTestFile() 108 + { 109 + var model = new TestModel 110 + { 111 + TestSuiteScript = @".\lang-ext.test.pxs", 112 + UnitsUnderTest = new TestDependency[]{ 113 + new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 114 + }}, 115 + new TestDependency { ScriptName = @"psr\impl\macro.pxs", Dependencies = new string[] { 116 + @"psr\impl\ast.pxs", 117 + }}, 118 + new TestDependency { ScriptName = @"psr\impl\struct.pxs", Dependencies = new string[] { 119 + @"psr\impl\ast.pxs", 120 + @"psr\impl\macro.pxs", 121 + }}, 122 + new TestDependency { ScriptName = @"psr\impl\pattern.pxs", Dependencies = new string[] { 123 + @"psr\impl\ast.pxs", 124 + @"psr\impl\macro.pxs", 125 + @"psr\impl\struct.pxs", 126 + }}, 127 + new TestDependency { ScriptName = @"psr\impl\prop.pxs", Dependencies = new string[] { 128 + @"psr\impl\ast.pxs", 129 + @"psr\impl\macro.pxs", 130 + }}, 131 + 132 + }, 133 + TestDependencies = new TestDependency[]{ 134 + new TestDependency { ScriptName = @"psr\test\meta_macro.pxs", Dependencies = new string[] { 135 + PrexoniteUnitTestFramework 136 + }}, 137 + 138 + } 139 + }; 140 + Initialize(); 141 + Runner.Configure(model, this); 142 + } 143 + 144 + [Test] 145 + public void test_con() 146 + { 147 + RunUnitTest(@"test_con"); 148 + } 149 + [Test] 150 + public void test_dcon() 151 + { 152 + RunUnitTest(@"test_dcon"); 153 + } 154 + [Test] 155 + public void test_prop_simple() 156 + { 157 + RunUnitTest(@"test_prop_simple"); 158 + } 159 + [Test] 160 + public void test_prop_proxy() 161 + { 162 + RunUnitTest(@"test_prop_proxy"); 163 + } 164 + [Test] 165 + public void test_prop_complex() 166 + { 167 + RunUnitTest(@"test_prop_complex"); 168 + } 169 + [Test] 170 + public void test_prop_simple_glob() 171 + { 172 + RunUnitTest(@"test_prop_simple_glob"); 173 + } 174 + } 175 + internal abstract class Unit_macro : ScriptedUnitTestContainer 176 + { 177 + [OneTimeSetUp] 178 + public void SetupTestFile() 179 + { 180 + var model = new TestModel 181 + { 182 + TestSuiteScript = @".\macro.test.pxs", 183 + UnitsUnderTest = new TestDependency[]{ 184 + new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 185 + }}, 186 + new TestDependency { ScriptName = @"psr\impl\macro.pxs", Dependencies = new string[] { 187 + @"psr\impl\ast.pxs", 188 + }}, 189 + 190 + }, 191 + TestDependencies = new TestDependency[]{ 192 + new TestDependency { ScriptName = @"psr\test\meta_macro.pxs", Dependencies = new string[] { 193 + PrexoniteUnitTestFramework 194 + }}, 195 + 196 + } 197 + }; 198 + Initialize(); 199 + Runner.Configure(model, this); 200 + } 201 + 202 + [Test] 203 + public void test_file() 204 + { 205 + RunUnitTest(@"test_file"); 206 + } 207 + [Test] 208 + public void test_pos() 209 + { 210 + RunUnitTest(@"test_pos"); 211 + } 212 + [Test] 213 + public void test_is_in_macro() 214 + { 215 + RunUnitTest(@"test_is_in_macro"); 216 + } 217 + [Test] 218 + public void test_establish_macro_context() 219 + { 220 + RunUnitTest(@"test_establish_macro_context"); 221 + } 222 + [Test] 223 + public void test_reports() 224 + { 225 + RunUnitTest(@"test_reports"); 226 + } 227 + [Test] 228 + public void test_ast_is_expression() 229 + { 230 + RunUnitTest(@"test_ast_is_expression"); 231 + } 232 + [Test] 233 + public void test_ast_is_effect() 234 + { 235 + RunUnitTest(@"test_ast_is_effect"); 236 + } 237 + [Test] 238 + public void test_ast_is_partially_applicable() 239 + { 240 + RunUnitTest(@"test_ast_is_partially_applicable"); 241 + } 242 + [Test] 243 + public void test_ast_is_partial_application() 244 + { 245 + RunUnitTest(@"test_ast_is_partial_application"); 246 + } 247 + [Test] 248 + public void test_ast_is_CreateClosure() 249 + { 250 + RunUnitTest(@"test_ast_is_CreateClosure"); 251 + } 252 + [Test] 253 + public void test_ast_is_node() 254 + { 255 + RunUnitTest(@"test_ast_is_node"); 256 + } 257 + [Test] 258 + public void test_temp() 259 + { 260 + RunUnitTest(@"test_temp"); 261 + } 262 + [Test] 263 + public void test_optimize() 264 + { 265 + RunUnitTest(@"test_optimize"); 266 + } 267 + [Test] 268 + public void test_read() 269 + { 270 + RunUnitTest(@"test_read"); 271 + } 272 + [Test] 273 + public void test_macro_internal_id_static() 274 + { 275 + RunUnitTest(@"test_macro_internal_id_static"); 276 + } 277 + [Test] 278 + public void test_macro_internal_id() 279 + { 280 + RunUnitTest(@"test_macro_internal_id"); 281 + } 282 + [Test] 283 + public void test_macro_entity_static() 284 + { 285 + RunUnitTest(@"test_macro_entity_static"); 286 + } 287 + [Test] 288 + public void test_expand_macro() 289 + { 290 + RunUnitTest(@"test_expand_macro"); 291 + } 292 + [Test] 293 + public void test_ast_symbol() 294 + { 295 + RunUnitTest(@"test_ast_symbol"); 296 + } 297 + [Test] 298 + public void test_ast_member() 299 + { 300 + RunUnitTest(@"test_ast_member"); 301 + } 302 + [Test] 303 + public void test_ast_const() 304 + { 305 + RunUnitTest(@"test_ast_const"); 306 + } 307 + [Test] 308 + public void test_ast_ret() 309 + { 310 + RunUnitTest(@"test_ast_ret"); 311 + } 312 + [Test] 313 + public void test_ast_with_arguments() 314 + { 315 + RunUnitTest(@"test_ast\with_arguments"); 316 + } 317 + [Test] 318 + public void test_ast_new() 319 + { 320 + RunUnitTest(@"test_ast\new"); 321 + } 322 + [Test] 323 + public void test_ast_null() 324 + { 325 + RunUnitTest(@"test_ast\null"); 326 + } 327 + } 328 + internal abstract class Unit_misc : ScriptedUnitTestContainer 329 + { 330 + [OneTimeSetUp] 331 + public void SetupTestFile() 332 + { 333 + var model = new TestModel 334 + { 335 + TestSuiteScript = @".\misc.test.pxs", 336 + UnitsUnderTest = new TestDependency[]{ 337 + new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 338 + }}, 339 + new TestDependency { ScriptName = @"psr\impl\macro.pxs", Dependencies = new string[] { 340 + @"psr\impl\ast.pxs", 341 + }}, 342 + new TestDependency { ScriptName = @"psr\impl\struct.pxs", Dependencies = new string[] { 343 + @"psr\impl\ast.pxs", 344 + @"psr\impl\macro.pxs", 345 + }}, 346 + new TestDependency { ScriptName = @"psr\impl\misc.pxs", Dependencies = new string[] { 347 + @"psr\impl\struct.pxs", 348 + @"psr\impl\ast.pxs", 349 + @"psr\impl\macro.pxs", 350 + }}, 351 + 352 + }, 353 + TestDependencies = new TestDependency[]{ 354 + 355 + } 356 + }; 357 + Initialize(); 358 + Runner.Configure(model, this); 359 + } 360 + 361 + [Test] 362 + public void test_cmp() 363 + { 364 + RunUnitTest(@"test_cmp"); 365 + } 366 + [Test] 367 + public void test_cmp_values() 368 + { 369 + RunUnitTest(@"test_cmp_values"); 370 + } 371 + [Test] 372 + public void test_cmp_keys() 373 + { 374 + RunUnitTest(@"test_cmp_keys"); 375 + } 376 + [Test] 377 + public void test_cmp_with() 378 + { 379 + RunUnitTest(@"test_cmp_with"); 380 + } 381 + [Test] 382 + public void test_cmp_then() 383 + { 384 + RunUnitTest(@"test_cmp_then"); 385 + } 386 + [Test] 387 + public void test_cmpr() 388 + { 389 + RunUnitTest(@"test_cmpr"); 390 + } 391 + [Test] 392 + public void test_ieq() 393 + { 394 + RunUnitTest(@"test_ieq"); 395 + } 396 + [Test] 397 + public void test_ieq_any() 398 + { 399 + RunUnitTest(@"test_ieq_any"); 400 + } 401 + [Test] 402 + public void test_ieq_all() 403 + { 404 + RunUnitTest(@"test_ieq_all"); 405 + } 406 + [Test] 407 + public void test_refeq() 408 + { 409 + RunUnitTest(@"test_refeq"); 410 + } 411 + [Test] 412 + public void test_nrefeq() 413 + { 414 + RunUnitTest(@"test_nrefeq"); 415 + } 416 + [Test] 417 + public void test_create_terminator() 418 + { 419 + RunUnitTest(@"test_create_terminator"); 420 + } 421 + [Test] 422 + public void test_swap() 423 + { 424 + RunUnitTest(@"test_swap"); 425 + } 426 + } 427 + internal abstract class Unit_struct : ScriptedUnitTestContainer 428 + { 429 + [OneTimeSetUp] 430 + public void SetupTestFile() 431 + { 432 + var model = new TestModel 433 + { 434 + TestSuiteScript = @".\struct.test.pxs", 435 + UnitsUnderTest = new TestDependency[]{ 436 + new TestDependency { ScriptName = @"psr\impl\ast.pxs", Dependencies = new string[] { 437 + }}, 438 + new TestDependency { ScriptName = @"psr\impl\macro.pxs", Dependencies = new string[] { 439 + @"psr\impl\ast.pxs", 440 + }}, 441 + new TestDependency { ScriptName = @"psr\impl\struct.pxs", Dependencies = new string[] { 442 + @"psr\impl\ast.pxs", 443 + @"psr\impl\macro.pxs", 444 + }}, 445 + new TestDependency { ScriptName = @"psr\impl\set.pxs", Dependencies = new string[] { 446 + @"psr\impl\struct.pxs", 447 + }}, 448 + new TestDependency { ScriptName = @"psr\impl\queue.pxs", Dependencies = new string[] { 449 + @"psr\impl\struct.pxs", 450 + }}, 451 + new TestDependency { ScriptName = @"psr\impl\stack.pxs", Dependencies = new string[] { 452 + @"psr\impl\struct.pxs", 453 + }}, 454 + 455 + }, 456 + TestDependencies = new TestDependency[]{ 457 + 458 + } 459 + }; 460 + Initialize(); 461 + Runner.Configure(model, this); 462 + } 463 + 464 + [Test] 465 + public void test_struct() 466 + { 467 + RunUnitTest(@"test_struct"); 468 + } 469 + [Test] 470 + public void tsm_create() 471 + { 472 + RunUnitTest(@"tsm_create"); 473 + } 474 + [Test] 475 + public void tsm_add_remove() 476 + { 477 + RunUnitTest(@"tsm_add_remove"); 478 + } 479 + [Test] 480 + public void tsi_create() 481 + { 482 + RunUnitTest(@"tsi_create"); 483 + } 484 + [Test] 485 + public void tsi_add_remove() 486 + { 487 + RunUnitTest(@"tsi_add_remove"); 488 + } 489 + [Test] 490 + public void tqm_count() 491 + { 492 + RunUnitTest(@"tqm_count"); 493 + } 494 + [Test] 495 + public void tqm_peek() 496 + { 497 + RunUnitTest(@"tqm_peek"); 498 + } 499 + [Test] 500 + public void tqm_dequeue() 501 + { 502 + RunUnitTest(@"tqm_dequeue"); 503 + } 504 + [Test] 505 + public void tqi_create() 506 + { 507 + RunUnitTest(@"tqi_create"); 508 + } 509 + [Test] 510 + public void tqi_enqueuedequeue() 511 + { 512 + RunUnitTest(@"tqi_enqueuedequeue"); 513 + } 514 + [Test] 515 + public void tqi_nonserial() 516 + { 517 + RunUnitTest(@"tqi_nonserial"); 518 + } 519 + [Test] 520 + public void tm_count() 521 + { 522 + RunUnitTest(@"tm_count"); 523 + } 524 + [Test] 525 + public void tm_peek() 526 + { 527 + RunUnitTest(@"tm_peek"); 528 + } 529 + [Test] 530 + public void tm_pop() 531 + { 532 + RunUnitTest(@"tm_pop"); 533 + } 534 + [Test] 535 + public void tm_enumarte_pops() 536 + { 537 + RunUnitTest(@"tm_enumarte_pops"); 538 + } 539 + [Test] 540 + public void ti_create() 541 + { 542 + RunUnitTest(@"ti_create"); 543 + } 544 + [Test] 545 + public void ti_pushpop() 546 + { 547 + RunUnitTest(@"ti_pushpop"); 548 + } 549 + [Test] 550 + public void ti_nonserial() 551 + { 552 + RunUnitTest(@"ti_nonserial"); 553 + } 554 + } 555 + } 556 + 557 + // ReSharper restore RedundantExplicitArrayCreation 558 + // ReSharper restore InconsistentNaming 559 +
+1 -1
PrexoniteTests/Tests/Configurations/PsrUnitTests.tt
··· 24 24 #> 25 25 internal abstract class <#=_toPsrClassName(testFile.TestFileName)#> : ScriptedUnitTestContainer 26 26 { 27 - [TestFixtureSetUp] 27 + [OneTimeSetUp] 28 28 public void SetupTestFile() 29 29 { 30 30 var model = new TestModel
+163 -162
PrexoniteTests/Tests/Configurations/ScriptedUnitTestContainer.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Collections.Generic; 28 - using System.IO; 29 - using System.Linq; 30 - using System.Threading.Tasks; 31 - using JetBrains.Annotations; 32 - using NUnit.Framework; 33 - using Prexonite; 34 - using Prexonite.Compiler; 35 - using Prexonite.Compiler.Build; 36 - using Prexonite.Compiler.Symbolic; 37 - using Prexonite.Modular; 38 - using Prexonite.Types; 39 - 40 - namespace PrexoniteTests.Tests.Configurations 41 - { 42 - internal abstract class ScriptedUnitTestContainer 43 - { 44 - public Application Application { get; set; } 45 - public Engine Engine { get; set; } 46 - public Loader Loader { get; set; } 47 - 48 - public List<string> Dependencies { get; set; } 49 - 50 - public StackContext Root { get; set; } 51 - 52 - public const string ListTestsId = @"test\list_test"; 53 - public const string RunTestId = @"test\run_test"; 54 - public const string PrexoniteUnitTestFramework = @"psr\test.pxs"; 55 - public const string DumpRequestFlag = "request_dump"; 56 - 57 - protected abstract UnitTestConfiguration Runner { get; } 58 - 59 - public void Initialize() 60 - { 61 - Application = new Application(ApplicationName); 62 - Engine = new Engine(); 63 - Loader = new Loader(Engine, Application); 64 - 65 - Dependencies = new List<string>(); 66 - Root = new NullContext(Engine, Application, new string[0]); 67 - 68 - var slnPath = Environment.CurrentDirectory; 69 - while (Directory.Exists(slnPath) && !File.Exists(Path.Combine(slnPath, "Prexonite.sln"))) 70 - slnPath = Path.Combine(slnPath, @".." + Path.DirectorySeparatorChar); 71 - 72 - if (Directory.Exists(slnPath)) 73 - { 74 - var psrTestsPath = 75 - Path.GetFullPath(Path.Combine(slnPath, @"PrexoniteTests\psr-tests")); 76 - Console.WriteLine("inferred psr-tests path: " + psrTestsPath, "Engine.Path"); 77 - Engine.Paths.Add(psrTestsPath); 78 - 79 - var prxPath = Path.GetFullPath(Path.Combine(slnPath, @"Prx")); 80 - Console.WriteLine("inferred prx path: " + prxPath, "Engine.Path"); 81 - Engine.Paths.Add(prxPath); 82 - } 83 - else 84 - { 85 - Console.WriteLine("CANNOT INFER solution PATH: " + slnPath, "Engine.Path"); 86 - } 87 - } 88 - 89 - public string ApplicationName 90 - { 91 - get { return GetType().Name; } 92 - } 93 - 94 - protected void RunUnitTest(string testCaseId) 95 - { 96 - Console.WriteLine("---- SNIP end of stored representation ----"); 97 - 98 - var tc = Application.Functions[testCaseId]; 99 - Assert.That(tc, Is.Not.Null, "Test case " + testCaseId + " not found."); 100 - 101 - var rt = _findRunFunction(); 102 - Assert.That(rt, Is.Not.Null, 103 - "Test case run function (part of testing framework) not found. Was looking for {0}.", RunTestId); 104 - 105 - var resP = rt.Run(Engine, new[] {PType.Null, Root.CreateNativePValue(tc)}); 106 - var success = (bool) resP.DynamicCall(Root, new PValue[0], PCall.Get, "Key").Value; 107 - if (success) 108 - return; 109 - 110 - var eObj = resP 111 - .DynamicCall(Root, new PValue[0], PCall.Get, "Value") 112 - .DynamicCall(Root, new PValue[0], PCall.Get, "e") 113 - .Value; 114 - var e = eObj as Exception; 115 - if (e != null) 116 - { 117 - throw e; 118 - } 119 - else 120 - { 121 - Console.WriteLine("Test failed. Result:"); 122 - Console.WriteLine(eObj); 123 - Assert.Fail("Test failed"); 124 - } 125 - } 126 - 127 - /// <summary> 128 - /// Prints a stored representation of each application in the compound that has its "request_dump" flag set. 129 - /// </summary> 130 - public void PrintCompound() 131 - { 132 - var tasks = 133 - Application.Compound.Where(app => app.Meta[DumpRequestFlag].Switch).Select( 134 - app => 135 - new KeyValuePair<ModuleName, Task<ITarget>>(app.Module.Name, ModuleCache.BuildAsync(app.Module.Name))) 136 - .ToDictionary(k => k.Key, k => k.Value); 137 - foreach (var entry in tasks) 138 - { 139 - var name = entry.Key; 140 - var target = entry.Value.Result; 141 - 142 - Console.WriteLine(); 143 - Console.WriteLine("################################## begin of stored representation for {0} ",name); 144 - 145 - var opt = new LoaderOptions(Engine, new Application(target.Module), target.Symbols) 146 - {ReconstructSymbols = false, RegisterCommands = false, StoreSymbols = true}; 147 - var ldr = new Loader(opt); 148 - ldr.Store(Console.Out); 149 - 150 - Console.WriteLine("################################## end of stored representation for {0} ----------", name); 151 - } 152 - } 153 - 154 - private PFunction _findRunFunction() 155 - { 156 - return Application.Compound.Select(app => 157 - { 158 - PFunction func; 159 - return app.Functions.TryGetValue(RunTestId, out func) ? func : null; 160 - }).SingleOrDefault(f => f != null); 161 - } 162 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Collections.Generic; 28 + using System.IO; 29 + using System.Linq; 30 + using System.Reflection; 31 + using System.Threading.Tasks; 32 + using JetBrains.Annotations; 33 + using NUnit.Framework; 34 + using Prexonite; 35 + using Prexonite.Compiler; 36 + using Prexonite.Compiler.Build; 37 + using Prexonite.Compiler.Symbolic; 38 + using Prexonite.Modular; 39 + using Prexonite.Types; 40 + 41 + namespace PrexoniteTests.Tests.Configurations 42 + { 43 + internal abstract class ScriptedUnitTestContainer 44 + { 45 + public Application Application { get; set; } 46 + public Engine Engine { get; set; } 47 + public Loader Loader { get; set; } 48 + 49 + public List<string> Dependencies { get; set; } 50 + 51 + public StackContext Root { get; set; } 52 + 53 + public const string ListTestsId = @"test\list_test"; 54 + public const string RunTestId = @"test\run_test"; 55 + public const string PrexoniteUnitTestFramework = @"psr\test.pxs"; 56 + public const string DumpRequestFlag = "request_dump"; 57 + 58 + protected abstract UnitTestConfiguration Runner { get; } 59 + 60 + public void Initialize() 61 + { 62 + Application = new Application(ApplicationName); 63 + Engine = new Engine(); 64 + Loader = new Loader(Engine, Application); 65 + 66 + Dependencies = new List<string>(); 67 + Root = new NullContext(Engine, Application, new string[0]); 68 + 69 + var slnPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 70 + while (Directory.Exists(slnPath) && !File.Exists(Path.Combine(slnPath, "Prexonite.sln"))) 71 + slnPath = Path.Combine(slnPath, @".." + Path.DirectorySeparatorChar); 72 + 73 + if (Directory.Exists(slnPath)) 74 + { 75 + var psrTestsPath = 76 + Path.GetFullPath(Path.Combine(slnPath, @"PrexoniteTests\psr-tests")); 77 + Console.WriteLine("inferred psr-tests path: " + psrTestsPath, "Engine.Path"); 78 + Engine.Paths.Add(psrTestsPath); 79 + 80 + var prxPath = Path.GetFullPath(Path.Combine(slnPath, @"Prx")); 81 + Console.WriteLine("inferred prx path: " + prxPath, "Engine.Path"); 82 + Engine.Paths.Add(prxPath); 83 + } 84 + else 85 + { 86 + Console.WriteLine("CANNOT INFER solution PATH: " + slnPath, "Engine.Path"); 87 + } 88 + } 89 + 90 + public string ApplicationName 91 + { 92 + get { return GetType().Name; } 93 + } 94 + 95 + protected void RunUnitTest(string testCaseId) 96 + { 97 + Console.WriteLine("---- SNIP end of stored representation ----"); 98 + 99 + var tc = Application.Functions[testCaseId]; 100 + Assert.That(tc, Is.Not.Null, "Test case " + testCaseId + " not found."); 101 + 102 + var rt = _findRunFunction(); 103 + Assert.That(rt, Is.Not.Null, 104 + "Test case run function (part of testing framework) not found. Was looking for {0}.", RunTestId); 105 + 106 + var resP = rt.Run(Engine, new[] {PType.Null, Root.CreateNativePValue(tc)}); 107 + var success = (bool) resP.DynamicCall(Root, new PValue[0], PCall.Get, "Key").Value; 108 + if (success) 109 + return; 110 + 111 + var eObj = resP 112 + .DynamicCall(Root, new PValue[0], PCall.Get, "Value") 113 + .DynamicCall(Root, new PValue[0], PCall.Get, "e") 114 + .Value; 115 + var e = eObj as Exception; 116 + if (e != null) 117 + { 118 + throw e; 119 + } 120 + else 121 + { 122 + Console.WriteLine("Test failed. Result:"); 123 + Console.WriteLine(eObj); 124 + Assert.Fail("Test failed"); 125 + } 126 + } 127 + 128 + /// <summary> 129 + /// Prints a stored representation of each application in the compound that has its "request_dump" flag set. 130 + /// </summary> 131 + public void PrintCompound() 132 + { 133 + var tasks = 134 + Application.Compound.Where(app => app.Meta[DumpRequestFlag].Switch).Select( 135 + app => 136 + new KeyValuePair<ModuleName, Task<ITarget>>(app.Module.Name, ModuleCache.BuildAsync(app.Module.Name))) 137 + .ToDictionary(k => k.Key, k => k.Value); 138 + foreach (var entry in tasks) 139 + { 140 + var name = entry.Key; 141 + var target = entry.Value.Result; 142 + 143 + Console.WriteLine(); 144 + Console.WriteLine("################################## begin of stored representation for {0} ",name); 145 + 146 + var opt = new LoaderOptions(Engine, new Application(target.Module), target.Symbols) 147 + {ReconstructSymbols = false, RegisterCommands = false, StoreSymbols = true}; 148 + var ldr = new Loader(opt); 149 + ldr.Store(Console.Out); 150 + 151 + Console.WriteLine("################################## end of stored representation for {0} ----------", name); 152 + } 153 + } 154 + 155 + private PFunction _findRunFunction() 156 + { 157 + return Application.Compound.Select(app => 158 + { 159 + PFunction func; 160 + return app.Functions.TryGetValue(RunTestId, out func) ? func : null; 161 + }).SingleOrDefault(f => f != null); 162 + } 163 + } 163 164 }
+62 -65
PrexoniteTests/Tests/Internal/DependingOnConstraint.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Linq; 28 - using NUnit.Framework.Constraints; 29 - using Prexonite.Compiler.Build; 30 - using Prexonite.Modular; 31 - 32 - namespace PrexoniteTests.Tests.Internal 33 - { 34 - public class DependingOnConstraint : Constraint 35 - { 36 - private readonly ModuleName _dependency; 37 - 38 - public DependingOnConstraint(ModuleName dependency) 39 - { 40 - _dependency = dependency; 41 - } 42 - 43 - public DependingOnConstraint(string name) 44 - { 45 - ModuleName moduleName; 46 - if (ModuleName.TryParse(name, out moduleName)) 47 - _dependency = moduleName; 48 - else 49 - throw new ArgumentException(string.Format("The string {0} is not a valid module name.", name)); 50 - } 51 - 52 - public override bool Matches(object actualValue) 53 - { 54 - actual = actualValue; 55 - var desc = actualValue as ITargetDescription; 56 - 57 - return desc != null && desc.Dependencies.Any(n => n.Equals(_dependency)); 58 - } 59 - 60 - public override void WriteDescriptionTo(MessageWriter writer) 61 - { 62 - writer.WritePredicate("build target description depending on "); 63 - writer.WriteExpectedValue(_dependency); 64 - } 65 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Linq; 28 + using NUnit.Framework.Constraints; 29 + using Prexonite.Compiler.Build; 30 + using Prexonite.Modular; 31 + 32 + namespace PrexoniteTests.Tests.Internal 33 + { 34 + public class DependingOnConstraint : Constraint 35 + { 36 + private readonly ModuleName _dependency; 37 + 38 + public DependingOnConstraint(ModuleName dependency) : base(dependency) 39 + { 40 + _dependency = dependency; 41 + } 42 + 43 + public DependingOnConstraint(string name) : base(name) 44 + { 45 + ModuleName moduleName; 46 + if (ModuleName.TryParse(name, out moduleName)) 47 + _dependency = moduleName; 48 + else 49 + throw new ArgumentException(string.Format("The string {0} is not a valid module name.", name)); 50 + } 51 + 52 + public override ConstraintResult ApplyTo<TActual>(TActual actual) 53 + { 54 + var actualValue = actual; 55 + return new ConstraintResult(this, actualValue, _matches(actualValue)); 56 + } 57 + 58 + private bool _matches(object actualValue) 59 + { 60 + return actualValue is ITargetDescription desc && desc.Dependencies.Any(n => n.Equals(_dependency)); 61 + } 62 + } 66 63 }
+565 -565
PrexoniteTests/Tests/SelfAssemblingPlanTests.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Diagnostics; 28 - using System.IO; 29 - using System.Linq; 30 - using System.Text; 31 - using System.Threading; 32 - using JetBrains.Annotations; 33 - using NUnit.Framework; 34 - using Prexonite.Compiler.Build; 35 - using Prexonite.Compiler.Build.Internal; 36 - using Prexonite.Modular; 37 - 38 - namespace PrexoniteTests.Tests 39 - { 40 - [TestFixture] 41 - public class SelfAssemblingPlanTests 42 - { 43 - protected static readonly TraceSource Trace = new TraceSource("PrexoniteTests.Tests.SelfAssemblingPlan"); 44 - 45 - private String _basePath; 46 - 47 - protected ISelfAssemblingPlan Sam; 48 - 49 - protected IDisposable MockFile(String path, String content) 50 - { 51 - var handle = new MockFileHandle(new FileInfo(Path.Combine(_basePath, path)), this); 52 - DirectoryInfo fileDir = handle.File.Directory; 53 - Debug.Assert(fileDir != null, "handle.File.Directory != null"); 54 - fileDir.Create(); 55 - using (var sw = new StreamWriter(handle.File.ToString(),false,Encoding.UTF8)) 56 - { 57 - sw.Write(content); 58 - sw.Flush(); 59 - sw.Close(); 60 - } 61 - return handle; 62 - } 63 - 64 - private class MockFileHandle : IDisposable 65 - { 66 - [NotNull] 67 - private readonly FileInfo _file; 68 - [NotNull] 69 - private readonly SelfAssemblingPlanTests _instance; 70 - 71 - [NotNull] 72 - public FileInfo File 73 - { 74 - get { return _file; } 75 - } 76 - 77 - [NotNull] 78 - public SelfAssemblingPlanTests Instance 79 - { 80 - get { return _instance; } 81 - } 82 - 83 - public MockFileHandle([NotNull]FileInfo file, [NotNull]SelfAssemblingPlanTests instance) 84 - { 85 - _file = file; 86 - _instance = instance; 87 - } 88 - 89 - public void Dispose() 90 - { 91 - GC.SuppressFinalize(this); 92 - Dispose(true); 93 - } 94 - 95 - protected void Dispose(bool disposing) 96 - { 97 - if (disposing) 98 - { 99 - 100 - } 101 - _tryDelete(); 102 - } 103 - 104 - private void _tryDelete() 105 - { 106 - try 107 - { 108 - _file.Delete(); 109 - } 110 - catch (IOException e) 111 - { 112 - Trace.TraceEvent(TraceEventType.Error, 0, string.Format("Cannot delete file {0} because of {1}", _file, e)); 113 - } 114 - } 115 - 116 - ~MockFileHandle() 117 - { 118 - Dispose(false); 119 - } 120 - } 121 - 122 - private String _prototypePath; 123 - 124 - [TestFixtureSetUp] 125 - public void Init() 126 - { 127 - _prototypePath = Path.Combine(Path.GetTempPath(), "PrexoniteTests.SelfAssemblingPlanTests"); 128 - } 129 - 130 - [SetUp] 131 - public void Prepare() 132 - { 133 - _basePath = Path.Combine(_prototypePath, Guid.NewGuid().ToString("N")); 134 - if (Directory.Exists(_basePath)) 135 - { 136 - Trace.TraceEvent(TraceEventType.Warning, 0, 137 - "Expected temporary directory at {0} not to exist. Using it anyway.", _basePath); 138 - } 139 - Sam = Plan.CreateSelfAssembling(); 140 - Sam.SearchPaths.Add(_basePath); 141 - } 142 - 143 - private void _tryTearDown() 144 - { 145 - try 146 - { 147 - Directory.Delete(_basePath, recursive: true); 148 - } 149 - catch (Exception e) 150 - { 151 - Trace.TraceEvent(TraceEventType.Error, 0, "Exception during tear down (deletion of temp dir): {0}", e); 152 - Console.WriteLine(e); 153 - } 154 - } 155 - 156 - [TearDown] 157 - public void TearDown() 158 - { 159 - _tryTearDown(); 160 - } 161 - 162 - [TestFixtureTearDown] 163 - public void LastDitchEffort() 164 - { 165 - try 166 - { 167 - Directory.Delete(_prototypePath,recursive:true); 168 - } 169 - catch (Exception e) 170 - { 171 - Trace.TraceEvent(TraceEventType.Error, 0, "Exception during fixture tear down (last ditch effort, deletion of temp dir): {0}", e); 172 - Console.WriteLine(e); 173 - } 174 - } 175 - 176 - [Test] 177 - public void EmptyInMemory() 178 - { 179 - var desc = Sam.AssembleAsync(Source.FromString(""), CancellationToken.None).Result; 180 - Assert.That(desc,Is.Not.Null); 181 - Assert.That(desc.BuildMessages,Is.Empty,"Should not have build (error) messages"); 182 - } 183 - 184 - [Test] 185 - public void Empty() 186 - { 187 - const string path = "empty.pxs"; 188 - using (MockFile(path,"")) 189 - { 190 - var desc = Sam.AssembleAsync(Source.FromFile(Path.Combine(_basePath,path),Encoding.UTF8), CancellationToken.None).Result; 191 - Assert.That(desc, Is.Not.Null); 192 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 193 - } 194 - } 195 - 196 - [Test] 197 - public void ExtractModuleNameInMemory() 198 - { 199 - var desc = Sam.AssembleAsync(Source.FromString("name the_module/5.4.3.2;"), CancellationToken.None).Result; 200 - Assert.That(desc, Is.Not.Null); 201 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 202 - Assert.That(desc.Name,Is.EqualTo(new ModuleName("the_module",new Version(5,4,3,2)))); 203 - } 204 - 205 - [Test] 206 - public void ExtractModuleName() 207 - { 208 - const string path = "unrelated_name.pxs"; 209 - using (MockFile(path,"name the_module/5.4.3.2;")) 210 - { 211 - var desc = Sam.AssembleAsync(Source.FromFile(Path.Combine(_basePath,path), Encoding.UTF8), CancellationToken.None).Result; 212 - Assert.That(desc, Is.Not.Null); 213 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 214 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("the_module", new Version(5, 4, 3, 2)))); 215 - } 216 - } 217 - 218 - [Test] 219 - public void SinglePathDependency() 220 - { 221 - const string path = "find_me.pxs"; 222 - using (MockFile(path, "name the_module/5.4.3.2;")) 223 - { 224 - var desc = Sam.AssembleAsync(Source.FromString(@" 225 - name finder; 226 - references { 227 - ""./find_me.pxs"" 228 - }; 229 - "), CancellationToken.None).Result; 230 - Assert.That(desc, Is.Not.Null); 231 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 232 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0,0)))); 233 - var theModuleName = new ModuleName("the_module", new Version(5, 4, 3, 2)); 234 - Assert.That(desc.Dependencies.Count,Is.GreaterThanOrEqualTo(1),"Primary should have at least one dependency."); 235 - Assert.That(desc.Dependencies,Contains.Item(theModuleName),string.Format("Primary is expected to depend on {0}.", theModuleName)); 236 - var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 237 - Assert.That(firstOrDefault,Is.Not.Null,string.Format("Expected a target description of {0} in SAM.", theModuleName)); 238 - } 239 - } 240 - 241 - [Test] 242 - public void SingleModuleNameDependency() 243 - { 244 - const string path = "found.pxs"; 245 - using (MockFile(path, "name found;")) 246 - { 247 - var desc = Sam.AssembleAsync(Source.FromString(@" 248 - name finder; 249 - references { 250 - found 251 - }; 252 - "), CancellationToken.None).Result; 253 - Assert.That(desc, Is.Not.Null); 254 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 255 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 256 - var theModuleName = new ModuleName("found", new Version(0,0)); 257 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 258 - Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 259 - var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 260 - Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 261 - } 262 - } 263 - 264 - [Test] 265 - public void SingleModuleDottedNameDependency() 266 - { 267 - const string path = "hay/stack.pxs"; 268 - using (MockFile(path, "name hay::stack;")) 269 - { 270 - var desc = Sam.AssembleAsync(Source.FromString(@" 271 - name finder; 272 - references { 273 - hay::stack 274 - }; 275 - "), CancellationToken.None).Result; 276 - Assert.That(desc, Is.Not.Null); 277 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 278 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 279 - var theModuleName = new ModuleName("hay.stack", new Version(0, 0)); 280 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 281 - Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 282 - var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 283 - Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 284 - } 285 - } 286 - 287 - [Test] 288 - public void DeeplyDottedModuleNameDependency() 289 - { 290 - const string path = "hay/stack/lazy/impl.pxs"; 291 - using (MockFile(path, "name hay::stack::lazy::impl;")) 292 - { 293 - var desc = Sam.AssembleAsync(Source.FromString(@" 294 - name finder; 295 - references { 296 - hay::stack::lazy::impl 297 - }; 298 - "), CancellationToken.None).Result; 299 - Assert.That(desc, Is.Not.Null); 300 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 301 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 302 - var theModuleName = new ModuleName("hay.stack.lazy.impl", new Version(0, 0)); 303 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 304 - Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 305 - var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 306 - Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 307 - } 308 - } 309 - 310 - 311 - [Test] 312 - public void CommonPrefixDottedModuleNameDependency() 313 - { 314 - const string path = "hay.stack/lazy/impl.pxs"; 315 - using (MockFile(path, "name hay::stack::lazy::impl;")) 316 - { 317 - var desc = Sam.AssembleAsync(Source.FromString(@" 318 - name finder; 319 - references { 320 - hay::stack::lazy::impl 321 - }; 322 - "), CancellationToken.None).Result; 323 - Assert.That(desc, Is.Not.Null); 324 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 325 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 326 - var theModuleName = new ModuleName("hay.stack.lazy.impl", new Version(0, 0)); 327 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 328 - Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 329 - var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 330 - Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 331 - } 332 - } 333 - 334 - [Test] 335 - public void FlatDottedModuleNameDependency() 336 - { 337 - const string path = "hay.stack.lazy.impl.pxs"; 338 - using (MockFile(path, "name hay::stack::lazy::impl;")) 339 - { 340 - var desc = Sam.AssembleAsync(Source.FromString(@" 341 - name finder; 342 - references { 343 - hay::stack::lazy::impl 344 - }; 345 - "), CancellationToken.None).Result; 346 - Assert.That(desc, Is.Not.Null); 347 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 348 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 349 - var theModuleName = new ModuleName("hay.stack.lazy.impl", new Version(0, 0)); 350 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 351 - Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 352 - var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 353 - Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 354 - } 355 - } 356 - 357 - [Test] 358 - public void DoubleModuleNameDependency() 359 - { 360 - const string pathFound = "found.pxs"; 361 - const string pathLost = "lost.pxs"; 362 - using (MockFile(pathFound, "name found;")) 363 - using (MockFile(pathLost,"name lost;")) 364 - { 365 - var desc = 366 - Sam.AssembleAsync( 367 - Source.FromString(@"name finder;references{found,lost};"), CancellationToken.None).Result; 368 - Assert.That(desc, Is.Not.Null); 369 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 370 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 371 - 372 - // Does the primary module depend on lost and found? 373 - var foundModuleName = new ModuleName("found", new Version(0, 0)); 374 - var lostModuleName = new ModuleName("lost", new Version(0, 0)); 375 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(2), "Primary should have at least two dependencies."); 376 - Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 377 - Assert.That(desc.Dependencies, Contains.Item(lostModuleName), string.Format("Primary is expected to depend on {0}.", lostModuleName)); 378 - 379 - // Does SAM contain the found module 380 - var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 381 - Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 382 - // ReSharper disable PossibleNullReferenceException 383 - Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 384 - // ReSharper restore PossibleNullReferenceException 385 - 386 - // does SAM contain the lost module? 387 - var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 388 - Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 389 - // ReSharper disable PossibleNullReferenceException 390 - Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 391 - // ReSharper restore PossibleNullReferenceException 392 - } 393 - } 394 - 395 - [Test] 396 - public void TransitiveDependency() 397 - { 398 - const string pathFound = "found.pxs"; 399 - const string pathLost = "lost.pxs"; 400 - using (MockFile(pathFound, "name found;references{lost}")) 401 - using (MockFile(pathLost, "name lost;")) 402 - { 403 - var desc = 404 - Sam.AssembleAsync( 405 - Source.FromString(@"name finder;references{found};"), CancellationToken.None).Result; 406 - Assert.That(desc, Is.Not.Null); 407 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 408 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 409 - 410 - // Does the primary module depend on lost? 411 - var foundModuleName = new ModuleName("found", new Version(0, 0)); 412 - var lostModuleName = new ModuleName("lost", new Version(0, 0)); 413 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 414 - Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 415 - 416 - // Does SAM contain the found module? 417 - var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 418 - Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 419 - Debug.Assert(foundTarget != null); 420 - 421 - // Does found depend on lost? 422 - // ReSharper disable PossibleNullReferenceException 423 - Assert.That(foundTarget.Dependencies, Contains.Item(lostModuleName), string.Format("{1} is expected to depend on {0}.", lostModuleName, foundModuleName)); 424 - Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 425 - 426 - // does SAM contain the lost module? 427 - var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 428 - Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 429 - Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 430 - // ReSharper restore PossibleNullReferenceException 431 - } 432 - } 433 - 434 - [Test] 435 - public void RelativeDependency() 436 - { 437 - const string pathFound = "stack/found.pxs"; 438 - const string pathLost = "stack/lost.pxs"; 439 - using (MockFile(pathFound, "name found;references{lost}")) 440 - using (MockFile(pathLost, "name lost;")) 441 - { 442 - var emptyCount = Sam.TargetDescriptions.Count; 443 - var desc = 444 - Sam.AssembleAsync( 445 - Source.FromString(@"name finder;references{""./stack/found.pxs""};"), CancellationToken.None).Result; 446 - Assert.That(desc, Is.Not.Null); 447 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 448 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 449 - 450 - // Does the primary module depend on lost and found? 451 - var foundModuleName = new ModuleName("found", new Version(0, 0)); 452 - var lostModuleName = new ModuleName("lost", new Version(0, 0)); 453 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 454 - Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 455 - 456 - // Does SAM contain the found module 457 - var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 458 - Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 459 - // ReSharper disable PossibleNullReferenceException 460 - Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 461 - // ReSharper restore PossibleNullReferenceException 462 - Assert.That(foundTarget.Dependencies, Contains.Item(lostModuleName), string.Format("found module expected to depend on {0}.", lostModuleName)); 463 - 464 - // does SAM contain the lost module? 465 - var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 466 - Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 467 - // ReSharper disable PossibleNullReferenceException 468 - Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 469 - // ReSharper restore PossibleNullReferenceException 470 - 471 - Assert.That(Sam.TargetDescriptions.Count,Is.EqualTo(emptyCount+3), "There should be exactly three new modules: finder, lost and found."); 472 - } 473 - } 474 - 475 - [Test] 476 - public void FindProvided() 477 - { 478 - const string pathFound = "found.pxs"; 479 - const string pathLost = "lost.pxs"; 480 - 481 - // Provide the module lost to the SAM ahead of time, fully resolved 482 - var lostModuleName = new ModuleName("lost", new Version(0, 0)); 483 - Sam.TargetDescriptions.Add(new ManualTargetDescription(lostModuleName, Source.FromString("name: lost;"), 484 - pathLost, Enumerable.Empty<ModuleName>())); 485 - 486 - // Have module found short-circuit when resolving lost 487 - using (MockFile(pathFound, "name found;references{lost}")) 488 - { 489 - var desc = 490 - Sam.AssembleAsync( 491 - Source.FromString(@"name finder;references{found};"), CancellationToken.None).Result; 492 - Assert.That(desc, Is.Not.Null); 493 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 494 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 495 - 496 - // Does the primary module depend on lost? 497 - var foundModuleName = new ModuleName("found", new Version(0, 0)); 498 - 499 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 500 - Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 501 - 502 - // Does SAM contain the found module? 503 - var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 504 - Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 505 - Debug.Assert(foundTarget != null); 506 - 507 - // Does found depend on lost? 508 - // ReSharper disable PossibleNullReferenceException 509 - Assert.That(foundTarget.Dependencies, Contains.Item(lostModuleName), string.Format("{1} is expected to depend on {0}.", lostModuleName, foundModuleName)); 510 - Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 511 - 512 - // does SAM contain the lost module? 513 - var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 514 - Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 515 - Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 516 - // ReSharper restore PossibleNullReferenceException 517 - } 518 - } 519 - 520 - [Test] 521 - public void DiamondDependency() 522 - { 523 - const string pathFound = "found.pxs"; 524 - const string pathLost = "lost.pxs"; 525 - const string pathBase = "base.pxs"; 526 - using (MockFile(pathFound, "name found;references{base}")) 527 - using (MockFile(pathLost, "name lost;references{base}")) 528 - using(MockFile(pathBase,"name base;")) 529 - { 530 - var desc = 531 - Sam.AssembleAsync( 532 - Source.FromString(@"name finder;references{lost,found};"), CancellationToken.None).Result; 533 - Assert.That(desc, Is.Not.Null); 534 - Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 535 - Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 536 - 537 - // Does the primary module depend on lost and found? 538 - var foundModuleName = new ModuleName("found", new Version(0, 0)); 539 - var lostModuleName = new ModuleName("lost", new Version(0, 0)); 540 - var baseModuelName = new ModuleName("base", new Version(0, 0)); 541 - Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 542 - Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 543 - Assert.That(desc.Dependencies, Contains.Item(lostModuleName), string.Format("Primary is expected to depend on {0}.", lostModuleName)); 544 - 545 - // Does SAM contain the found module? 546 - var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 547 - Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 548 - Debug.Assert(foundTarget != null); 549 - 550 - // Does found depend on base? 551 - // ReSharper disable PossibleNullReferenceException 552 - Assert.That(foundTarget.Dependencies, Contains.Item(baseModuelName), string.Format("{1} is expected to depend on {0}.", baseModuelName, foundModuleName)); 553 - Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 554 - 555 - // does SAM contain the lost module? 556 - var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 557 - Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 558 - Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 559 - // ReSharper restore PossibleNullReferenceException 560 - 561 - Assert.That(lostTarget.Dependencies, Contains.Item(baseModuelName), string.Format("{1} is expected to depend on {0}.", baseModuelName, lostTarget)); 562 - Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostTarget)); 563 - } 564 - } 565 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Diagnostics; 28 + using System.IO; 29 + using System.Linq; 30 + using System.Text; 31 + using System.Threading; 32 + using JetBrains.Annotations; 33 + using NUnit.Framework; 34 + using Prexonite.Compiler.Build; 35 + using Prexonite.Compiler.Build.Internal; 36 + using Prexonite.Modular; 37 + 38 + namespace PrexoniteTests.Tests 39 + { 40 + [TestFixture] 41 + public class SelfAssemblingPlanTests 42 + { 43 + protected static readonly TraceSource Trace = new TraceSource("PrexoniteTests.Tests.SelfAssemblingPlan"); 44 + 45 + private String _basePath; 46 + 47 + protected ISelfAssemblingPlan Sam; 48 + 49 + protected IDisposable MockFile(String path, String content) 50 + { 51 + var handle = new MockFileHandle(new FileInfo(Path.Combine(_basePath, path)), this); 52 + DirectoryInfo fileDir = handle.File.Directory; 53 + Debug.Assert(fileDir != null, "handle.File.Directory != null"); 54 + fileDir.Create(); 55 + using (var sw = new StreamWriter(handle.File.ToString(),false,Encoding.UTF8)) 56 + { 57 + sw.Write(content); 58 + sw.Flush(); 59 + sw.Close(); 60 + } 61 + return handle; 62 + } 63 + 64 + private class MockFileHandle : IDisposable 65 + { 66 + [NotNull] 67 + private readonly FileInfo _file; 68 + [NotNull] 69 + private readonly SelfAssemblingPlanTests _instance; 70 + 71 + [NotNull] 72 + public FileInfo File 73 + { 74 + get { return _file; } 75 + } 76 + 77 + [NotNull] 78 + public SelfAssemblingPlanTests Instance 79 + { 80 + get { return _instance; } 81 + } 82 + 83 + public MockFileHandle([NotNull]FileInfo file, [NotNull]SelfAssemblingPlanTests instance) 84 + { 85 + _file = file; 86 + _instance = instance; 87 + } 88 + 89 + public void Dispose() 90 + { 91 + GC.SuppressFinalize(this); 92 + Dispose(true); 93 + } 94 + 95 + protected void Dispose(bool disposing) 96 + { 97 + if (disposing) 98 + { 99 + 100 + } 101 + _tryDelete(); 102 + } 103 + 104 + private void _tryDelete() 105 + { 106 + try 107 + { 108 + _file.Delete(); 109 + } 110 + catch (IOException e) 111 + { 112 + Trace.TraceEvent(TraceEventType.Error, 0, string.Format("Cannot delete file {0} because of {1}", _file, e)); 113 + } 114 + } 115 + 116 + ~MockFileHandle() 117 + { 118 + Dispose(false); 119 + } 120 + } 121 + 122 + private String _prototypePath; 123 + 124 + [OneTimeSetUp] 125 + public void Init() 126 + { 127 + _prototypePath = Path.Combine(Path.GetTempPath(), "PrexoniteTests.SelfAssemblingPlanTests"); 128 + } 129 + 130 + [SetUp] 131 + public void Prepare() 132 + { 133 + _basePath = Path.Combine(_prototypePath, Guid.NewGuid().ToString("N")); 134 + if (Directory.Exists(_basePath)) 135 + { 136 + Trace.TraceEvent(TraceEventType.Warning, 0, 137 + "Expected temporary directory at {0} not to exist. Using it anyway.", _basePath); 138 + } 139 + Sam = Plan.CreateSelfAssembling(); 140 + Sam.SearchPaths.Add(_basePath); 141 + } 142 + 143 + private void _tryTearDown() 144 + { 145 + try 146 + { 147 + Directory.Delete(_basePath, recursive: true); 148 + } 149 + catch (Exception e) 150 + { 151 + Trace.TraceEvent(TraceEventType.Error, 0, "Exception during tear down (deletion of temp dir): {0}", e); 152 + Console.WriteLine(e); 153 + } 154 + } 155 + 156 + [TearDown] 157 + public void TearDown() 158 + { 159 + _tryTearDown(); 160 + } 161 + 162 + [OneTimeTearDown] 163 + public void LastDitchEffort() 164 + { 165 + try 166 + { 167 + Directory.Delete(_prototypePath,recursive:true); 168 + } 169 + catch (Exception e) 170 + { 171 + Trace.TraceEvent(TraceEventType.Error, 0, "Exception during fixture tear down (last ditch effort, deletion of temp dir): {0}", e); 172 + Console.WriteLine(e); 173 + } 174 + } 175 + 176 + [Test] 177 + public void EmptyInMemory() 178 + { 179 + var desc = Sam.AssembleAsync(Source.FromString(""), CancellationToken.None).Result; 180 + Assert.That(desc,Is.Not.Null); 181 + Assert.That(desc.BuildMessages,Is.Empty,"Should not have build (error) messages"); 182 + } 183 + 184 + [Test] 185 + public void Empty() 186 + { 187 + const string path = "empty.pxs"; 188 + using (MockFile(path,"")) 189 + { 190 + var desc = Sam.AssembleAsync(Source.FromFile(Path.Combine(_basePath,path),Encoding.UTF8), CancellationToken.None).Result; 191 + Assert.That(desc, Is.Not.Null); 192 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 193 + } 194 + } 195 + 196 + [Test] 197 + public void ExtractModuleNameInMemory() 198 + { 199 + var desc = Sam.AssembleAsync(Source.FromString("name the_module/5.4.3.2;"), CancellationToken.None).Result; 200 + Assert.That(desc, Is.Not.Null); 201 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 202 + Assert.That(desc.Name,Is.EqualTo(new ModuleName("the_module",new Version(5,4,3,2)))); 203 + } 204 + 205 + [Test] 206 + public void ExtractModuleName() 207 + { 208 + const string path = "unrelated_name.pxs"; 209 + using (MockFile(path,"name the_module/5.4.3.2;")) 210 + { 211 + var desc = Sam.AssembleAsync(Source.FromFile(Path.Combine(_basePath,path), Encoding.UTF8), CancellationToken.None).Result; 212 + Assert.That(desc, Is.Not.Null); 213 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 214 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("the_module", new Version(5, 4, 3, 2)))); 215 + } 216 + } 217 + 218 + [Test] 219 + public void SinglePathDependency() 220 + { 221 + const string path = "find_me.pxs"; 222 + using (MockFile(path, "name the_module/5.4.3.2;")) 223 + { 224 + var desc = Sam.AssembleAsync(Source.FromString(@" 225 + name finder; 226 + references { 227 + ""./find_me.pxs"" 228 + }; 229 + "), CancellationToken.None).Result; 230 + Assert.That(desc, Is.Not.Null); 231 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 232 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0,0)))); 233 + var theModuleName = new ModuleName("the_module", new Version(5, 4, 3, 2)); 234 + Assert.That(desc.Dependencies.Count,Is.GreaterThanOrEqualTo(1),"Primary should have at least one dependency."); 235 + Assert.That(desc.Dependencies,Contains.Item(theModuleName),string.Format("Primary is expected to depend on {0}.", theModuleName)); 236 + var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 237 + Assert.That(firstOrDefault,Is.Not.Null,string.Format("Expected a target description of {0} in SAM.", theModuleName)); 238 + } 239 + } 240 + 241 + [Test] 242 + public void SingleModuleNameDependency() 243 + { 244 + const string path = "found.pxs"; 245 + using (MockFile(path, "name found;")) 246 + { 247 + var desc = Sam.AssembleAsync(Source.FromString(@" 248 + name finder; 249 + references { 250 + found 251 + }; 252 + "), CancellationToken.None).Result; 253 + Assert.That(desc, Is.Not.Null); 254 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 255 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 256 + var theModuleName = new ModuleName("found", new Version(0,0)); 257 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 258 + Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 259 + var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 260 + Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 261 + } 262 + } 263 + 264 + [Test] 265 + public void SingleModuleDottedNameDependency() 266 + { 267 + const string path = "hay/stack.pxs"; 268 + using (MockFile(path, "name hay::stack;")) 269 + { 270 + var desc = Sam.AssembleAsync(Source.FromString(@" 271 + name finder; 272 + references { 273 + hay::stack 274 + }; 275 + "), CancellationToken.None).Result; 276 + Assert.That(desc, Is.Not.Null); 277 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 278 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 279 + var theModuleName = new ModuleName("hay.stack", new Version(0, 0)); 280 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 281 + Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 282 + var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 283 + Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 284 + } 285 + } 286 + 287 + [Test] 288 + public void DeeplyDottedModuleNameDependency() 289 + { 290 + const string path = "hay/stack/lazy/impl.pxs"; 291 + using (MockFile(path, "name hay::stack::lazy::impl;")) 292 + { 293 + var desc = Sam.AssembleAsync(Source.FromString(@" 294 + name finder; 295 + references { 296 + hay::stack::lazy::impl 297 + }; 298 + "), CancellationToken.None).Result; 299 + Assert.That(desc, Is.Not.Null); 300 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 301 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 302 + var theModuleName = new ModuleName("hay.stack.lazy.impl", new Version(0, 0)); 303 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 304 + Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 305 + var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 306 + Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 307 + } 308 + } 309 + 310 + 311 + [Test] 312 + public void CommonPrefixDottedModuleNameDependency() 313 + { 314 + const string path = "hay.stack/lazy/impl.pxs"; 315 + using (MockFile(path, "name hay::stack::lazy::impl;")) 316 + { 317 + var desc = Sam.AssembleAsync(Source.FromString(@" 318 + name finder; 319 + references { 320 + hay::stack::lazy::impl 321 + }; 322 + "), CancellationToken.None).Result; 323 + Assert.That(desc, Is.Not.Null); 324 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 325 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 326 + var theModuleName = new ModuleName("hay.stack.lazy.impl", new Version(0, 0)); 327 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 328 + Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 329 + var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 330 + Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 331 + } 332 + } 333 + 334 + [Test] 335 + public void FlatDottedModuleNameDependency() 336 + { 337 + const string path = "hay.stack.lazy.impl.pxs"; 338 + using (MockFile(path, "name hay::stack::lazy::impl;")) 339 + { 340 + var desc = Sam.AssembleAsync(Source.FromString(@" 341 + name finder; 342 + references { 343 + hay::stack::lazy::impl 344 + }; 345 + "), CancellationToken.None).Result; 346 + Assert.That(desc, Is.Not.Null); 347 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 348 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 349 + var theModuleName = new ModuleName("hay.stack.lazy.impl", new Version(0, 0)); 350 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 351 + Assert.That(desc.Dependencies, Contains.Item(theModuleName), string.Format("Primary is expected to depend on {0}.", theModuleName)); 352 + var firstOrDefault = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(theModuleName)); 353 + Assert.That(firstOrDefault, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", theModuleName)); 354 + } 355 + } 356 + 357 + [Test] 358 + public void DoubleModuleNameDependency() 359 + { 360 + const string pathFound = "found.pxs"; 361 + const string pathLost = "lost.pxs"; 362 + using (MockFile(pathFound, "name found;")) 363 + using (MockFile(pathLost,"name lost;")) 364 + { 365 + var desc = 366 + Sam.AssembleAsync( 367 + Source.FromString(@"name finder;references{found,lost};"), CancellationToken.None).Result; 368 + Assert.That(desc, Is.Not.Null); 369 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 370 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 371 + 372 + // Does the primary module depend on lost and found? 373 + var foundModuleName = new ModuleName("found", new Version(0, 0)); 374 + var lostModuleName = new ModuleName("lost", new Version(0, 0)); 375 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(2), "Primary should have at least two dependencies."); 376 + Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 377 + Assert.That(desc.Dependencies, Contains.Item(lostModuleName), string.Format("Primary is expected to depend on {0}.", lostModuleName)); 378 + 379 + // Does SAM contain the found module 380 + var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 381 + Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 382 + // ReSharper disable PossibleNullReferenceException 383 + Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 384 + // ReSharper restore PossibleNullReferenceException 385 + 386 + // does SAM contain the lost module? 387 + var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 388 + Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 389 + // ReSharper disable PossibleNullReferenceException 390 + Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 391 + // ReSharper restore PossibleNullReferenceException 392 + } 393 + } 394 + 395 + [Test] 396 + public void TransitiveDependency() 397 + { 398 + const string pathFound = "found.pxs"; 399 + const string pathLost = "lost.pxs"; 400 + using (MockFile(pathFound, "name found;references{lost}")) 401 + using (MockFile(pathLost, "name lost;")) 402 + { 403 + var desc = 404 + Sam.AssembleAsync( 405 + Source.FromString(@"name finder;references{found};"), CancellationToken.None).Result; 406 + Assert.That(desc, Is.Not.Null); 407 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 408 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 409 + 410 + // Does the primary module depend on lost? 411 + var foundModuleName = new ModuleName("found", new Version(0, 0)); 412 + var lostModuleName = new ModuleName("lost", new Version(0, 0)); 413 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 414 + Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 415 + 416 + // Does SAM contain the found module? 417 + var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 418 + Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 419 + Debug.Assert(foundTarget != null); 420 + 421 + // Does found depend on lost? 422 + // ReSharper disable PossibleNullReferenceException 423 + Assert.That(foundTarget.Dependencies, Contains.Item(lostModuleName), string.Format("{1} is expected to depend on {0}.", lostModuleName, foundModuleName)); 424 + Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 425 + 426 + // does SAM contain the lost module? 427 + var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 428 + Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 429 + Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 430 + // ReSharper restore PossibleNullReferenceException 431 + } 432 + } 433 + 434 + [Test] 435 + public void RelativeDependency() 436 + { 437 + const string pathFound = "stack/found.pxs"; 438 + const string pathLost = "stack/lost.pxs"; 439 + using (MockFile(pathFound, "name found;references{lost}")) 440 + using (MockFile(pathLost, "name lost;")) 441 + { 442 + var emptyCount = Sam.TargetDescriptions.Count; 443 + var desc = 444 + Sam.AssembleAsync( 445 + Source.FromString(@"name finder;references{""./stack/found.pxs""};"), CancellationToken.None).Result; 446 + Assert.That(desc, Is.Not.Null); 447 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 448 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 449 + 450 + // Does the primary module depend on lost and found? 451 + var foundModuleName = new ModuleName("found", new Version(0, 0)); 452 + var lostModuleName = new ModuleName("lost", new Version(0, 0)); 453 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 454 + Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 455 + 456 + // Does SAM contain the found module 457 + var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 458 + Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 459 + // ReSharper disable PossibleNullReferenceException 460 + Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 461 + // ReSharper restore PossibleNullReferenceException 462 + Assert.That(foundTarget.Dependencies, Contains.Item(lostModuleName), string.Format("found module expected to depend on {0}.", lostModuleName)); 463 + 464 + // does SAM contain the lost module? 465 + var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 466 + Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 467 + // ReSharper disable PossibleNullReferenceException 468 + Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 469 + // ReSharper restore PossibleNullReferenceException 470 + 471 + Assert.That(Sam.TargetDescriptions.Count,Is.EqualTo(emptyCount+3), "There should be exactly three new modules: finder, lost and found."); 472 + } 473 + } 474 + 475 + [Test] 476 + public void FindProvided() 477 + { 478 + const string pathFound = "found.pxs"; 479 + const string pathLost = "lost.pxs"; 480 + 481 + // Provide the module lost to the SAM ahead of time, fully resolved 482 + var lostModuleName = new ModuleName("lost", new Version(0, 0)); 483 + Sam.TargetDescriptions.Add(new ManualTargetDescription(lostModuleName, Source.FromString("name: lost;"), 484 + pathLost, Enumerable.Empty<ModuleName>())); 485 + 486 + // Have module found short-circuit when resolving lost 487 + using (MockFile(pathFound, "name found;references{lost}")) 488 + { 489 + var desc = 490 + Sam.AssembleAsync( 491 + Source.FromString(@"name finder;references{found};"), CancellationToken.None).Result; 492 + Assert.That(desc, Is.Not.Null); 493 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 494 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 495 + 496 + // Does the primary module depend on lost? 497 + var foundModuleName = new ModuleName("found", new Version(0, 0)); 498 + 499 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 500 + Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 501 + 502 + // Does SAM contain the found module? 503 + var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 504 + Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 505 + Debug.Assert(foundTarget != null); 506 + 507 + // Does found depend on lost? 508 + // ReSharper disable PossibleNullReferenceException 509 + Assert.That(foundTarget.Dependencies, Contains.Item(lostModuleName), string.Format("{1} is expected to depend on {0}.", lostModuleName, foundModuleName)); 510 + Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 511 + 512 + // does SAM contain the lost module? 513 + var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 514 + Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 515 + Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 516 + // ReSharper restore PossibleNullReferenceException 517 + } 518 + } 519 + 520 + [Test] 521 + public void DiamondDependency() 522 + { 523 + const string pathFound = "found.pxs"; 524 + const string pathLost = "lost.pxs"; 525 + const string pathBase = "base.pxs"; 526 + using (MockFile(pathFound, "name found;references{base}")) 527 + using (MockFile(pathLost, "name lost;references{base}")) 528 + using(MockFile(pathBase,"name base;")) 529 + { 530 + var desc = 531 + Sam.AssembleAsync( 532 + Source.FromString(@"name finder;references{lost,found};"), CancellationToken.None).Result; 533 + Assert.That(desc, Is.Not.Null); 534 + Assert.That(desc.BuildMessages, Is.Empty, "Should not have build (error) messages"); 535 + Assert.That(desc.Name, Is.EqualTo(new ModuleName("finder", new Version(0, 0)))); 536 + 537 + // Does the primary module depend on lost and found? 538 + var foundModuleName = new ModuleName("found", new Version(0, 0)); 539 + var lostModuleName = new ModuleName("lost", new Version(0, 0)); 540 + var baseModuelName = new ModuleName("base", new Version(0, 0)); 541 + Assert.That(desc.Dependencies.Count, Is.GreaterThanOrEqualTo(1), "Primary should have at least one dependency."); 542 + Assert.That(desc.Dependencies, Contains.Item(foundModuleName), string.Format("Primary is expected to depend on {0}.", foundModuleName)); 543 + Assert.That(desc.Dependencies, Contains.Item(lostModuleName), string.Format("Primary is expected to depend on {0}.", lostModuleName)); 544 + 545 + // Does SAM contain the found module? 546 + var foundTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(foundModuleName)); 547 + Assert.That(foundTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", foundModuleName)); 548 + Debug.Assert(foundTarget != null); 549 + 550 + // Does found depend on base? 551 + // ReSharper disable PossibleNullReferenceException 552 + Assert.That(foundTarget.Dependencies, Contains.Item(baseModuelName), string.Format("{1} is expected to depend on {0}.", baseModuelName, foundModuleName)); 553 + Assert.That(foundTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", foundModuleName)); 554 + 555 + // does SAM contain the lost module? 556 + var lostTarget = Sam.TargetDescriptions.FirstOrDefault(td => td.Name.Equals(lostModuleName)); 557 + Assert.That(lostTarget, Is.Not.Null, string.Format("Expected a target description of {0} in SAM.", lostModuleName)); 558 + Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostModuleName)); 559 + // ReSharper restore PossibleNullReferenceException 560 + 561 + Assert.That(lostTarget.Dependencies, Contains.Item(baseModuelName), string.Format("{1} is expected to depend on {0}.", baseModuelName, lostTarget)); 562 + Assert.That(lostTarget.BuildMessages, Is.Empty, string.Format("{0} should not have build (error) messages", lostTarget)); 563 + } 564 + } 565 + } 566 566 }
+1 -1
PrexoniteTests/Tests/ShellExtensions.cs
··· 253 253 return x + y - z; 254 254 } 255 255 "); 256 - var x = 15; 256 + const int x = 15; 257 257 Expect(x + (-x) - (-x), x); 258 258 } 259 259
+1256 -1262
PrexoniteTests/Tests/Translation.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Collections.Generic; 28 - using System.IO; 29 - using System.Linq; 30 - using JetBrains.Annotations; 31 - using Moq; 32 - using NUnit.Framework; 33 - using Prexonite; 34 - using Prexonite.Commands; 35 - using Prexonite.Compiler; 36 - using Prexonite.Compiler.Ast; 37 - using Prexonite.Compiler.Build; 38 - using Prexonite.Compiler.Symbolic; 39 - using Prexonite.Modular; 40 - using Prexonite.Types; 41 - 42 - namespace PrexoniteTests.Tests 43 - { 44 - public class Translation : VMTestsBase 45 - { 46 - [Test] 47 - public void SimpleSwitchMetaEntry() 48 - { 49 - Compile( 50 - @" 51 - globalSwitch; 52 - is gloS; 53 - is not gloS2; 54 - not glos3; 55 - 56 - function main()[loc] 57 - { 58 - 59 - } 60 - 61 - function main2 [loc2; 62 - loc3; 63 - not loc4] 64 - { 65 - } 66 - 67 - "); 68 - 69 - var main = target.Functions["main"]; 70 - var main2 = target.Functions["main2"]; 71 - 72 - //Global entries 73 - Assert.That(target, Meta.ContainsExact("globalSwitch", true)); 74 - Assert.That(target, Meta.ContainsExact("gloS", true)); 75 - Assert.That(target, Meta.ContainsExact("gloS2", false)); 76 - Assert.That(target, Meta.ContainsExact("glos3", false)); 77 - 78 - //First function 79 - Assert.That(main, Is.Not.Null); 80 - Assert.That(main, Meta.ContainsExact("loc", true)); 81 - 82 - //Second function 83 - Assert.That(main2, Is.Not.Null); 84 - Assert.That(main2, Meta.ContainsExact("loc2", true)); 85 - Assert.That(main2, Meta.ContainsExact("loc3", true)); 86 - Assert.That(main2, Meta.ContainsExact("loc4", false)); 87 - } 88 - 89 - [Test] 90 - public void TrailingCommaMetaList() 91 - { 92 - Compile(@" 93 - glob {1,2,3,}; 94 - 95 - function main [loc {1,2,3,}] 96 - {} 97 - 98 - "); 99 - 100 - var entry = new MetaEntry(new MetaEntry[] {"1", "2", "3"}); 101 - 102 - Assert.That(target, Meta.Contains("glob", entry)); 103 - var main = target.Functions["main"]; 104 - 105 - Assert.That(main, Is.Not.Null); 106 - Assert.That(main, Meta.Contains("loc", entry)); 107 - } 108 - 109 - [Test] 110 - public void TrailingCommaListLiteral() 111 - { 112 - Compile(@" 113 - function main = [1,2,3,]; 114 - "); 115 - 116 - Expect(new List<PValue> {1, 2, 3}); 117 - } 118 - 119 - [Test] 120 - public void TrailingCommaHashLiteral() 121 - { 122 - Compile( 123 - @" 124 - function main(ks,vs) 125 - { 126 - var h = {1: ""a"", 2: ""b"", 3: ""c"",}; 127 - var r = """"; 128 - for(var i = 0; i < ks.Count; i++) 129 - if(h.ContainsKey(ks[i]) and h[ks[i]] == vs[i]) 130 - r += ""1""; 131 - else 132 - r += ""0""; 133 - return r; 134 - } 135 - "); 136 - 137 - Expect("110101", (PValue) new List<PValue> {1, 2, 4, 3, 2, 1}, 138 - (PValue) new List<PValue> {"a", "b", "d", "c", "a", "a"}); 139 - } 140 - 141 - [Test] 142 - public void TrailingArgumentList() 143 - { 144 - Compile( 145 - @" 146 - function f(a,b,) = a + 2*b; 147 - function main(x,y) 148 - { 149 - return f(x,y,); 150 - } 151 - "); 152 - 153 - Expect(2 + 6, 2, 3); 154 - } 155 - 156 - [Test] 157 - public void SuppressSymbols() 158 - { 159 - var ldr = 160 - Compile( 161 - @" 162 - function g = 5; 163 - var f = 7; 164 - 165 - var g[\sps] = 3; 166 - 167 - function f as p(x) [\sps] 168 - { 169 - declare var g; 170 - return g*x; 171 - } 172 - 173 - // At this point, we should have 174 - // g -> function g 175 - // f -> variable f 176 - // p -> function f 177 - 178 - function main(x) 179 - { 180 - var f' = f; 181 - 182 - declare function f; 183 - return g + f' + f(x); 184 - } 185 - "); 186 - 187 - Expect(3*2 + 5 + 7, 2); 188 - Expect(3*11 + 5 + 7, 11); 189 - 190 - var mn = ldr.ParentApplication.Module.Name; 191 - 192 - { 193 - Assert.That(ldr.TopLevelSymbols.Contains("f"), Is.True, 194 - "Symbol table must contain an entry for 'f'."); 195 - var entry = LookupSymbolEntry(ldr.TopLevelSymbols,"f"); 196 - Assert.That(entry,Is.InstanceOf<DereferenceSymbol>()); 197 - var deref = (DereferenceSymbol) entry; 198 - Assert.That(deref.InnerSymbol,Is.InstanceOf<ReferenceSymbol>()); 199 - var refSym = (ReferenceSymbol) deref.InnerSymbol; 200 - Assert.That(refSym.Entity,Is.InstanceOf<EntityRef.Variable.Global>()); 201 - EntityRef.Variable.Global globVar; 202 - refSym.Entity.TryGetGlobalVariable(out globVar); 203 - Assert.That(globVar,Is.EqualTo(EntityRef.Variable.Global.Create("f",mn))); 204 - } 205 - 206 - { 207 - Assert.That(ldr.TopLevelSymbols.Contains("g"), Is.True, 208 - "Symbol table must contain an entry for 'g'."); 209 - var entry = LookupSymbolEntry(ldr.TopLevelSymbols, "g"); 210 - Assert.That(entry, Is.InstanceOf<DereferenceSymbol>()); 211 - var deref = (DereferenceSymbol)entry; 212 - Assert.That(deref.InnerSymbol, Is.InstanceOf<ReferenceSymbol>()); 213 - var refSym = (ReferenceSymbol)deref.InnerSymbol; 214 - Assert.That(refSym.Entity, Is.InstanceOf<EntityRef.Function>()); 215 - EntityRef.Function func; 216 - refSym.Entity.TryGetFunction(out func); 217 - Assert.That(func, Is.EqualTo(EntityRef.Function.Create("g",mn))); 218 - } 219 - 220 - { 221 - Assert.That(ldr.TopLevelSymbols.Contains("p"), Is.True, 222 - "Symbol table must contain an entry for 'p'."); 223 - var entry = LookupSymbolEntry(ldr.TopLevelSymbols, "p"); 224 - Assert.That(entry, Is.InstanceOf<DereferenceSymbol>()); 225 - var deref = (DereferenceSymbol)entry; 226 - Assert.That(deref.InnerSymbol, Is.InstanceOf<ReferenceSymbol>()); 227 - var refSym = (ReferenceSymbol)deref.InnerSymbol; 228 - Assert.That(refSym.Entity, Is.InstanceOf<EntityRef.Function>()); 229 - EntityRef.Function func; 230 - refSym.Entity.TryGetFunction(out func); 231 - Assert.That(func, Is.EqualTo(EntityRef.Function.Create("f",mn))); 232 - } 233 - } 234 - 235 - [Test] 236 - public void AppendRightLocalFunc() 237 - { 238 - Compile(@" 239 - function main() 240 - { 241 - var ys = []; 242 - coroutine trace(t,xs) 243 - { 244 - foreach(var x in xs) 245 - { 246 - ys[] = t:x; 247 - yield x; 248 - } 249 - } 250 - ([1,2]) >> trace(33) >> all >> println; 251 - return (var args >> trace(77) >> map(?~String) >> foldl((l,r) => l + "" "" + r, """")) + ys; 252 - } 253 - "); 254 - Expect(" 1 2 3 4 5 6 7[ 33: 1, 33: 2, 77: 1, 77: 2, 77: 3, 77: 4, 77: 5, 77: 6, 77: 7 ]",1,2,3,4,5,6,7); 255 - } 256 - 257 - [Test] 258 - public void TestPsrTestRunSingleTest() 259 - { 260 - Compile(@"function test\run_single_test as run_single_test(testFunc) 261 - { 262 - var t = new Structure; 263 - t.\(""test"") = testFunc; 264 - try 265 - { 266 - testFunc.(); 267 - return true: t; 268 - } 269 - catch(var e) 270 - { 271 - t.\(""e"") = e; 272 - return false: t; 273 - } 274 - } 275 - 276 - function main() 277 - { 278 - var tp = run_single_test(() => 15); 279 - return ""$(tp.Key):$(tp.Value.test.Id)""; 280 - }"); 281 - 282 - Expect("True:main\\0"); 283 - } 284 - 285 - [Test] 286 - public void TestPsrAst3WithPos() 287 - { 288 - Compile(@" 289 - function ast3\withPos(factory,type) [compiler] 290 - { 291 - var args; 292 - var targs = args >> skip(2); 293 - 294 - if(factory is null) 295 - throw ""AST factory cannot be null.""; 296 - 297 - return call\member(factory,type, targs); 298 - }"); 299 - var factory = new Mock<IAstFactory>(MockBehavior.Strict); 300 - var astPlaceholder = new AstPlaceholder(NoSourcePosition.MissingFileName, NoSourcePosition.Instance.Line, NoSourcePosition.Instance.Column); 301 - factory.Setup(f => f.Placeholder(It.IsAny<ISourcePosition>(), 5)) 302 - .Returns(astPlaceholder); 303 - ExpectNamed("ast3\\withPos", astPlaceholder, sctx.CreateNativePValue(factory.Object), "Placeholder", sctx.CreateNativePValue(NoSourcePosition.Instance), 5); 304 - } 305 - 306 - [Test] 307 - public void TestSysDeclaresMacroCommand() 308 - { 309 - Compile(@"//PRX 310 - 311 - Name sys; 312 - 313 - declare( 314 - print = ref command ""print"", 315 - println = ref command ""println"", 316 - meta = ref command ""meta"", 317 - boxed = ref command ""boxed"", 318 - concat = ref command ""concat"", 319 - map = ref command ""map"", 320 - select = ref command ""select"", 321 - foldl = ref command ""foldl"", 322 - foldr = ref command ""foldr"", 323 - dispose = ref command ""dispose"", 324 - call = expand macro command ""call"", 325 - call\perform = ref command ""call\\perform"", 326 - thunk = ref command ""thunk"", 327 - asthunk = ref command ""asthunk"", 328 - force = ref command ""force"", 329 - toseq = ref command ""toseq"", 330 - call\member = expand macro command ""call\\member"", 331 - call\member\perform = ref command ""call\\member\\perform"", 332 - caller = ref command ""caller"", 333 - pair = ref command ""pair"", 334 - unbind = ref command ""unbind"", 335 - sort = ref command ""sort"", 336 - orderby = ref command ""orderby"", 337 - LoadAssembly = ref command ""LoadAssembly"", 338 - debug = ref command ""debug"", 339 - setcenter = ref command ""setcenter"", 340 - setleft = ref command ""setleft"", 341 - setright = ref command ""setright"", 342 - all = ref command ""all"", 343 - where = ref command ""where"", 344 - skip = ref command ""skip"", 345 - limit = ref command ""limit"", 346 - take = ref command ""take"", 347 - abs = ref command ""abs"", 348 - ceiling = ref command ""ceiling"", 349 - exp = ref command ""exp"", 350 - floor = ref command ""floor"", 351 - log = ref command ""log"", 352 - max = ref command ""max"", 353 - min = ref command ""min"", 354 - pi = ref command ""pi"", 355 - round = ref command ""round"", 356 - sin = ref command ""sin"", 357 - cos = ref command ""cos"", 358 - sqrt = ref command ""sqrt"", 359 - tan = ref command ""tan"", 360 - char = ref command ""char"", 361 - count = ref command ""count"", 362 - distinct = ref command ""distinct"", 363 - union = ref command ""union"", 364 - unique = ref command ""unique"", 365 - frequency = ref command ""frequency"", 366 - groupby = ref command ""groupby"", 367 - intersect = ref command ""intersect"", 368 - call\tail = expand macro command ""call\\tail"", 369 - call\tail\perform = ref command ""call\\tail\\perform"", 370 - list = ref command ""list"", 371 - each = ref command ""each"", 372 - exists = ref command ""exists"", 373 - forall = ref command ""forall"", 374 - CompileToCil = ref command ""CompileToCil"", 375 - takewhile = ref command ""takewhile"", 376 - except = ref command ""except"", 377 - range = ref command ""range"", 378 - reverse = ref command ""reverse"", 379 - headtail = ref command ""headtail"", 380 - append = ref command ""append"", 381 - sum = ref command ""sum"", 382 - contains = ref command ""contains"", 383 - chan = ref command ""chan"", 384 - call\async = expand macro command ""call\\async"", 385 - call\async\perform = ref command ""call\\async\\perform"", 386 - async_seq = ref command ""async_seq"", 387 - call\sub\perform = ref command ""call\\sub\\perform"", 388 - pa\ind = ref command ""pa\\ind"", 389 - pa\mem = ref command ""pa\\mem"", 390 - pa\ctor = ref command ""pa\\ctor"", 391 - pa\check = ref command ""pa\\check"", 392 - pa\cast = ref command ""pa\\cast"", 393 - pa\smem = ref command ""pa\\smem"", 394 - pa\fun\call = ref command ""pa\\fun\\call"", 395 - pa\flip\call = ref command ""pa\\flip\\call"", 396 - pa\call\star = ref command ""pa\\call\\star"", 397 - then = ref command ""then"", 398 - id = ref command ""id"", 399 - const = ref command ""const"", 400 - (+) = ref command ""plus"", 401 - (-) = ref command ""minus"", 402 - (*) = ref command ""times"", 403 - (/) = ref command ""dividedBy"", 404 - $mod = ref command ""mod"", 405 - (^) = ref command ""raisedTo"", 406 - (&) = ref command ""bitwiseAnd"", 407 - (|) = ref command ""bitwiseOr"", 408 - $xor = ref command ""xor"", 409 - (==) = ref command ""isEqualTo"", 410 - (!=) = ref command ""isInequalTo"", 411 - (>) = ref command ""isGreaterThan"", 412 - (>=) = ref command ""isGreaterThanOrEqual"", 413 - (<) = ref command ""isLessThan"", 414 - (<=) = ref command ""isLessThanOrEqual"", 415 - (-.) = ref command ""negation"", 416 - $complement = ref command ""complement"", 417 - $not = ref command ""not"", 418 - create_enumerator = ref command ""create_enumerator"", 419 - create_module_name = ref command ""create_module_name"", 420 - seqconcat = ref command ""seqconcat"", 421 - call\sub = expand macro command ""call\\sub"", 422 - call\sub\interpret = expand macro command ""call\\sub\\interpret"", 423 - macro\pack = expand macro command ""macro\\pack"", 424 - macro\unpack = expand macro command ""macro\\unpack"", 425 - macro\reference = expand macro command ""macro\\reference"", 426 - call\star = expand macro command ""call\\star"", 427 - call\macro = expand macro command ""call\\macro"", 428 - call\macro\impl = expand macro command ""call\\macro\\impl"", 429 - main = ref function(""main"",""testApplication"",0.0), 430 - ); 431 - 432 - function main(x,y) 433 - { 434 - return call\member(x,y); 435 - } 436 - "); 437 - 438 - var x = new Mock<ISourcePosition>(MockBehavior.Strict); 439 - x.SetupGet(s => s.Line).Returns(15); 440 - Expect(15,sctx.CreateNativePValue(x.Object),"Line"); 441 - } 442 - 443 - [Test] 444 - public void BlockDeclarationOfMacroCommand() 445 - { 446 - Compile(@" 447 - declare macro command call\member; 448 - 449 - function main(x,y) 450 - { 451 - return call\member(x,y); 452 - } 453 - "); 454 - var x = new Mock<ISourcePosition>(MockBehavior.Strict); 455 - x.SetupGet(s => s.Line).Returns(15); 456 - Expect(15, sctx.CreateNativePValue(x.Object), "Line"); 457 - } 458 - 459 - [Test] 460 - public void ReferenceToSymbolWithMessage() 461 - { 462 - var ldr = Compile(@" 463 - function t1 = 7; 464 - ref t2 = ->t1; 465 - declare( 466 - t3 = warn(pos(""Translation.cs.pxs"",434,5),""T.tt"",""Hooder"", sym ""t2"") 467 - ); 468 - 469 - function main() 470 - { 471 - return ->t1 == ->t3; 472 - } 473 - "); 474 - 475 - Expect(true); 476 - Assert.That(ldr.Warnings.Count,Is.EqualTo(1)); 477 - Assert.That(ldr.Warnings[0].MessageClass,Is.EqualTo("T.tt")); 478 - } 479 - 480 - [Test] 481 - public void EntityRefToCommand() 482 - { 483 - var ldr = Compile(@" 484 - function f{} 485 - var v; 486 - ref r; 487 - macro m{} 488 - 489 - function main() 490 - { 491 - var loc; 492 - ref rloc; 493 - var sep = ""|""; 494 - return """" + entityref_to(f) + sep 495 - + entityref_to(v) + sep 496 - + entityref_to(->r) + sep 497 - + entityref_to(m) + sep 498 - + entityref_to(loc) + sep 499 - + entityref_to(->rloc) + sep 500 - + entityref_to(entityref_to) + sep 501 - + entityref_to(print); 502 - } 503 - "); 504 - var nm = ldr.ParentApplication.Module.Name; 505 - 506 - Expect(rv => 507 - { 508 - var r = rv.CallToString(sctx).Split('|'); 509 - Console.WriteLine(rv); 510 - Assert.That(r.Length,Is.EqualTo(8),"Expected return value to consist of 8 elements. Returned {0}",rv); 511 - 512 - Assert.That(r[0],Is.EqualTo(EntityRef.Function.Create("f",nm).ToString())); 513 - Assert.That(r[1], Is.EqualTo(EntityRef.Variable.Global.Create("v", nm).ToString())); 514 - Assert.That(r[2], Is.EqualTo(EntityRef.Variable.Global.Create("r", nm).ToString())); 515 - Assert.That(r[3], Is.EqualTo(EntityRef.Function.Create("m", nm).ToString())); 516 - Assert.That(r[4], Is.EqualTo(EntityRef.Variable.Local.Create("loc").ToString())); 517 - Assert.That(r[5], Is.EqualTo(EntityRef.Variable.Local.Create("rloc").ToString())); 518 - Assert.That(r[6], Is.EqualTo(EntityRef.MacroCommand.Create("entityref_to").ToString())); 519 - Assert.That(r[7], Is.EqualTo(EntityRef.Command.Create("print").ToString())); 520 - }); 521 - } 522 - 523 - [Test] 524 - public void NamespaceLookup() 525 - { 526 - var ldr = new Loader(options); 527 - Compile(ldr, @" 528 - function f = 17; 529 - "); 530 - Symbol f; 531 - if(!ldr.TopLevelSymbols.TryGet("f",out f)) 532 - Assert.Fail("Expected module level symbol f to exist."); 533 - 534 - var scopea = SymbolStore.Create(); 535 - scopea.Declare("g",f); 536 - var nsa = new MergedNamespace(scopea); 537 - var a = Symbol.CreateNamespace(nsa, NoSourcePosition.Instance); 538 - ldr.TopLevelSymbols.Declare("a",a); 539 - 540 - Compile(ldr, @" 541 - function main() 542 - { 543 - return a.g; 544 - } 545 - "); 546 - 547 - Expect(17); 548 - } 549 - 550 - [Test] 551 - public void NestedNamespaceLookup() 552 - { 553 - 554 - var ldr = new Loader(options); 555 - Compile(ldr, @" 556 - function f = 17; 557 - "); 558 - Symbol f; 559 - if (!ldr.TopLevelSymbols.TryGet("f", out f)) 560 - Assert.Fail("Expected module level symbol f to exist."); 561 - 562 - var scopea = SymbolStore.Create(); 563 - scopea.Declare("g", f); 564 - var nsa = new MergedNamespace(scopea); 565 - var a = Symbol.CreateNamespace(nsa, NoSourcePosition.Instance); 566 - 567 - var scopeb = SymbolStore.Create(); 568 - scopeb.Declare("a",a); 569 - var nsb = new MergedNamespace(scopeb); 570 - var b = Symbol.CreateNamespace(nsb, NoSourcePosition.Instance); 571 - 572 - ldr.TopLevelSymbols.Declare("b",b); 573 - 574 - Compile(ldr, @" 575 - function main() 576 - { 577 - return b.a.g; 578 - } 579 - "); 580 - 581 - Expect(17); 582 - } 583 - 584 - [Test] 585 - public void AliasedNamespaceLookup() 586 - { 587 - 588 - var ldr = new Loader(options); 589 - Compile(ldr, @" 590 - function f = 17; 591 - "); 592 - Symbol f; 593 - if (!ldr.TopLevelSymbols.TryGet("f", out f)) 594 - Assert.Fail("Expected module level symbol f to exist."); 595 - 596 - var scopea = SymbolStore.Create(); 597 - scopea.Declare("g", f); 598 - var nsa = new MergedNamespace(scopea); 599 - var a = Symbol.CreateNamespace(nsa, NoSourcePosition.Instance); 600 - 601 - var scopeb = SymbolStore.Create(); 602 - scopeb.Declare("a", a); 603 - var nsb = new MergedNamespace(scopeb); 604 - var b = Symbol.CreateNamespace(nsb, NoSourcePosition.Instance); 605 - 606 - ldr.TopLevelSymbols.Declare("b", b); 607 - 608 - Compile(ldr, @" 609 - declare(z = sym(""b"",""a"")); 610 - function main() 611 - { 612 - return z.g; 613 - } 614 - "); 615 - 616 - Expect(17); 617 - } 618 - 619 - [Test] 620 - public void NamespaceDeclaration() 621 - { 622 - var ldr = Compile(@" 623 - namespace a 624 - { 625 - function f = 17; 626 - } 627 - 628 - function main = a.f; 629 - "); 630 - Expect(17); 631 - Symbol dummy; 632 - Assert.That(ldr.TopLevelSymbols.TryGet("f",out dummy),Is.False,"Existence of symbol f in the global scope"); 633 - } 634 - 635 - [Test] 636 - public void SugaredNestedNamespaceDeclaration() 637 - { 638 - 639 - Compile(@" 640 - namespace a.b 641 - { 642 - function f = 17; 643 - } 644 - 645 - function main = a.b.f; 646 - "); 647 - Expect(17); 648 - } 649 - 650 - [Test] 651 - public void NestedNamespaceDeclaration() 652 - { 653 - 654 - Compile(@" 655 - namespace a 656 - { 657 - namespace b 658 - { 659 - function f = 17; 660 - } 661 - } 662 - 663 - function main = a.b.f; 664 - "); 665 - Expect(17); 666 - } 667 - 668 - [Test] 669 - public void TopLevelAccessFromNamespace() 670 - { 671 - 672 - Compile(@" 673 - function f = 17; 674 - 675 - namespace a 676 - { 677 - function g = f; 678 - } 679 - 680 - function main = a.g; 681 - "); 682 - Expect(17); 683 - } 684 - 685 - [Test] 686 - public void SurroundingAccessFromNamespace() 687 - { 688 - 689 - Compile(@" 690 - namespace a 691 - { 692 - function f = 17; 693 - namespace b 694 - { 695 - function g = f; 696 - } 697 - } 698 - 699 - function main = a.b.g; 700 - "); 701 - Expect(17); 702 - } 703 - 704 - [Test] 705 - public void Surrounding2AccessFromNamespace() 706 - { 707 - 708 - Compile(@" 709 - namespace a 710 - { 711 - function f = 17; 712 - namespace b 713 - { 714 - namespace c 715 - { 716 - function g = f; 717 - } 718 - } 719 - } 720 - 721 - function main = a.b.c.g; 722 - "); 723 - Expect(17); 724 - } 725 - 726 - [Test] 727 - public void SugarComposeNamespaces() 728 - { 729 - Compile(@" 730 - namespace a.b 731 - { 732 - function f = 17; 733 - } 734 - 735 - namespace a.c 736 - { 737 - function g = 3; 738 - } 739 - 740 - function main = a.b.f + a.c.g; 741 - "); 742 - Expect(20); 743 - } 744 - 745 - [Test] 746 - public void SugarNsOverride() 747 - { 748 - CompileInvalid(@" 749 - namespace a 750 - { 751 - function b = 13; 752 - } 753 - 754 - namespace a.b 755 - { 756 - function f = 17; 757 - } 758 - 759 - function main = a.b.f; 760 - ","Expected","namespace","func"); 761 - } 762 - 763 - [Test] 764 - public void DontReExportSurrounding() 765 - { 766 - CompileInvalid(@" 767 - function f = 13; 768 - namespace a 769 - { 770 - function g = 15; 771 - } 772 - 773 - function main = a.f; 774 - ","symbol","resolve","f"); 775 - 776 - } 777 - 778 - [Test] 779 - public void RestoreExportedOnExtend() 780 - { 781 - Compile(@" 782 - namespace a { 783 - function f = 13; 784 - } 785 - 786 - namespace a { 787 - function g = f+2; 788 - } 789 - 790 - function main = a.g; 791 - "); 792 - 793 - Expect(13+2); 794 - } 795 - 796 - [Test] 797 - public void SuppressRestoreExportedOnExtend() 798 - { 799 - CompileInvalid(@" 800 - namespace a { 801 - function zz_f = 13; 802 - } 803 - 804 - namespace a 805 - import() 806 - { 807 - function g = zz_f+2; 808 - } 809 - 810 - function main = a.g; 811 - ","symbol","resolve","zz_f"); 812 - } 813 - 814 - [Test] 815 - public void SimpleNsSugarExtend() 816 - { 817 - Compile(@" 818 - namespace a.c 819 - { 820 - function f = 17; 821 - } 822 - 823 - namespace a 824 - { 825 - namespace c 826 - { 827 - function g = 2; 828 - } 829 - } 830 - 831 - function main = a.c.f + a.c.g; 832 - "); 833 - Expect(17+2); 834 - } 835 - 836 - [Test] 837 - public void SugarNsExtend() 838 - { 839 - Compile(@" 840 - namespace a 841 - { 842 - function b = 13; 843 - } 844 - 845 - namespace a.c 846 - { 847 - function f = 17; 848 - } 849 - 850 - namespace a 851 - { 852 - function d = 10; 853 - } 854 - 855 - namespace a 856 - { 857 - namespace c 858 - { 859 - function g = 2; 860 - } 861 - } 862 - 863 - function main = a.b + a.c.f + a.d + a.c.g; 864 - "); 865 - 866 - Expect(13 + 17 + 10 + 2); 867 - } 868 - 869 - [Test] 870 - public void NsPhysical() 871 - { 872 - SkipStore = true; 873 - 874 - Compile(@" 875 - namespace a 876 - { 877 - function f = 3; 878 - } 879 - 880 - namespace b 881 - { 882 - function f = 14; 883 - } 884 - 885 - function main = a.f + b.f; 886 - "); 887 - 888 - Expect(17); 889 - } 890 - 891 - [Test] 892 - public void ImportBackgroundConflict() 893 - { 894 - Compile(@" 895 - namespace a { 896 - function f = 13; 897 - function g = 12; 898 - function x = 3; 899 - } 900 - 901 - namespace b { 902 - var g = 19; 903 - declare(f = absolute sym(""a"",""f"")); 904 - function y = 4; 905 - } 906 - 907 - namespace c 908 - import a.*, b.* 909 - { 910 - function s = f + x + y; 911 - } 912 - 913 - function main = c.s; 914 - "); 915 - 916 - Expect(4+3+13); 917 - } 918 - 919 - [Test] 920 - public void ImportConflict() 921 - { 922 - CompileInvalid(@" 923 - namespace a 924 - { 925 - function f = 13; 926 - } 927 - 928 - namespace b 929 - { 930 - var f = 14; 931 - } 932 - 933 - namespace c 934 - import a.*, b.* 935 - { 936 - function s = f; 937 - } 938 - 939 - function main = c.s; 940 - ","incompatible","namespace a","namespace b","symbol f"); 941 - } 942 - 943 - [Test] 944 - public void RenameOneAvoidsConflict() 945 - { 946 - Compile(@" 947 - namespace a 948 - { 949 - function f = 13; 950 - } 951 - 952 - namespace b 953 - { 954 - var f = 14; 955 - } 956 - 957 - namespace c 958 - import a.*, b(f => z) 959 - { 960 - function s = f + z; 961 - } 962 - 963 - function main = c.s; 964 - "); 965 - Expect(13+14); 966 - } 967 - 968 - [Test] 969 - public void UseMultiplicationAsNamespaceName() 970 - { 971 - Compile(@" 972 - namespace a.(*).c { 973 - function f = 3; 974 - } 975 - 976 - namespace b 977 - import a.(*).c.f 978 - { 979 - function g = f; 980 - } 981 - 982 - function main = b.g; 983 - "); 984 - Expect(3); 985 - } 986 - 987 - [Test] 988 - public void UseMultiplicationInExplicitTransfer() 989 - { 990 - Compile(@" 991 - namespace a { 992 - function (*) = 3; 993 - var gobb = 4; 994 - } 995 - 996 - namespace z { 997 - function gobb = 5; 998 - } 999 - 1000 - namespace b 1001 - import a((*)), z(*) // should import only (*) from a, everything from z 1002 - { 1003 - function g = (*) + gobb; 1004 - } 1005 - 1006 - function main = b.g; 1007 - "); 1008 - } 1009 - 1010 - [Test] 1011 - public void ExplicitWildcardTransfer() 1012 - { 1013 - Compile(@" 1014 - namespace a { function f = 13; } 1015 - namespace b import a(*) 1016 - { function g = f; } 1017 - function main = b.g; 1018 - "); 1019 - 1020 - Expect(13); 1021 - } 1022 - 1023 - [Test] 1024 - public void DropAvoidsConflict() 1025 - { 1026 - Compile(@" 1027 - namespace a 1028 - { 1029 - function f = 13; 1030 - } 1031 - 1032 - namespace b 1033 - { 1034 - var f = 14; 1035 - function g = 12; 1036 - } 1037 - 1038 - namespace c 1039 - import 1040 - a.*, 1041 - b(*, not f) 1042 - { 1043 - function s = f + g; 1044 - } 1045 - 1046 - function main = c.s; 1047 - "); 1048 - Expect(13 + 12); 1049 - } 1050 - 1051 - [Test] 1052 - public void FunctionScopeImport() 1053 - { 1054 - Compile(@" 1055 - namespace a 1056 - { 1057 - function f = 13; 1058 - } 1059 - 1060 - function main namespace import a.f = f; 1061 - "); 1062 - Expect(13); 1063 - } 1064 - 1065 - [Test] 1066 - public void ForwardDeclarationAncientSyntax() 1067 - { 1068 - Compile(@" 1069 - namespace a 1070 - { 1071 - declare function f; 1072 - function g(x) = f(x); 1073 - function f(x) = 2*x; 1074 - } 1075 - 1076 - function main(x) = a.g(x); 1077 - "); 1078 - 1079 - Expect(16,8); 1080 - } 1081 - 1082 - [Test] 1083 - public void ForwardDeclarationOldSyntax() 1084 - { 1085 - Compile(@" 1086 - namespace a 1087 - { 1088 - declare { function: f }; 1089 - function g(x) = f(x); 1090 - function f(x) = 2*x; 1091 - } 1092 - 1093 - function main(x) = a.g(x); 1094 - "); 1095 - 1096 - Expect(16,8); 1097 - } 1098 - 1099 - [Test] 1100 - public void ForwardDeclarationMachineSyntax() 1101 - { 1102 - Compile(@" 1103 - namespace a 1104 - { 1105 - // This forward declaration is not taken as relative to the namesapce. 1106 - // It is intended for machine consumption. 1107 - declare( f = ref function(""f"",""testApplication"",0.0)); 1108 - function g(x) = f(x); 1109 - } 1110 - 1111 - function f(x) = 2*x; 1112 - 1113 - function main(x) = a.g(x); 1114 - "); 1115 - 1116 - Expect(16, 8); 1117 - } 1118 - 1119 - [Test] 1120 - public void ExportInterferenceWithTimesLiteral() 1121 - { 1122 - Compile(@" 1123 - namespace a{var g;} 1124 - namespace b{}export(*),a(g); 1125 - "); 1126 - } 1127 - 1128 - [Test] 1129 - public void AlternateExportAllSyntax() 1130 - { 1131 - Compile(@" 1132 - namespace a{var g;} 1133 - namespace b{}export.*,a(g); 1134 - "); 1135 - } 1136 - 1137 - [Test] 1138 - public void SelfReferenceInVarInit() 1139 - { 1140 - Compile(@" 1141 - namespace a 1142 - { 1143 - var h = 4; 1144 - } 1145 - namespace a{ 1146 - var g = g ?? 15; 1147 - var h = h ?? 3; 1148 - } 1149 - 1150 - function main = a.g+a.h; 1151 - "); 1152 - Expect(15+4); 1153 - } 1154 - 1155 - [Test] 1156 - public void NamespaceExtensionCrossModule() 1157 - { 1158 - var plan = Plan.CreateSelfAssembling(StandardLibraryPreference.None); 1159 - 1160 - plan.Assemble(Source.FromString(@" 1161 - name one; 1162 - namespace a { 1163 - function b = 15; 1164 - } 1165 - ")); 1166 - 1167 - var moduleTwoDesc = plan.Assemble(Source.FromString(@" 1168 - name two; 1169 - references {one}; 1170 - namespace a { 1171 - function c =7; 1172 - } 1173 - ")); 1174 - 1175 - var moduleTwo = plan.Build(moduleTwoDesc.Name); 1176 - Assert.That(moduleTwo.Messages.Where(m => m.Severity == MessageSeverity.Error),Is.Empty,"Modules should compile without any error messages."); 1177 - foreach (var message in moduleTwo.Messages) 1178 - Console.WriteLine(message); 1179 - Assert.That(moduleTwo.Exception,Is.Null); 1180 - 1181 - var symbols = moduleTwo.Symbols; 1182 - Symbol symbol; 1183 - Assert.That(symbols.TryGet("a",out symbol),Is.True,"Expect module two to have a symbol called 'a'"); 1184 - Assert.That(symbol,Is.InstanceOf<NamespaceSymbol>()); 1185 - var nsSym = (NamespaceSymbol) symbol; 1186 - _assumeNotNull(nsSym); 1187 - Assert.That(nsSym.Namespace.TryGet("b",out symbol),"Expect namespace a to contain a symbol b."); 1188 - Assert.That(nsSym.Namespace.TryGet("c",out symbol),"Expect namespace a to contain a symbol c."); 1189 - 1190 - } 1191 - 1192 - [Test] 1193 - public void CommentAtEnd() 1194 - { 1195 - var ldr = new Loader(options); 1196 - var add = new InternalLoadCommand(ldr); 1197 - ldr.ParentEngine.Commands.AddHostCommand("add_internal", add); 1198 - add.VirtualFiles.Add("f1",@" 1199 - function f1() { 1200 - println(""f1 called""); 1201 - // something 1202 - return 15; 1203 - } 1204 - 1205 - //s"); 1206 - Compile(ldr, @" 1207 - declare command add_internal; 1208 - 1209 - function f0() { 1210 - println(""f0 called""); 1211 - /* something else */ 1212 - return 16; 1213 - } 1214 - 1215 - build does add_internal(""f1""); 1216 - 1217 - function main() { 1218 - return f0 + f1; 1219 - } 1220 - "); 1221 - 1222 - Expect(15+16); 1223 - } 1224 - 1225 - [ContractAnnotation("value:null=>halt")] 1226 - private static void _assumeNotNull(object value) 1227 - { 1228 - Assert.That(value,Is.Not.Null); 1229 - } 1230 - 1231 - /// <summary> 1232 - /// A command that works in a fashion very similar to the add and requires commands 1233 - /// that a loader exposes in build blocks. 1234 - /// Needs to be initialized first. 1235 - /// </summary> 1236 - private class InternalLoadCommand : PCommand 1237 - { 1238 - [NotNull] 1239 - private readonly Dictionary<string, string> _virtualFiles = new Dictionary<string, string>(); 1240 - [NotNull] 1241 - private readonly Loader _loaderReference; 1242 - 1243 - public InternalLoadCommand([NotNull] Loader loaderReference) 1244 - { 1245 - _loaderReference = loaderReference; 1246 - } 1247 - 1248 - public Dictionary<string, string> VirtualFiles 1249 - { 1250 - get { return _virtualFiles; } 1251 - } 1252 - 1253 - public override PValue Run(StackContext sctx, PValue[] args) 1254 - { 1255 - var n = args[0].CallToString(sctx); 1256 - var virtualFile = _virtualFiles[n]; 1257 - using(var cr = new StringReader(virtualFile)) 1258 - _loaderReference.LoadFromReader(cr,n); 1259 - return PType.Null; 1260 - } 1261 - } 1262 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Collections.Generic; 28 + using System.IO; 29 + using System.Linq; 30 + using JetBrains.Annotations; 31 + using Moq; 32 + using NUnit.Framework; 33 + using Prexonite; 34 + using Prexonite.Commands; 35 + using Prexonite.Compiler; 36 + using Prexonite.Compiler.Ast; 37 + using Prexonite.Compiler.Build; 38 + using Prexonite.Compiler.Symbolic; 39 + using Prexonite.Modular; 40 + using Prexonite.Types; 41 + 42 + namespace PrexoniteTests.Tests 43 + { 44 + public class Translation : VMTestsBase 45 + { 46 + [Test] 47 + public void SimpleSwitchMetaEntry() 48 + { 49 + Compile( 50 + @" 51 + globalSwitch; 52 + is gloS; 53 + is not gloS2; 54 + not glos3; 55 + 56 + function main()[loc] 57 + { 58 + 59 + } 60 + 61 + function main2 [loc2; 62 + loc3; 63 + not loc4] 64 + { 65 + } 66 + 67 + "); 68 + 69 + var main = target.Functions["main"]; 70 + var main2 = target.Functions["main2"]; 71 + 72 + //Global entries 73 + Assert.That(target, Meta.ContainsExact("globalSwitch", true)); 74 + Assert.That(target, Meta.ContainsExact("gloS", true)); 75 + Assert.That(target, Meta.ContainsExact("gloS2", false)); 76 + Assert.That(target, Meta.ContainsExact("glos3", false)); 77 + 78 + //First function 79 + Assert.That(main, Is.Not.Null); 80 + Assert.That(main, Meta.ContainsExact("loc", true)); 81 + 82 + //Second function 83 + Assert.That(main2, Is.Not.Null); 84 + Assert.That(main2, Meta.ContainsExact("loc2", true)); 85 + Assert.That(main2, Meta.ContainsExact("loc3", true)); 86 + Assert.That(main2, Meta.ContainsExact("loc4", false)); 87 + } 88 + 89 + [Test] 90 + public void TrailingCommaMetaList() 91 + { 92 + Compile(@" 93 + glob {1,2,3,}; 94 + 95 + function main [loc {1,2,3,}] 96 + {} 97 + 98 + "); 99 + 100 + var entry = new MetaEntry(new MetaEntry[] {"1", "2", "3"}); 101 + 102 + Assert.That(target, Meta.Contains("glob", entry)); 103 + var main = target.Functions["main"]; 104 + 105 + Assert.That(main, Is.Not.Null); 106 + Assert.That(main, Meta.Contains("loc", entry)); 107 + } 108 + 109 + [Test] 110 + public void TrailingCommaListLiteral() 111 + { 112 + Compile(@" 113 + function main = [1,2,3,]; 114 + "); 115 + 116 + Expect(new List<PValue> {1, 2, 3}); 117 + } 118 + 119 + [Test] 120 + public void TrailingCommaHashLiteral() 121 + { 122 + Compile( 123 + @" 124 + function main(ks,vs) 125 + { 126 + var h = {1: ""a"", 2: ""b"", 3: ""c"",}; 127 + var r = """"; 128 + for(var i = 0; i < ks.Count; i++) 129 + if(h.ContainsKey(ks[i]) and h[ks[i]] == vs[i]) 130 + r += ""1""; 131 + else 132 + r += ""0""; 133 + return r; 134 + } 135 + "); 136 + 137 + Expect("110101", (PValue) new List<PValue> {1, 2, 4, 3, 2, 1}, 138 + (PValue) new List<PValue> {"a", "b", "d", "c", "a", "a"}); 139 + } 140 + 141 + [Test] 142 + public void TrailingArgumentList() 143 + { 144 + Compile( 145 + @" 146 + function f(a,b,) = a + 2*b; 147 + function main(x,y) 148 + { 149 + return f(x,y,); 150 + } 151 + "); 152 + 153 + Expect(2 + 6, 2, 3); 154 + } 155 + 156 + [Test] 157 + public void SuppressSymbols() 158 + { 159 + var ldr = 160 + Compile( 161 + @" 162 + function g = 5; 163 + var f = 7; 164 + 165 + var g[\sps] = 3; 166 + 167 + function f as p(x) [\sps] 168 + { 169 + declare var g; 170 + return g*x; 171 + } 172 + 173 + // At this point, we should have 174 + // g -> function g 175 + // f -> variable f 176 + // p -> function f 177 + 178 + function main(x) 179 + { 180 + var f' = f; 181 + 182 + declare function f; 183 + return g + f' + f(x); 184 + } 185 + "); 186 + 187 + Expect(3*2 + 5 + 7, 2); 188 + Expect(3*11 + 5 + 7, 11); 189 + 190 + var mn = ldr.ParentApplication.Module.Name; 191 + 192 + { 193 + Assert.That(ldr.TopLevelSymbols.Contains("f"), Is.True, 194 + "Symbol table must contain an entry for 'f'."); 195 + var entry = LookupSymbolEntry(ldr.TopLevelSymbols,"f"); 196 + Assert.That(entry,Is.InstanceOf<DereferenceSymbol>()); 197 + var deref = (DereferenceSymbol) entry; 198 + Assert.That(deref.InnerSymbol,Is.InstanceOf<ReferenceSymbol>()); 199 + var refSym = (ReferenceSymbol) deref.InnerSymbol; 200 + Assert.That(refSym.Entity,Is.InstanceOf<EntityRef.Variable.Global>()); 201 + EntityRef.Variable.Global globVar; 202 + refSym.Entity.TryGetGlobalVariable(out globVar); 203 + Assert.That(globVar,Is.EqualTo(EntityRef.Variable.Global.Create("f",mn))); 204 + } 205 + 206 + { 207 + Assert.That(ldr.TopLevelSymbols.Contains("g"), Is.True, 208 + "Symbol table must contain an entry for 'g'."); 209 + var entry = LookupSymbolEntry(ldr.TopLevelSymbols, "g"); 210 + Assert.That(entry, Is.InstanceOf<DereferenceSymbol>()); 211 + var deref = (DereferenceSymbol)entry; 212 + Assert.That(deref.InnerSymbol, Is.InstanceOf<ReferenceSymbol>()); 213 + var refSym = (ReferenceSymbol)deref.InnerSymbol; 214 + Assert.That(refSym.Entity, Is.InstanceOf<EntityRef.Function>()); 215 + refSym.Entity.TryGetFunction(out var func); 216 + Assert.That(func, Is.EqualTo(EntityRef.Function.Create("g",mn))); 217 + } 218 + 219 + { 220 + Assert.That(ldr.TopLevelSymbols.Contains("p"), Is.True, 221 + "Symbol table must contain an entry for 'p'."); 222 + var entry = LookupSymbolEntry(ldr.TopLevelSymbols, "p"); 223 + Assert.That(entry, Is.InstanceOf<DereferenceSymbol>()); 224 + var deref = (DereferenceSymbol)entry; 225 + Assert.That(deref.InnerSymbol, Is.InstanceOf<ReferenceSymbol>()); 226 + var refSym = (ReferenceSymbol)deref.InnerSymbol; 227 + Assert.That(refSym.Entity, Is.InstanceOf<EntityRef.Function>()); 228 + refSym.Entity.TryGetFunction(out var func); 229 + Assert.That(func, Is.EqualTo(EntityRef.Function.Create("f",mn))); 230 + } 231 + } 232 + 233 + [Test] 234 + public void AppendRightLocalFunc() 235 + { 236 + Compile(@" 237 + function main() 238 + { 239 + var ys = []; 240 + coroutine trace(t,xs) 241 + { 242 + foreach(var x in xs) 243 + { 244 + ys[] = t:x; 245 + yield x; 246 + } 247 + } 248 + ([1,2]) >> trace(33) >> all >> println; 249 + return (var args >> trace(77) >> map(?~String) >> foldl((l,r) => l + "" "" + r, """")) + ys; 250 + } 251 + "); 252 + Expect(" 1 2 3 4 5 6 7[ 33: 1, 33: 2, 77: 1, 77: 2, 77: 3, 77: 4, 77: 5, 77: 6, 77: 7 ]",1,2,3,4,5,6,7); 253 + } 254 + 255 + [Test] 256 + public void TestPsrTestRunSingleTest() 257 + { 258 + Compile(@"function test\run_single_test as run_single_test(testFunc) 259 + { 260 + var t = new Structure; 261 + t.\(""test"") = testFunc; 262 + try 263 + { 264 + testFunc.(); 265 + return true: t; 266 + } 267 + catch(var e) 268 + { 269 + t.\(""e"") = e; 270 + return false: t; 271 + } 272 + } 273 + 274 + function main() 275 + { 276 + var tp = run_single_test(() => 15); 277 + return ""$(tp.Key):$(tp.Value.test.Id)""; 278 + }"); 279 + 280 + Expect("True:main\\0"); 281 + } 282 + 283 + [Test] 284 + public void TestPsrAst3WithPos() 285 + { 286 + Compile(@" 287 + function ast3\withPos(factory,type) [compiler] 288 + { 289 + var args; 290 + var targs = args >> skip(2); 291 + 292 + if(factory is null) 293 + throw ""AST factory cannot be null.""; 294 + 295 + return call\member(factory,type, targs); 296 + }"); 297 + var factory = new Mock<IAstFactory>(MockBehavior.Strict); 298 + var astPlaceholder = new AstPlaceholder(NoSourcePosition.MissingFileName, NoSourcePosition.Instance.Line, NoSourcePosition.Instance.Column); 299 + factory.Setup(f => f.Placeholder(It.IsAny<ISourcePosition>(), 5)) 300 + .Returns(astPlaceholder); 301 + ExpectNamed("ast3\\withPos", astPlaceholder, sctx.CreateNativePValue(factory.Object), "Placeholder", sctx.CreateNativePValue(NoSourcePosition.Instance), 5); 302 + } 303 + 304 + [Test] 305 + public void TestSysDeclaresMacroCommand() 306 + { 307 + Compile(@"//PRX 308 + 309 + Name sys; 310 + 311 + declare( 312 + print = ref command ""print"", 313 + println = ref command ""println"", 314 + meta = ref command ""meta"", 315 + boxed = ref command ""boxed"", 316 + concat = ref command ""concat"", 317 + map = ref command ""map"", 318 + select = ref command ""select"", 319 + foldl = ref command ""foldl"", 320 + foldr = ref command ""foldr"", 321 + dispose = ref command ""dispose"", 322 + call = expand macro command ""call"", 323 + call\perform = ref command ""call\\perform"", 324 + thunk = ref command ""thunk"", 325 + asthunk = ref command ""asthunk"", 326 + force = ref command ""force"", 327 + toseq = ref command ""toseq"", 328 + call\member = expand macro command ""call\\member"", 329 + call\member\perform = ref command ""call\\member\\perform"", 330 + caller = ref command ""caller"", 331 + pair = ref command ""pair"", 332 + unbind = ref command ""unbind"", 333 + sort = ref command ""sort"", 334 + orderby = ref command ""orderby"", 335 + LoadAssembly = ref command ""LoadAssembly"", 336 + debug = ref command ""debug"", 337 + setcenter = ref command ""setcenter"", 338 + setleft = ref command ""setleft"", 339 + setright = ref command ""setright"", 340 + all = ref command ""all"", 341 + where = ref command ""where"", 342 + skip = ref command ""skip"", 343 + limit = ref command ""limit"", 344 + take = ref command ""take"", 345 + abs = ref command ""abs"", 346 + ceiling = ref command ""ceiling"", 347 + exp = ref command ""exp"", 348 + floor = ref command ""floor"", 349 + log = ref command ""log"", 350 + max = ref command ""max"", 351 + min = ref command ""min"", 352 + pi = ref command ""pi"", 353 + round = ref command ""round"", 354 + sin = ref command ""sin"", 355 + cos = ref command ""cos"", 356 + sqrt = ref command ""sqrt"", 357 + tan = ref command ""tan"", 358 + char = ref command ""char"", 359 + count = ref command ""count"", 360 + distinct = ref command ""distinct"", 361 + union = ref command ""union"", 362 + unique = ref command ""unique"", 363 + frequency = ref command ""frequency"", 364 + groupby = ref command ""groupby"", 365 + intersect = ref command ""intersect"", 366 + call\tail = expand macro command ""call\\tail"", 367 + call\tail\perform = ref command ""call\\tail\\perform"", 368 + list = ref command ""list"", 369 + each = ref command ""each"", 370 + exists = ref command ""exists"", 371 + forall = ref command ""forall"", 372 + CompileToCil = ref command ""CompileToCil"", 373 + takewhile = ref command ""takewhile"", 374 + except = ref command ""except"", 375 + range = ref command ""range"", 376 + reverse = ref command ""reverse"", 377 + headtail = ref command ""headtail"", 378 + append = ref command ""append"", 379 + sum = ref command ""sum"", 380 + contains = ref command ""contains"", 381 + chan = ref command ""chan"", 382 + call\async = expand macro command ""call\\async"", 383 + call\async\perform = ref command ""call\\async\\perform"", 384 + async_seq = ref command ""async_seq"", 385 + call\sub\perform = ref command ""call\\sub\\perform"", 386 + pa\ind = ref command ""pa\\ind"", 387 + pa\mem = ref command ""pa\\mem"", 388 + pa\ctor = ref command ""pa\\ctor"", 389 + pa\check = ref command ""pa\\check"", 390 + pa\cast = ref command ""pa\\cast"", 391 + pa\smem = ref command ""pa\\smem"", 392 + pa\fun\call = ref command ""pa\\fun\\call"", 393 + pa\flip\call = ref command ""pa\\flip\\call"", 394 + pa\call\star = ref command ""pa\\call\\star"", 395 + then = ref command ""then"", 396 + id = ref command ""id"", 397 + const = ref command ""const"", 398 + (+) = ref command ""plus"", 399 + (-) = ref command ""minus"", 400 + (*) = ref command ""times"", 401 + (/) = ref command ""dividedBy"", 402 + $mod = ref command ""mod"", 403 + (^) = ref command ""raisedTo"", 404 + (&) = ref command ""bitwiseAnd"", 405 + (|) = ref command ""bitwiseOr"", 406 + $xor = ref command ""xor"", 407 + (==) = ref command ""isEqualTo"", 408 + (!=) = ref command ""isInequalTo"", 409 + (>) = ref command ""isGreaterThan"", 410 + (>=) = ref command ""isGreaterThanOrEqual"", 411 + (<) = ref command ""isLessThan"", 412 + (<=) = ref command ""isLessThanOrEqual"", 413 + (-.) = ref command ""negation"", 414 + $complement = ref command ""complement"", 415 + $not = ref command ""not"", 416 + create_enumerator = ref command ""create_enumerator"", 417 + create_module_name = ref command ""create_module_name"", 418 + seqconcat = ref command ""seqconcat"", 419 + call\sub = expand macro command ""call\\sub"", 420 + call\sub\interpret = expand macro command ""call\\sub\\interpret"", 421 + macro\pack = expand macro command ""macro\\pack"", 422 + macro\unpack = expand macro command ""macro\\unpack"", 423 + macro\reference = expand macro command ""macro\\reference"", 424 + call\star = expand macro command ""call\\star"", 425 + call\macro = expand macro command ""call\\macro"", 426 + call\macro\impl = expand macro command ""call\\macro\\impl"", 427 + main = ref function(""main"",""testApplication"",0.0), 428 + ); 429 + 430 + function main(x,y) 431 + { 432 + return call\member(x,y); 433 + } 434 + "); 435 + 436 + var x = new Mock<ISourcePosition>(MockBehavior.Strict); 437 + x.SetupGet(s => s.Line).Returns(15); 438 + Expect(15,sctx.CreateNativePValue(x.Object),"Line"); 439 + } 440 + 441 + [Test] 442 + public void BlockDeclarationOfMacroCommand() 443 + { 444 + Compile(@" 445 + declare macro command call\member; 446 + 447 + function main(x,y) 448 + { 449 + return call\member(x,y); 450 + } 451 + "); 452 + var x = new Mock<ISourcePosition>(MockBehavior.Strict); 453 + x.SetupGet(s => s.Line).Returns(15); 454 + Expect(15, sctx.CreateNativePValue(x.Object), "Line"); 455 + } 456 + 457 + [Test] 458 + public void ReferenceToSymbolWithMessage() 459 + { 460 + var ldr = Compile(@" 461 + function t1 = 7; 462 + ref t2 = ->t1; 463 + declare( 464 + t3 = warn(pos(""Translation.cs.pxs"",434,5),""T.tt"",""Hooder"", sym ""t2"") 465 + ); 466 + 467 + function main() 468 + { 469 + return ->t1 == ->t3; 470 + } 471 + "); 472 + 473 + Expect(true); 474 + Assert.That(ldr.Warnings.Count,Is.EqualTo(1)); 475 + Assert.That(ldr.Warnings[0].MessageClass,Is.EqualTo("T.tt")); 476 + } 477 + 478 + [Test] 479 + public void EntityRefToCommand() 480 + { 481 + var ldr = Compile(@" 482 + function f{} 483 + var v; 484 + ref r; 485 + macro m{} 486 + 487 + function main() 488 + { 489 + var loc; 490 + ref rloc; 491 + var sep = ""|""; 492 + return """" + entityref_to(f) + sep 493 + + entityref_to(v) + sep 494 + + entityref_to(->r) + sep 495 + + entityref_to(m) + sep 496 + + entityref_to(loc) + sep 497 + + entityref_to(->rloc) + sep 498 + + entityref_to(entityref_to) + sep 499 + + entityref_to(print); 500 + } 501 + "); 502 + var nm = ldr.ParentApplication.Module.Name; 503 + 504 + Expect(rv => 505 + { 506 + var r = rv.CallToString(sctx).Split('|'); 507 + Console.WriteLine(rv); 508 + Assert.That((object) r.Length,Is.EqualTo(8),"Expected return value to consist of 8 elements. Returned {0}",rv); 509 + 510 + Assert.That(r[0], Is.EqualTo(EntityRef.Function.Create("f",nm).ToString())); 511 + Assert.That(r[1], Is.EqualTo(EntityRef.Variable.Global.Create("v", nm).ToString())); 512 + Assert.That(r[2], Is.EqualTo(EntityRef.Variable.Global.Create("r", nm).ToString())); 513 + Assert.That(r[3], Is.EqualTo(EntityRef.Function.Create("m", nm).ToString())); 514 + Assert.That(r[4], Is.EqualTo(EntityRef.Variable.Local.Create("loc").ToString())); 515 + Assert.That(r[5], Is.EqualTo(EntityRef.Variable.Local.Create("rloc").ToString())); 516 + Assert.That(r[6], Is.EqualTo(EntityRef.MacroCommand.Create("entityref_to").ToString())); 517 + Assert.That(r[7], Is.EqualTo(EntityRef.Command.Create("print").ToString())); 518 + }); 519 + } 520 + 521 + [Test] 522 + public void NamespaceLookup() 523 + { 524 + var ldr = new Loader(options); 525 + Compile(ldr, @" 526 + function f = 17; 527 + "); 528 + Symbol f; 529 + if(!ldr.TopLevelSymbols.TryGet("f",out f)) 530 + Assert.Fail("Expected module level symbol f to exist."); 531 + 532 + var scopea = SymbolStore.Create(); 533 + scopea.Declare("g",f); 534 + var nsa = new MergedNamespace(scopea); 535 + var a = Symbol.CreateNamespace(nsa, NoSourcePosition.Instance); 536 + ldr.TopLevelSymbols.Declare("a",a); 537 + 538 + Compile(ldr, @" 539 + function main() 540 + { 541 + return a.g; 542 + } 543 + "); 544 + 545 + Expect(17); 546 + } 547 + 548 + [Test] 549 + public void NestedNamespaceLookup() 550 + { 551 + 552 + var ldr = new Loader(options); 553 + Compile(ldr, @" 554 + function f = 17; 555 + "); 556 + Symbol f; 557 + if (!ldr.TopLevelSymbols.TryGet("f", out f)) 558 + Assert.Fail("Expected module level symbol f to exist."); 559 + 560 + var scopea = SymbolStore.Create(); 561 + scopea.Declare("g", f); 562 + var nsa = new MergedNamespace(scopea); 563 + var a = Symbol.CreateNamespace(nsa, NoSourcePosition.Instance); 564 + 565 + var scopeb = SymbolStore.Create(); 566 + scopeb.Declare("a",a); 567 + var nsb = new MergedNamespace(scopeb); 568 + var b = Symbol.CreateNamespace(nsb, NoSourcePosition.Instance); 569 + 570 + ldr.TopLevelSymbols.Declare("b",b); 571 + 572 + Compile(ldr, @" 573 + function main() 574 + { 575 + return b.a.g; 576 + } 577 + "); 578 + 579 + Expect(17); 580 + } 581 + 582 + [Test] 583 + public void AliasedNamespaceLookup() 584 + { 585 + 586 + var ldr = new Loader(options); 587 + Compile(ldr, @" 588 + function f = 17; 589 + "); 590 + Symbol f; 591 + if (!ldr.TopLevelSymbols.TryGet("f", out f)) 592 + Assert.Fail("Expected module level symbol f to exist."); 593 + 594 + var scopea = SymbolStore.Create(); 595 + scopea.Declare("g", f); 596 + var nsa = new MergedNamespace(scopea); 597 + var a = Symbol.CreateNamespace(nsa, NoSourcePosition.Instance); 598 + 599 + var scopeb = SymbolStore.Create(); 600 + scopeb.Declare("a", a); 601 + var nsb = new MergedNamespace(scopeb); 602 + var b = Symbol.CreateNamespace(nsb, NoSourcePosition.Instance); 603 + 604 + ldr.TopLevelSymbols.Declare("b", b); 605 + 606 + Compile(ldr, @" 607 + declare(z = sym(""b"",""a"")); 608 + function main() 609 + { 610 + return z.g; 611 + } 612 + "); 613 + 614 + Expect(17); 615 + } 616 + 617 + [Test] 618 + public void NamespaceDeclaration() 619 + { 620 + var ldr = Compile(@" 621 + namespace a 622 + { 623 + function f = 17; 624 + } 625 + 626 + function main = a.f; 627 + "); 628 + Expect(17); 629 + Symbol dummy; 630 + Assert.That(ldr.TopLevelSymbols.TryGet("f",out dummy),Is.False,"Existence of symbol f in the global scope"); 631 + } 632 + 633 + [Test] 634 + public void SugaredNestedNamespaceDeclaration() 635 + { 636 + 637 + Compile(@" 638 + namespace a.b 639 + { 640 + function f = 17; 641 + } 642 + 643 + function main = a.b.f; 644 + "); 645 + Expect(17); 646 + } 647 + 648 + [Test] 649 + public void NestedNamespaceDeclaration() 650 + { 651 + 652 + Compile(@" 653 + namespace a 654 + { 655 + namespace b 656 + { 657 + function f = 17; 658 + } 659 + } 660 + 661 + function main = a.b.f; 662 + "); 663 + Expect(17); 664 + } 665 + 666 + [Test] 667 + public void TopLevelAccessFromNamespace() 668 + { 669 + 670 + Compile(@" 671 + function f = 17; 672 + 673 + namespace a 674 + { 675 + function g = f; 676 + } 677 + 678 + function main = a.g; 679 + "); 680 + Expect(17); 681 + } 682 + 683 + [Test] 684 + public void SurroundingAccessFromNamespace() 685 + { 686 + 687 + Compile(@" 688 + namespace a 689 + { 690 + function f = 17; 691 + namespace b 692 + { 693 + function g = f; 694 + } 695 + } 696 + 697 + function main = a.b.g; 698 + "); 699 + Expect(17); 700 + } 701 + 702 + [Test] 703 + public void Surrounding2AccessFromNamespace() 704 + { 705 + 706 + Compile(@" 707 + namespace a 708 + { 709 + function f = 17; 710 + namespace b 711 + { 712 + namespace c 713 + { 714 + function g = f; 715 + } 716 + } 717 + } 718 + 719 + function main = a.b.c.g; 720 + "); 721 + Expect(17); 722 + } 723 + 724 + [Test] 725 + public void SugarComposeNamespaces() 726 + { 727 + Compile(@" 728 + namespace a.b 729 + { 730 + function f = 17; 731 + } 732 + 733 + namespace a.c 734 + { 735 + function g = 3; 736 + } 737 + 738 + function main = a.b.f + a.c.g; 739 + "); 740 + Expect(20); 741 + } 742 + 743 + [Test] 744 + public void SugarNsOverride() 745 + { 746 + CompileInvalid(@" 747 + namespace a 748 + { 749 + function b = 13; 750 + } 751 + 752 + namespace a.b 753 + { 754 + function f = 17; 755 + } 756 + 757 + function main = a.b.f; 758 + ","Expected","namespace","func"); 759 + } 760 + 761 + [Test] 762 + public void DontReExportSurrounding() 763 + { 764 + CompileInvalid(@" 765 + function f = 13; 766 + namespace a 767 + { 768 + function g = 15; 769 + } 770 + 771 + function main = a.f; 772 + ","symbol","resolve","f"); 773 + 774 + } 775 + 776 + [Test] 777 + public void RestoreExportedOnExtend() 778 + { 779 + Compile(@" 780 + namespace a { 781 + function f = 13; 782 + } 783 + 784 + namespace a { 785 + function g = f+2; 786 + } 787 + 788 + function main = a.g; 789 + "); 790 + 791 + Expect(13+2); 792 + } 793 + 794 + [Test] 795 + public void SuppressRestoreExportedOnExtend() 796 + { 797 + CompileInvalid(@" 798 + namespace a { 799 + function zz_f = 13; 800 + } 801 + 802 + namespace a 803 + import() 804 + { 805 + function g = zz_f+2; 806 + } 807 + 808 + function main = a.g; 809 + ","symbol","resolve","zz_f"); 810 + } 811 + 812 + [Test] 813 + public void SimpleNsSugarExtend() 814 + { 815 + Compile(@" 816 + namespace a.c 817 + { 818 + function f = 17; 819 + } 820 + 821 + namespace a 822 + { 823 + namespace c 824 + { 825 + function g = 2; 826 + } 827 + } 828 + 829 + function main = a.c.f + a.c.g; 830 + "); 831 + Expect(17+2); 832 + } 833 + 834 + [Test] 835 + public void SugarNsExtend() 836 + { 837 + Compile(@" 838 + namespace a 839 + { 840 + function b = 13; 841 + } 842 + 843 + namespace a.c 844 + { 845 + function f = 17; 846 + } 847 + 848 + namespace a 849 + { 850 + function d = 10; 851 + } 852 + 853 + namespace a 854 + { 855 + namespace c 856 + { 857 + function g = 2; 858 + } 859 + } 860 + 861 + function main = a.b + a.c.f + a.d + a.c.g; 862 + "); 863 + 864 + Expect(13 + 17 + 10 + 2); 865 + } 866 + 867 + [Test] 868 + public void NsPhysical() 869 + { 870 + SkipStore = true; 871 + 872 + Compile(@" 873 + namespace a 874 + { 875 + function f = 3; 876 + } 877 + 878 + namespace b 879 + { 880 + function f = 14; 881 + } 882 + 883 + function main = a.f + b.f; 884 + "); 885 + 886 + Expect(17); 887 + } 888 + 889 + [Test] 890 + public void ImportBackgroundConflict() 891 + { 892 + Compile(@" 893 + namespace a { 894 + function f = 13; 895 + function g = 12; 896 + function x = 3; 897 + } 898 + 899 + namespace b { 900 + var g = 19; 901 + declare(f = absolute sym(""a"",""f"")); 902 + function y = 4; 903 + } 904 + 905 + namespace c 906 + import a.*, b.* 907 + { 908 + function s = f + x + y; 909 + } 910 + 911 + function main = c.s; 912 + "); 913 + 914 + Expect(4+3+13); 915 + } 916 + 917 + [Test] 918 + public void ImportConflict() 919 + { 920 + CompileInvalid(@" 921 + namespace a 922 + { 923 + function f = 13; 924 + } 925 + 926 + namespace b 927 + { 928 + var f = 14; 929 + } 930 + 931 + namespace c 932 + import a.*, b.* 933 + { 934 + function s = f; 935 + } 936 + 937 + function main = c.s; 938 + ","incompatible","namespace a","namespace b","symbol f"); 939 + } 940 + 941 + [Test] 942 + public void RenameOneAvoidsConflict() 943 + { 944 + Compile(@" 945 + namespace a 946 + { 947 + function f = 13; 948 + } 949 + 950 + namespace b 951 + { 952 + var f = 14; 953 + } 954 + 955 + namespace c 956 + import a.*, b(f => z) 957 + { 958 + function s = f + z; 959 + } 960 + 961 + function main = c.s; 962 + "); 963 + Expect(13+14); 964 + } 965 + 966 + [Test] 967 + public void UseMultiplicationAsNamespaceName() 968 + { 969 + Compile(@" 970 + namespace a.(*).c { 971 + function f = 3; 972 + } 973 + 974 + namespace b 975 + import a.(*).c.f 976 + { 977 + function g = f; 978 + } 979 + 980 + function main = b.g; 981 + "); 982 + Expect(3); 983 + } 984 + 985 + [Test] 986 + public void UseMultiplicationInExplicitTransfer() 987 + { 988 + Compile(@" 989 + namespace a { 990 + function (*) = 3; 991 + var gobb = 4; 992 + } 993 + 994 + namespace z { 995 + function gobb = 5; 996 + } 997 + 998 + namespace b 999 + import a((*)), z(*) // should import only (*) from a, everything from z 1000 + { 1001 + function g = (*) + gobb; 1002 + } 1003 + 1004 + function main = b.g; 1005 + "); 1006 + } 1007 + 1008 + [Test] 1009 + public void ExplicitWildcardTransfer() 1010 + { 1011 + Compile(@" 1012 + namespace a { function f = 13; } 1013 + namespace b import a(*) 1014 + { function g = f; } 1015 + function main = b.g; 1016 + "); 1017 + 1018 + Expect(13); 1019 + } 1020 + 1021 + [Test] 1022 + public void DropAvoidsConflict() 1023 + { 1024 + Compile(@" 1025 + namespace a 1026 + { 1027 + function f = 13; 1028 + } 1029 + 1030 + namespace b 1031 + { 1032 + var f = 14; 1033 + function g = 12; 1034 + } 1035 + 1036 + namespace c 1037 + import 1038 + a.*, 1039 + b(*, not f) 1040 + { 1041 + function s = f + g; 1042 + } 1043 + 1044 + function main = c.s; 1045 + "); 1046 + Expect(13 + 12); 1047 + } 1048 + 1049 + [Test] 1050 + public void FunctionScopeImport() 1051 + { 1052 + Compile(@" 1053 + namespace a 1054 + { 1055 + function f = 13; 1056 + } 1057 + 1058 + function main namespace import a.f = f; 1059 + "); 1060 + Expect(13); 1061 + } 1062 + 1063 + [Test] 1064 + public void ForwardDeclarationAncientSyntax() 1065 + { 1066 + Compile(@" 1067 + namespace a 1068 + { 1069 + declare function f; 1070 + function g(x) = f(x); 1071 + function f(x) = 2*x; 1072 + } 1073 + 1074 + function main(x) = a.g(x); 1075 + "); 1076 + 1077 + Expect(16,8); 1078 + } 1079 + 1080 + [Test] 1081 + public void ForwardDeclarationOldSyntax() 1082 + { 1083 + Compile(@" 1084 + namespace a 1085 + { 1086 + declare { function: f }; 1087 + function g(x) = f(x); 1088 + function f(x) = 2*x; 1089 + } 1090 + 1091 + function main(x) = a.g(x); 1092 + "); 1093 + 1094 + Expect(16,8); 1095 + } 1096 + 1097 + [Test] 1098 + public void ForwardDeclarationMachineSyntax() 1099 + { 1100 + Compile(@" 1101 + namespace a 1102 + { 1103 + // This forward declaration is not taken as relative to the namesapce. 1104 + // It is intended for machine consumption. 1105 + declare( f = ref function(""f"",""testApplication"",0.0)); 1106 + function g(x) = f(x); 1107 + } 1108 + 1109 + function f(x) = 2*x; 1110 + 1111 + function main(x) = a.g(x); 1112 + "); 1113 + 1114 + Expect(16, 8); 1115 + } 1116 + 1117 + [Test] 1118 + public void ExportInterferenceWithTimesLiteral() 1119 + { 1120 + Compile(@" 1121 + namespace a{var g;} 1122 + namespace b{}export(*),a(g); 1123 + "); 1124 + } 1125 + 1126 + [Test] 1127 + public void AlternateExportAllSyntax() 1128 + { 1129 + Compile(@" 1130 + namespace a{var g;} 1131 + namespace b{}export.*,a(g); 1132 + "); 1133 + } 1134 + 1135 + [Test] 1136 + public void SelfReferenceInVarInit() 1137 + { 1138 + Compile(@" 1139 + namespace a 1140 + { 1141 + var h = 4; 1142 + } 1143 + namespace a{ 1144 + var g = g ?? 15; 1145 + var h = h ?? 3; 1146 + } 1147 + 1148 + function main = a.g+a.h; 1149 + "); 1150 + Expect(15+4); 1151 + } 1152 + 1153 + [Test] 1154 + public void NamespaceExtensionCrossModule() 1155 + { 1156 + var plan = Plan.CreateSelfAssembling(StandardLibraryPreference.None); 1157 + 1158 + plan.Assemble(Source.FromString(@" 1159 + name one; 1160 + namespace a { 1161 + function b = 15; 1162 + } 1163 + ")); 1164 + 1165 + var moduleTwoDesc = plan.Assemble(Source.FromString(@" 1166 + name two; 1167 + references {one}; 1168 + namespace a { 1169 + function c =7; 1170 + } 1171 + ")); 1172 + 1173 + var moduleTwo = plan.Build(moduleTwoDesc.Name); 1174 + Assert.That(moduleTwo.Messages.Where(m => m.Severity == MessageSeverity.Error),Is.Empty,"Modules should compile without any error messages."); 1175 + foreach (var message in moduleTwo.Messages) 1176 + Console.WriteLine(message); 1177 + Assert.That(moduleTwo.Exception,Is.Null); 1178 + 1179 + var symbols = moduleTwo.Symbols; 1180 + Assert.That(symbols.TryGet("a",out var symbol),Is.True,"Expect module two to have a symbol called 'a'"); 1181 + Assert.That(symbol,Is.InstanceOf<NamespaceSymbol>()); 1182 + var nsSym = (NamespaceSymbol) symbol; 1183 + _assumeNotNull(nsSym); 1184 + Assert.That(nsSym.Namespace.TryGet("b",out symbol),"Expect namespace a to contain a symbol b."); 1185 + Assert.That(nsSym.Namespace.TryGet("c",out symbol),"Expect namespace a to contain a symbol c."); 1186 + 1187 + } 1188 + 1189 + [Test] 1190 + public void CommentAtEnd() 1191 + { 1192 + var ldr = new Loader(options); 1193 + var add = new InternalLoadCommand(ldr); 1194 + ldr.ParentEngine.Commands.AddHostCommand("add_internal", add); 1195 + add.VirtualFiles.Add("f1",@" 1196 + function f1() { 1197 + println(""f1 called""); 1198 + // something 1199 + return 15; 1200 + } 1201 + 1202 + //s"); 1203 + Compile(ldr, @" 1204 + declare command add_internal; 1205 + 1206 + function f0() { 1207 + println(""f0 called""); 1208 + /* something else */ 1209 + return 16; 1210 + } 1211 + 1212 + build does add_internal(""f1""); 1213 + 1214 + function main() { 1215 + return f0 + f1; 1216 + } 1217 + "); 1218 + 1219 + Expect(15+16); 1220 + } 1221 + 1222 + [ContractAnnotation("value:null=>halt")] 1223 + private static void _assumeNotNull(object value) 1224 + { 1225 + Assert.That(value,Is.Not.Null); 1226 + } 1227 + 1228 + /// <summary> 1229 + /// A command that works in a fashion very similar to the add and requires commands 1230 + /// that a loader exposes in build blocks. 1231 + /// Needs to be initialized first. 1232 + /// </summary> 1233 + private class InternalLoadCommand : PCommand 1234 + { 1235 + [NotNull] 1236 + private readonly Dictionary<string, string> _virtualFiles = new Dictionary<string, string>(); 1237 + [NotNull] 1238 + private readonly Loader _loaderReference; 1239 + 1240 + public InternalLoadCommand([NotNull] Loader loaderReference) 1241 + { 1242 + _loaderReference = loaderReference; 1243 + } 1244 + 1245 + public Dictionary<string, string> VirtualFiles => _virtualFiles; 1246 + 1247 + public override PValue Run(StackContext sctx, PValue[] args) 1248 + { 1249 + var n = args[0].CallToString(sctx); 1250 + var virtualFile = _virtualFiles[n]; 1251 + using(var cr = new StringReader(virtualFile)) 1252 + _loaderReference.LoadFromReader(cr,n); 1253 + return PType.Null; 1254 + } 1255 + } 1256 + } 1263 1257 }
+186 -186
PrexoniteTests/Tests/TypeSystem.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Threading; 28 - using NUnit.Framework; 29 - using Prexonite; 30 - using Prexonite.Types; 31 - using Prx.Tests; 32 - 33 - namespace PrexoniteTests.Tests 34 - { 35 - [TestFixture(Description = "General type system checks")] 36 - public class TypeSystem 37 - { 38 - private Engine engine; 39 - private StackContext sctx; 40 - 41 - [TestFixtureSetUp] 42 - public void SetupTypeSystemEngine() 43 - { 44 - engine = new Engine(); 45 - sctx = new TestStackContext(engine, new Application()); 46 - } 47 - 48 - [TestFixtureTearDown] 49 - public void TeardownTypeSystemEngine() 50 - { 51 - engine = null; 52 - sctx = null; 53 - } 54 - 55 - [Test(Description = "Does a number of set and get calls on a mock object")] 56 - public void TestFieldAccess() 57 - { 58 - //obj.Subject = 55; 59 - //obj.Count = obj.Subject; 60 - var test = new TestObject(); 61 - var obj = engine.CreateNativePValue(test); 62 - Assert.AreEqual(obj.Type, PType.Object[typeof (TestObject)]); 63 - Assert.AreSame(test, obj.Value); 64 - 65 - //Set obj.Subject = 55 66 - obj.DynamicCall( 67 - sctx, 68 - new PValue[] {55}, 69 - PCall.Set, 70 - "Subject"); 71 - Assert.AreSame(test, obj.Value); 72 - Assert.AreEqual(test.Subject, ((TestObject) obj.Value).Subject); 73 - 74 - //Get res = obj.Subject 75 - var res = obj.DynamicCall( 76 - sctx, 77 - new PValue[] {}, 78 - PCall.Get, 79 - "Subject"); 80 - Assert.AreEqual(test.Subject, res.Value); 81 - 82 - //Set obj.Count = res 83 - obj.DynamicCall( 84 - sctx, 85 - new[] {res}, 86 - PCall.Set, 87 - "Count"); 88 - Assert.AreEqual(55, test.Count); 89 - 90 - //Get res = obj.Count 91 - res = obj.DynamicCall( 92 - sctx, 93 - new PValue[] {}, 94 - PCall.Get, 95 - "Count"); 96 - Assert.AreEqual(55, test.Count); 97 - Assert.AreEqual(55, (int) res.Value); 98 - } 99 - 100 - [Test(Description = "Test the implicit [basic] to [PValue] conversion operators")] 101 - public void TestImplicitPValueConversion() 102 - { 103 - PValue obj; 104 - 105 - obj = 55; 106 - Assert.AreSame(PType.Int, obj.Type); 107 - 108 - obj = 5.5; 109 - Assert.AreSame(PType.Real, obj.Type); 110 - 111 - obj = true; 112 - Assert.AreSame(PType.Bool, obj.Type); 113 - 114 - obj = "Hello World"; 115 - Assert.AreSame(PType.String, obj.Type); 116 - } 117 - 118 - [Test(Description = "PType creation from type name.")] 119 - public void TestPTypeCreationUsingClrObjects_name() 120 - { 121 - var res = 122 - sctx.ConstructPType( 123 - "Object", new[] {PType.Object.CreatePValue(typeof (Int32))}); 124 - Assert.AreEqual(PType.Object[typeof (Int32)], res); 125 - } 126 - 127 - [Test(Description = "PType creation from type")] 128 - public void TestPTypeCreationUsingClrObjects_type() 129 - { 130 - var res = 131 - sctx.ConstructPType( 132 - typeof (ObjectPType), new[] {PType.Object.CreatePValue(typeof (DateTime))}); 133 - Assert.AreEqual(PType.Object[typeof (DateTime)], res); 134 - } 135 - 136 - [Test(Description = "PType creation from type as ClrPType")] 137 - public void TestPTypeCreationUsingClrObjects_clrtype() 138 - { 139 - var res = 140 - sctx.ConstructPType( 141 - PType.Object[typeof (ObjectPType)], 142 - new[] {PType.Object.CreatePValue(typeof (Thread))}); 143 - Assert.AreEqual(PType.Object[typeof (Thread)], res); 144 - } 145 - 146 - [Test(Description = "Creation of a ClrPType from a fqTypeName")] 147 - public void TestTypeResolving() 148 - { 149 - var res = new ObjectPType(sctx, "System.Threading.Thread"); 150 - Assert.AreEqual(PType.Object[typeof (Thread)], res); 151 - } 152 - 153 - [Test(Description = "PType creation from type simple expression")] 154 - public void TestPTypeCreationUsingExpression_simple() 155 - { 156 - var res = sctx.ConstructPType("Object(\"System.Threading.Thread\")"); 157 - Assert.AreEqual(PType.Object[typeof (Thread)], res); 158 - } 159 - 160 - [Test] 161 - public void NativePValue() 162 - { 163 - var str = "Hello "; 164 - var nStr = engine.CreateNativePValue(str); 165 - Assert.IsInstanceOf(typeof (StringPType), nStr.Type); 166 - Assert.AreSame(str, nStr.Value); 167 - } 168 - 169 - [Test] 170 - public void TestStringEscape() 171 - { 172 - var sEscaped = @"This is a \n followed by a \ttab and an umlaut: \x" + 173 - ((int) '�').ToString("X") + 174 - " escape sequence."; 175 - var sUnescaped = "This is a \n followed by a \ttab and an umlaut: � escape sequence."; 176 - 177 - var escaped = PType.String.CreatePValue(sEscaped); 178 - PValue unescaped; 179 - Assert.IsTrue( 180 - escaped.TryDynamicCall(sctx, new PValue[] {}, PCall.Get, "unescape", out unescaped)); 181 - Assert.AreEqual(sUnescaped, unescaped.Value as string); 182 - Assert.IsTrue( 183 - unescaped.TryDynamicCall(sctx, new PValue[] {}, PCall.Get, "escape", out escaped)); 184 - Assert.AreEqual(sEscaped, escaped.Value as string); 185 - } 186 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Threading; 28 + using NUnit.Framework; 29 + using Prexonite; 30 + using Prexonite.Types; 31 + using Prx.Tests; 32 + 33 + namespace PrexoniteTests.Tests 34 + { 35 + [TestFixture(Description = "General type system checks")] 36 + public class TypeSystem 37 + { 38 + private Engine engine; 39 + private StackContext sctx; 40 + 41 + [OneTimeSetUp] 42 + public void SetupTypeSystemEngine() 43 + { 44 + engine = new Engine(); 45 + sctx = new TestStackContext(engine, new Application()); 46 + } 47 + 48 + [OneTimeTearDown] 49 + public void TeardownTypeSystemEngine() 50 + { 51 + engine = null; 52 + sctx = null; 53 + } 54 + 55 + [Test(Description = "Does a number of set and get calls on a mock object")] 56 + public void TestFieldAccess() 57 + { 58 + //obj.Subject = 55; 59 + //obj.Count = obj.Subject; 60 + var test = new TestObject(); 61 + var obj = engine.CreateNativePValue(test); 62 + Assert.AreEqual(obj.Type, PType.Object[typeof (TestObject)]); 63 + Assert.AreSame(test, obj.Value); 64 + 65 + //Set obj.Subject = 55 66 + obj.DynamicCall( 67 + sctx, 68 + new PValue[] {55}, 69 + PCall.Set, 70 + "Subject"); 71 + Assert.AreSame(test, obj.Value); 72 + Assert.AreEqual(test.Subject, ((TestObject) obj.Value).Subject); 73 + 74 + //Get res = obj.Subject 75 + var res = obj.DynamicCall( 76 + sctx, 77 + new PValue[] {}, 78 + PCall.Get, 79 + "Subject"); 80 + Assert.AreEqual(test.Subject, res.Value); 81 + 82 + //Set obj.Count = res 83 + obj.DynamicCall( 84 + sctx, 85 + new[] {res}, 86 + PCall.Set, 87 + "Count"); 88 + Assert.AreEqual(55, test.Count); 89 + 90 + //Get res = obj.Count 91 + res = obj.DynamicCall( 92 + sctx, 93 + new PValue[] {}, 94 + PCall.Get, 95 + "Count"); 96 + Assert.AreEqual(55, test.Count); 97 + Assert.AreEqual(55, (int) res.Value); 98 + } 99 + 100 + [Test(Description = "Test the implicit [basic] to [PValue] conversion operators")] 101 + public void TestImplicitPValueConversion() 102 + { 103 + PValue obj; 104 + 105 + obj = 55; 106 + Assert.AreSame(PType.Int, obj.Type); 107 + 108 + obj = 5.5; 109 + Assert.AreSame(PType.Real, obj.Type); 110 + 111 + obj = true; 112 + Assert.AreSame(PType.Bool, obj.Type); 113 + 114 + obj = "Hello World"; 115 + Assert.AreSame(PType.String, obj.Type); 116 + } 117 + 118 + [Test(Description = "PType creation from type name.")] 119 + public void TestPTypeCreationUsingClrObjects_name() 120 + { 121 + var res = 122 + sctx.ConstructPType( 123 + "Object", new[] {PType.Object.CreatePValue(typeof (Int32))}); 124 + Assert.AreEqual(PType.Object[typeof (Int32)], res); 125 + } 126 + 127 + [Test(Description = "PType creation from type")] 128 + public void TestPTypeCreationUsingClrObjects_type() 129 + { 130 + var res = 131 + sctx.ConstructPType( 132 + typeof (ObjectPType), new[] {PType.Object.CreatePValue(typeof (DateTime))}); 133 + Assert.AreEqual(PType.Object[typeof (DateTime)], res); 134 + } 135 + 136 + [Test(Description = "PType creation from type as ClrPType")] 137 + public void TestPTypeCreationUsingClrObjects_clrtype() 138 + { 139 + var res = 140 + sctx.ConstructPType( 141 + PType.Object[typeof (ObjectPType)], 142 + new[] {PType.Object.CreatePValue(typeof (Thread))}); 143 + Assert.AreEqual(PType.Object[typeof (Thread)], res); 144 + } 145 + 146 + [Test(Description = "Creation of a ClrPType from a fqTypeName")] 147 + public void TestTypeResolving() 148 + { 149 + var res = new ObjectPType(sctx, "System.Threading.Thread"); 150 + Assert.AreEqual(PType.Object[typeof (Thread)], res); 151 + } 152 + 153 + [Test(Description = "PType creation from type simple expression")] 154 + public void TestPTypeCreationUsingExpression_simple() 155 + { 156 + var res = sctx.ConstructPType("Object(\"System.Threading.Thread\")"); 157 + Assert.AreEqual(PType.Object[typeof (Thread)], res); 158 + } 159 + 160 + [Test] 161 + public void NativePValue() 162 + { 163 + var str = "Hello "; 164 + var nStr = engine.CreateNativePValue(str); 165 + Assert.IsInstanceOf(typeof (StringPType), nStr.Type); 166 + Assert.AreSame(str, nStr.Value); 167 + } 168 + 169 + [Test] 170 + public void TestStringEscape() 171 + { 172 + var sEscaped = @"This is a \n followed by a \ttab and an umlaut: \x" + 173 + ((int) '�').ToString("X") + 174 + " escape sequence."; 175 + var sUnescaped = "This is a \n followed by a \ttab and an umlaut: � escape sequence."; 176 + 177 + var escaped = PType.String.CreatePValue(sEscaped); 178 + PValue unescaped; 179 + Assert.IsTrue( 180 + escaped.TryDynamicCall(sctx, new PValue[] {}, PCall.Get, "unescape", out unescaped)); 181 + Assert.AreEqual(sUnescaped, unescaped.Value as string); 182 + Assert.IsTrue( 183 + unescaped.TryDynamicCall(sctx, new PValue[] {}, PCall.Get, "escape", out escaped)); 184 + Assert.AreEqual(sEscaped, escaped.Value as string); 185 + } 186 + } 187 187 }
+488 -488
PrexoniteTests/Tests/VMTests.Macro.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - #if ((!(DEBUG || Verbose)) || forceIndex) && allowIndex 27 - #define useIndex 28 - #endif 29 - 30 - #define UseCil 31 - //need to change this in VMTestsBase.cs too! 32 - 33 - using System; 34 - using System.Collections.Generic; 35 - using NUnit.Framework; 36 - using Prexonite; 37 - using Prexonite.Compiler; 38 - using Prexonite.Compiler.Ast; 39 - using Prexonite.Compiler.Macro.Commands; 40 - using Prexonite.Modular; 41 - using Prexonite.Types; 42 - using PrexoniteTests.Tests; 43 - 44 - namespace Prx.Tests 45 - { 46 - public abstract partial class VMTests : VMTestsBase 47 - { 48 - [Test] 49 - public void CallSubMacroCommandNested() 50 - { 51 - CompileInvalid( 52 - @" 53 - function main(xs) 54 - { 55 - var zs = []; 56 - function f(x) 57 - { 58 - if(x mod 2 == 0) 59 - continue; 60 - if(x > 6) 61 - break; 62 - return x*3+1; 63 - } 64 - foreach(var x in xs) 65 - { 66 - zs[] = call\sub(f(?),[x]); 67 - } 68 - 69 - return zs.ToString(); 70 - } 71 - ", 72 - CallSub.Alias, "expression"); 73 - 74 - //var xs = new List<PValue> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; 75 - //Expect("[ 4, 10, 16 ]", (PValue)xs); 76 - } 77 - 78 - [Test] 79 - public void CallSubMacroCommandTopLevel() 80 - { 81 - Compile( 82 - @" 83 - var zs = []; 84 - function main(x1,x2,x3) 85 - { 86 - function f(x) 87 - { 88 - if(x mod 2 == 0) 89 - continue; 90 - if(x > 6) 91 - break; 92 - return x*3+1; 93 - } 94 - 95 - zs[] = call\sub(f(?),[x1]); 96 - zs[] = call\sub(f(?),[x2]); 97 - call\sub(f(?),[x3]); 98 - 99 - return zs.ToString(); 100 - } 101 - "); 102 - Func<List<PValue>> getZs = () => 103 - { 104 - var pv = target.Variables["zs"].Value.Value as List<PValue>; 105 - return pv ?? new List<PValue>(0); 106 - }; 107 - Action resetZs = () => getZs().Clear(); 108 - 109 - Expect("[ 4, 10 ]", 1, 3); 110 - resetZs(); 111 - 112 - ExpectNull(2, 4, 8); 113 - Assert.AreEqual(0, getZs().Count); 114 - resetZs(); 115 - 116 - ExpectNull(1, 8, 8); 117 - var zs = getZs(); 118 - Assert.AreEqual(1, zs.Count); 119 - AssertPValuesAreEqual(4, zs[0]); 120 - resetZs(); 121 - 122 - ExpectNull(1, 3, 8); 123 - zs = getZs(); 124 - Assert.AreEqual(2, zs.Count); 125 - AssertPValuesAreEqual(4, zs[0]); 126 - AssertPValuesAreEqual(10, zs[1]); 127 - resetZs(); 128 - } 129 - 130 - [Test] 131 - public void CallSubMinimal() 132 - { 133 - Compile( 134 - @" 135 - function f(x) 136 - { 137 - return x; 138 - } 139 - 140 - function main() 141 - { 142 - call\sub(f(?),[2]); 143 - return 2; 144 - } 145 - "); 146 - 147 - Expect(2); 148 - } 149 - 150 - [Test] 151 - public void CallSubMinimalReturn() 152 - { 153 - Compile( 154 - @" 155 - function f() 156 - { 157 - return 1; 158 - } 159 - 160 - function main() 161 - { 162 - var zs = []; 163 - asm{nop nop nop} 164 - zs[] = call\sub(f(?)); 165 - asm{nop nop nop} 166 - return zs[0]; 167 - } 168 - "); 169 - 170 - Expect(1); 171 - } 172 - 173 - [Test] 174 - public void CallSubOfPartial() 175 - { 176 - CompileInvalid( 177 - @" 178 - function main(xs,y) 179 - { 180 - var zs = []; 181 - function f(x,y) 182 - { 183 - if(x mod 2 == 0) 184 - continue; 185 - if(x > y) 186 - break; 187 - return x*3+1; 188 - } 189 - foreach(var x in xs) 190 - { 191 - zs[] = call\sub(f(?,y),[x]); 192 - } 193 - 194 - return zs.ToString(); 195 - } 196 - ", 197 - CallSub.Alias, "expression"); 198 - 199 - //var xs = new List<PValue> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; 200 - //Expect("[ 4, 10, 16 ]", (PValue)xs, 6); 201 - //Expect("[ 4, 10 ]", (PValue)xs, 4); 202 - } 203 - 204 - [Test] 205 - public void CaptureUnmentionedMacroVariable() 206 - { 207 - Compile( 208 - @" 209 - macro echo() 210 - { 211 - var f = (x) => 212 - if(context is null) 213 - ""context is null"" 214 - else if(context.LocalSymbols.TryGet(x, ref r)) 215 - var r 216 - else 217 - ""cannot resolve $x""; 218 - println(f.(""x"")); 219 - } 220 - 221 - function main() 222 - { 223 - var x = 15; 224 - echo; 225 - return x; 226 - } 227 - "); 228 - var clo = target.Functions["echo\\0"]; 229 - Assert.IsNotNull(clo, "Closure must exist."); 230 - Assert.IsTrue(clo.Meta.ContainsKey(PFunction.SharedNamesKey)); 231 - Assert.AreEqual(clo.Meta[PFunction.SharedNamesKey].List.Length, 1); 232 - Assert.AreEqual(clo.Meta[PFunction.SharedNamesKey].List[0].Text, 233 - MacroAliases.ContextAlias); 234 - 235 - Expect(15, new PValue[0]); 236 - } 237 - 238 - [Test] 239 - public void MacroTransport() 240 - { 241 - Compile( 242 - @" 243 - macro echo(lst) 244 - { 245 - lst = macro\unpack(lst); 246 - return new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 247 - context.Invocation.Line,context.Invocation.Column,sum(lst) + lst.Count); 248 - } 249 - 250 - macro gen(n) 251 - { 252 - n = n.Constant~Int; 253 - var id = macro\pack(1.to(n) >> all); 254 - var idConst = new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 255 - context.Invocation.Line,context.Invocation.Column, id); 256 - return call\macro([echo(idConst)]); 257 - } 258 - 259 - function main() 260 - { 261 - return gen(4); 262 - } 263 - 264 - function main2() 265 - { 266 - return gen(5); 267 - } 268 - "); 269 - 270 - Expect(1 + 2 + 3 + 4 + 4); 271 - ExpectNamed("main2", 1 + 2 + 3 + 4 + 5 + 5); 272 - } 273 - 274 - [Test] 275 - public void CallMacroOnFunction() 276 - { 277 - Compile( 278 - @" 279 - macro __append(con) 280 - { 281 - var c = con.Constant + ""__""; 282 - 283 - if(context.IsJustEffect) 284 - c += ""je""; 285 - 286 - if(context.Call~Int == Prexonite::Types::PCall.Set~Int) 287 - c += ""=""; 288 - 289 - var con = new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 290 - context.Invocation.Line,context.Invocation.Column,c); 291 - return con; 292 - } 293 - 294 - macro __surround(con, idx) 295 - { 296 - var idx = idx.Constant~Int; 297 - con.Constant = ""__"" + con.Constant; 298 - return [ call\macro([__append],[con]) 299 - , call\macro([__append(con)]) 300 - , call\macro([__append = con]) 301 - , call\macro([__append,true],[con]) 302 - , call\macro([__append,false],[con]) 303 - , call\macro([__append(con),true]) 304 - , call\macro([__append(con),false]) 305 - , call\macro([__append = con, true]) 306 - , call\macro([__append = con, false]) ][idx]; 307 - } 308 - 309 - function main(x,y) 310 - { 311 - return [ x + __surround(""xXx"", 0) + y 312 - , x + __surround(""xXx"", 1) + y 313 - , x + __surround(""xXx"", 2) + y 314 - , x + __surround(""xXx"", 3) + y 315 - , x + __surround(""xXx"", 4) + y 316 - , x + __surround(""xXx"", 5) + y 317 - , x + __surround(""xXx"", 6) + y 318 - , x + __surround(""xXx"", 7) + y 319 - , x + __surround(""xXx"", 8) + y]; 320 - } 321 - "); 322 - 323 - Expect(new List<PValue> 324 - { 325 - "a__xXx__b", 326 - "a__xXx__b", 327 - "a__xXx__=b", 328 - "a__xXx__jeb", 329 - "a__xXx__b", 330 - "a__xXx__jeb", 331 - "a__xXx__b", 332 - "a__xXx__je=b", 333 - "a__xXx__=b" 334 - }, "a", "b"); 335 - 336 - if (CompileToCil) 337 - { 338 - var surround = target.Functions["__surround"]; 339 - Assert.That(surround, Is.Not.Null, "Function __surround does not exist."); 340 - Assert.That(surround.Meta[PFunction.VolatileKey].Switch, 341 - Is.False, 342 - string.Format("Function {0} is volatile. Reason: {1}", surround.Id, 343 - surround.Meta[PFunction.DeficiencyKey].Text)); 344 - } 345 - } 346 - 347 - 348 - [Test,Ignore] 349 - public void PartialCallMacroOnFunction() 350 - { 351 - Compile( 352 - @" 353 - macro __append(con) 354 - { 355 - var c = con.Constant + ""__""; 356 - 357 - if(context.IsJustEffect) 358 - c += ""je""; 359 - 360 - if(context.Call~Int == Prexonite::Types::PCall.Set~Int) 361 - c += ""=""; 362 - 363 - var con = new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 364 - context.Invocation.Line,context.Invocation.Column,c); 365 - return con; 366 - } 367 - 368 - macro __surround\create_pa(con, idx) 369 - { 370 - var idx = idx.Constant~Int; 371 - con.Constant = ""__"" + con.Constant; 372 - var f = [ call\macro([?],[?]) // 20 373 - , call\macro([__append(?0)]) 374 - , call\macro([__append = ?0]) // 22 375 - , call\macro([__append,?],[con]) 376 - , call\macro([?,?],[?]) 377 - , call\macro([__append(con),?]) // 25 378 - , call\macro([__append(?0),?]) 379 - , call\macro([__append = ?0, ?]) // 27 380 - , call\macro([__append = con, ?]) ][idx]; 381 - 382 - var fc = macro\pack(f); 383 - return new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 384 - context.Invocation.Line,context.Invocation.Column,fc); 385 - } 386 - 387 - macro __surround(con, idx) 388 - { 389 - var i = idx.Constant~Int; //37 390 - var fc = call\macro([__surround\create_pa(con, idx)]).Expression; 391 - var f = macro\unpack(fc.Constant~Int); 392 - if(i == 0) 393 - return f.(macro\reference(__append),con); 394 - else if(i == 1) 395 - return f.(con); 396 - else if(i == 2) 397 - return f.(con); 398 - else if(i == 3) 399 - return f.(true); 400 - else if(i == 4) 401 - return f.(macro\reference(__append),false,con); 402 - else if(i == 5) // 50 403 - return f.(true); 404 - else if(i == 6) 405 - return f.(con, false); 406 - else if(i == 7) 407 - return f.(con,true); 408 - else if(i == 8) 409 - return f.(false); 410 - else 411 - throw ""ZOMG! (invalid index to macro __surround)""; 412 - } // 60 413 - 414 - function main(x,y) 415 - { 416 - return [ x + __surround(""xXx"", 0) + y 417 - , x + __surround(""xXx"", 1) + y 418 - , x + __surround(""xXx"", 2) + y 419 - , x + __surround(""xXx"", 3) + y 420 - , x + __surround(""xXx"", 4) + y 421 - , x + __surround(""xXx"", 5) + y 422 - , x + __surround(""xXx"", 6) + y // 70 423 - , x + __surround(""xXx"", 7) + y // 71 424 - , x + __surround(""xXx"", 8) + y]; // 72 425 - } 426 - "); 427 - 428 - Expect(new List<PValue> 429 - { 430 - "a__xXx__b", 431 - "a__xXx__b", 432 - "a__xXx__=b", 433 - "a__xXx__jeb", 434 - "a__xXx__b", 435 - "a__xXx__jeb", 436 - "a__xXx__b", 437 - "a__xXx__je=b", 438 - "a__xXx__=b" 439 - }, "a", "b"); 440 - } 441 - 442 - [Test] 443 - public void AstIsExpand() 444 - { 445 - Compile(@" 446 - var uniq\\node_t6; 447 - 448 - function ast_is_Expand(node_arg) 449 - {asm{ 450 - var tmpp0 451 - /* 00 */ ldloc node_arg 452 - /* 01 */ cmd.1 boxed 453 - /* 02 */ get.0 Type 454 - /* 03 */ dup 1 455 - /* 04 */ stloc tmpp0 456 - /* 05 */ check.const ""Object(\""Prexonite.Types.ObjectPType\"")"" 457 - /* 06 */ jump.t 9 458 - /* 07 */ ldc.bool false 459 - /* 08 */ ret.value 460 - /* 09 */ ldglob uniq\\node_t6 461 - /* 10 */ check.null 462 - /* 11 */ jump.f 15 463 - /* 12 */ ldc.string ""Prexonite.Compiler.Ast.AstExpand"" 464 - /* 13 */ sget.1 ""Object(\""System.Type\"")::GetType"" 465 - /* 14 */ stglob uniq\\node_t6 466 - /* 15 */ ldglob uniq\\node_t6 467 - /* 16 */ ldloc tmpp0 468 - /* 17 */ get.0 ClrType 469 - /* 18 */ get.1 IsAssignableFrom 470 - /* 19 */ jump.f 26 471 - /* 20 */ ldloc node_arg 472 - /* 21 */ get.0 CheckForPlaceholders 473 - /* 22 */ cmd.1 $not 474 - /* 23 */ jump.f 26 475 - /* 24 */ ldc.bool true 476 - /* 25 */ jump 27 477 - /* 26 */ ldc.bool false 478 - /* 27 */ ret.value 479 - /* 28 */ }} 480 - 481 - function main(n) = ast_is_Expand(n);"); 482 - 483 - Expect(true, 484 - sctx.CreateNativePValue(new AstExpand(NoSourcePosition.Instance, 485 - EntityRef.MacroCommand.Create("call\\macro"), PCall.Get))); 486 - 487 - } 488 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + #if ((!(DEBUG || Verbose)) || forceIndex) && allowIndex 27 + #define useIndex 28 + #endif 29 + 30 + #define UseCil 31 + //need to change this in VMTestsBase.cs too! 32 + 33 + using System; 34 + using System.Collections.Generic; 35 + using NUnit.Framework; 36 + using Prexonite; 37 + using Prexonite.Compiler; 38 + using Prexonite.Compiler.Ast; 39 + using Prexonite.Compiler.Macro.Commands; 40 + using Prexonite.Modular; 41 + using Prexonite.Types; 42 + using PrexoniteTests.Tests; 43 + 44 + namespace Prx.Tests 45 + { 46 + public abstract partial class VMTests : VMTestsBase 47 + { 48 + [Test] 49 + public void CallSubMacroCommandNested() 50 + { 51 + CompileInvalid( 52 + @" 53 + function main(xs) 54 + { 55 + var zs = []; 56 + function f(x) 57 + { 58 + if(x mod 2 == 0) 59 + continue; 60 + if(x > 6) 61 + break; 62 + return x*3+1; 63 + } 64 + foreach(var x in xs) 65 + { 66 + zs[] = call\sub(f(?),[x]); 67 + } 68 + 69 + return zs.ToString(); 70 + } 71 + ", 72 + CallSub.Alias, "expression"); 73 + 74 + //var xs = new List<PValue> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; 75 + //Expect("[ 4, 10, 16 ]", (PValue)xs); 76 + } 77 + 78 + [Test] 79 + public void CallSubMacroCommandTopLevel() 80 + { 81 + Compile( 82 + @" 83 + var zs = []; 84 + function main(x1,x2,x3) 85 + { 86 + function f(x) 87 + { 88 + if(x mod 2 == 0) 89 + continue; 90 + if(x > 6) 91 + break; 92 + return x*3+1; 93 + } 94 + 95 + zs[] = call\sub(f(?),[x1]); 96 + zs[] = call\sub(f(?),[x2]); 97 + call\sub(f(?),[x3]); 98 + 99 + return zs.ToString(); 100 + } 101 + "); 102 + Func<List<PValue>> getZs = () => 103 + { 104 + var pv = target.Variables["zs"].Value.Value as List<PValue>; 105 + return pv ?? new List<PValue>(0); 106 + }; 107 + Action resetZs = () => getZs().Clear(); 108 + 109 + Expect("[ 4, 10 ]", 1, 3); 110 + resetZs(); 111 + 112 + ExpectNull(2, 4, 8); 113 + Assert.AreEqual(0, getZs().Count); 114 + resetZs(); 115 + 116 + ExpectNull(1, 8, 8); 117 + var zs = getZs(); 118 + Assert.AreEqual(1, zs.Count); 119 + AssertPValuesAreEqual(4, zs[0]); 120 + resetZs(); 121 + 122 + ExpectNull(1, 3, 8); 123 + zs = getZs(); 124 + Assert.AreEqual(2, zs.Count); 125 + AssertPValuesAreEqual(4, zs[0]); 126 + AssertPValuesAreEqual(10, zs[1]); 127 + resetZs(); 128 + } 129 + 130 + [Test] 131 + public void CallSubMinimal() 132 + { 133 + Compile( 134 + @" 135 + function f(x) 136 + { 137 + return x; 138 + } 139 + 140 + function main() 141 + { 142 + call\sub(f(?),[2]); 143 + return 2; 144 + } 145 + "); 146 + 147 + Expect(2); 148 + } 149 + 150 + [Test] 151 + public void CallSubMinimalReturn() 152 + { 153 + Compile( 154 + @" 155 + function f() 156 + { 157 + return 1; 158 + } 159 + 160 + function main() 161 + { 162 + var zs = []; 163 + asm{nop nop nop} 164 + zs[] = call\sub(f(?)); 165 + asm{nop nop nop} 166 + return zs[0]; 167 + } 168 + "); 169 + 170 + Expect(1); 171 + } 172 + 173 + [Test] 174 + public void CallSubOfPartial() 175 + { 176 + CompileInvalid( 177 + @" 178 + function main(xs,y) 179 + { 180 + var zs = []; 181 + function f(x,y) 182 + { 183 + if(x mod 2 == 0) 184 + continue; 185 + if(x > y) 186 + break; 187 + return x*3+1; 188 + } 189 + foreach(var x in xs) 190 + { 191 + zs[] = call\sub(f(?,y),[x]); 192 + } 193 + 194 + return zs.ToString(); 195 + } 196 + ", 197 + CallSub.Alias, "expression"); 198 + 199 + //var xs = new List<PValue> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; 200 + //Expect("[ 4, 10, 16 ]", (PValue)xs, 6); 201 + //Expect("[ 4, 10 ]", (PValue)xs, 4); 202 + } 203 + 204 + [Test] 205 + public void CaptureUnmentionedMacroVariable() 206 + { 207 + Compile( 208 + @" 209 + macro echo() 210 + { 211 + var f = (x) => 212 + if(context is null) 213 + ""context is null"" 214 + else if(context.LocalSymbols.TryGet(x, ref r)) 215 + var r 216 + else 217 + ""cannot resolve $x""; 218 + println(f.(""x"")); 219 + } 220 + 221 + function main() 222 + { 223 + var x = 15; 224 + echo; 225 + return x; 226 + } 227 + "); 228 + var clo = target.Functions["echo\\0"]; 229 + Assert.IsNotNull(clo, "Closure must exist."); 230 + Assert.IsTrue(clo.Meta.ContainsKey(PFunction.SharedNamesKey)); 231 + Assert.AreEqual(clo.Meta[PFunction.SharedNamesKey].List.Length, 1); 232 + Assert.AreEqual(clo.Meta[PFunction.SharedNamesKey].List[0].Text, 233 + MacroAliases.ContextAlias); 234 + 235 + Expect(15, new PValue[0]); 236 + } 237 + 238 + [Test] 239 + public void MacroTransport() 240 + { 241 + Compile( 242 + @" 243 + macro echo(lst) 244 + { 245 + lst = macro\unpack(lst); 246 + return new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 247 + context.Invocation.Line,context.Invocation.Column,sum(lst) + lst.Count); 248 + } 249 + 250 + macro gen(n) 251 + { 252 + n = n.Constant~Int; 253 + var id = macro\pack(1.to(n) >> all); 254 + var idConst = new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 255 + context.Invocation.Line,context.Invocation.Column, id); 256 + return call\macro([echo(idConst)]); 257 + } 258 + 259 + function main() 260 + { 261 + return gen(4); 262 + } 263 + 264 + function main2() 265 + { 266 + return gen(5); 267 + } 268 + "); 269 + 270 + Expect(1 + 2 + 3 + 4 + 4); 271 + ExpectNamed("main2", 1 + 2 + 3 + 4 + 5 + 5); 272 + } 273 + 274 + [Test] 275 + public void CallMacroOnFunction() 276 + { 277 + Compile( 278 + @" 279 + macro __append(con) 280 + { 281 + var c = con.Constant + ""__""; 282 + 283 + if(context.IsJustEffect) 284 + c += ""je""; 285 + 286 + if(context.Call~Int == Prexonite::Types::PCall.Set~Int) 287 + c += ""=""; 288 + 289 + var con = new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 290 + context.Invocation.Line,context.Invocation.Column,c); 291 + return con; 292 + } 293 + 294 + macro __surround(con, idx) 295 + { 296 + var idx = idx.Constant~Int; 297 + con.Constant = ""__"" + con.Constant; 298 + return [ call\macro([__append],[con]) 299 + , call\macro([__append(con)]) 300 + , call\macro([__append = con]) 301 + , call\macro([__append,true],[con]) 302 + , call\macro([__append,false],[con]) 303 + , call\macro([__append(con),true]) 304 + , call\macro([__append(con),false]) 305 + , call\macro([__append = con, true]) 306 + , call\macro([__append = con, false]) ][idx]; 307 + } 308 + 309 + function main(x,y) 310 + { 311 + return [ x + __surround(""xXx"", 0) + y 312 + , x + __surround(""xXx"", 1) + y 313 + , x + __surround(""xXx"", 2) + y 314 + , x + __surround(""xXx"", 3) + y 315 + , x + __surround(""xXx"", 4) + y 316 + , x + __surround(""xXx"", 5) + y 317 + , x + __surround(""xXx"", 6) + y 318 + , x + __surround(""xXx"", 7) + y 319 + , x + __surround(""xXx"", 8) + y]; 320 + } 321 + "); 322 + 323 + Expect(new List<PValue> 324 + { 325 + "a__xXx__b", 326 + "a__xXx__b", 327 + "a__xXx__=b", 328 + "a__xXx__jeb", 329 + "a__xXx__b", 330 + "a__xXx__jeb", 331 + "a__xXx__b", 332 + "a__xXx__je=b", 333 + "a__xXx__=b" 334 + }, "a", "b"); 335 + 336 + if (CompileToCil) 337 + { 338 + var surround = target.Functions["__surround"]; 339 + Assert.That(surround, Is.Not.Null, "Function __surround does not exist."); 340 + Assert.That(surround.Meta[PFunction.VolatileKey].Switch, 341 + Is.False, 342 + string.Format("Function {0} is volatile. Reason: {1}", surround.Id, 343 + surround.Meta[PFunction.DeficiencyKey].Text)); 344 + } 345 + } 346 + 347 + 348 + [Test,Ignore("TODO: figure out why this is ignored")] 349 + public void PartialCallMacroOnFunction() 350 + { 351 + Compile( 352 + @" 353 + macro __append(con) 354 + { 355 + var c = con.Constant + ""__""; 356 + 357 + if(context.IsJustEffect) 358 + c += ""je""; 359 + 360 + if(context.Call~Int == Prexonite::Types::PCall.Set~Int) 361 + c += ""=""; 362 + 363 + var con = new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 364 + context.Invocation.Line,context.Invocation.Column,c); 365 + return con; 366 + } 367 + 368 + macro __surround\create_pa(con, idx) 369 + { 370 + var idx = idx.Constant~Int; 371 + con.Constant = ""__"" + con.Constant; 372 + var f = [ call\macro([?],[?]) // 20 373 + , call\macro([__append(?0)]) 374 + , call\macro([__append = ?0]) // 22 375 + , call\macro([__append,?],[con]) 376 + , call\macro([?,?],[?]) 377 + , call\macro([__append(con),?]) // 25 378 + , call\macro([__append(?0),?]) 379 + , call\macro([__append = ?0, ?]) // 27 380 + , call\macro([__append = con, ?]) ][idx]; 381 + 382 + var fc = macro\pack(f); 383 + return new Prexonite::Compiler::Ast::AstConstant(context.Invocation.File, 384 + context.Invocation.Line,context.Invocation.Column,fc); 385 + } 386 + 387 + macro __surround(con, idx) 388 + { 389 + var i = idx.Constant~Int; //37 390 + var fc = call\macro([__surround\create_pa(con, idx)]).Expression; 391 + var f = macro\unpack(fc.Constant~Int); 392 + if(i == 0) 393 + return f.(macro\reference(__append),con); 394 + else if(i == 1) 395 + return f.(con); 396 + else if(i == 2) 397 + return f.(con); 398 + else if(i == 3) 399 + return f.(true); 400 + else if(i == 4) 401 + return f.(macro\reference(__append),false,con); 402 + else if(i == 5) // 50 403 + return f.(true); 404 + else if(i == 6) 405 + return f.(con, false); 406 + else if(i == 7) 407 + return f.(con,true); 408 + else if(i == 8) 409 + return f.(false); 410 + else 411 + throw ""ZOMG! (invalid index to macro __surround)""; 412 + } // 60 413 + 414 + function main(x,y) 415 + { 416 + return [ x + __surround(""xXx"", 0) + y 417 + , x + __surround(""xXx"", 1) + y 418 + , x + __surround(""xXx"", 2) + y 419 + , x + __surround(""xXx"", 3) + y 420 + , x + __surround(""xXx"", 4) + y 421 + , x + __surround(""xXx"", 5) + y 422 + , x + __surround(""xXx"", 6) + y // 70 423 + , x + __surround(""xXx"", 7) + y // 71 424 + , x + __surround(""xXx"", 8) + y]; // 72 425 + } 426 + "); 427 + 428 + Expect(new List<PValue> 429 + { 430 + "a__xXx__b", 431 + "a__xXx__b", 432 + "a__xXx__=b", 433 + "a__xXx__jeb", 434 + "a__xXx__b", 435 + "a__xXx__jeb", 436 + "a__xXx__b", 437 + "a__xXx__je=b", 438 + "a__xXx__=b" 439 + }, "a", "b"); 440 + } 441 + 442 + [Test] 443 + public void AstIsExpand() 444 + { 445 + Compile(@" 446 + var uniq\\node_t6; 447 + 448 + function ast_is_Expand(node_arg) 449 + {asm{ 450 + var tmpp0 451 + /* 00 */ ldloc node_arg 452 + /* 01 */ cmd.1 boxed 453 + /* 02 */ get.0 Type 454 + /* 03 */ dup 1 455 + /* 04 */ stloc tmpp0 456 + /* 05 */ check.const ""Object(\""Prexonite.Types.ObjectPType\"")"" 457 + /* 06 */ jump.t 9 458 + /* 07 */ ldc.bool false 459 + /* 08 */ ret.value 460 + /* 09 */ ldglob uniq\\node_t6 461 + /* 10 */ check.null 462 + /* 11 */ jump.f 15 463 + /* 12 */ ldc.string ""Prexonite.Compiler.Ast.AstExpand"" 464 + /* 13 */ sget.1 ""Object(\""System.Type\"")::GetType"" 465 + /* 14 */ stglob uniq\\node_t6 466 + /* 15 */ ldglob uniq\\node_t6 467 + /* 16 */ ldloc tmpp0 468 + /* 17 */ get.0 ClrType 469 + /* 18 */ get.1 IsAssignableFrom 470 + /* 19 */ jump.f 26 471 + /* 20 */ ldloc node_arg 472 + /* 21 */ get.0 CheckForPlaceholders 473 + /* 22 */ cmd.1 $not 474 + /* 23 */ jump.f 26 475 + /* 24 */ ldc.bool true 476 + /* 25 */ jump 27 477 + /* 26 */ ldc.bool false 478 + /* 27 */ ret.value 479 + /* 28 */ }} 480 + 481 + function main(n) = ast_is_Expand(n);"); 482 + 483 + Expect(true, 484 + sctx.CreateNativePValue(new AstExpand(NoSourcePosition.Instance, 485 + EntityRef.MacroCommand.Create("call\\macro"), PCall.Get))); 486 + 487 + } 488 + } 489 489 }
+6 -2
PrexoniteTests/packages.config
··· 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <packages> 3 - <package id="Moq" version="4.0.10827" targetFramework="net45" /> 4 - <package id="NUnit" version="2.6.2" targetFramework="net45" /> 3 + <package id="Castle.Core" version="4.2.1" targetFramework="net461" /> 4 + <package id="Microsoft.Net.Compilers" version="2.7.0" targetFramework="net462" developmentDependency="true" /> 5 + <package id="Moq" version="4.8.2" targetFramework="net461" /> 6 + <package id="NUnit" version="3.10.1" targetFramework="net461" /> 7 + <package id="System.Threading.Tasks.Extensions" version="4.4.0" targetFramework="net461" /> 8 + <package id="System.ValueTuple" version="4.4.0" targetFramework="net461" /> 5 9 </packages>
+347 -335
Prx/Prx.csproj
··· 1 - <?xml version="1.0" encoding="utf-8"?> 2 - <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0"> 3 - <PropertyGroup> 4 - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 5 - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 6 - <ProductVersion>9.0.30729</ProductVersion> 7 - <SchemaVersion>2.0</SchemaVersion> 8 - <ProjectGuid>{8C90E0C5-8FD3-407C-ABE8-9EE856F87269}</ProjectGuid> 9 - <OutputType>Exe</OutputType> 10 - <AppDesignerFolder>Properties</AppDesignerFolder> 11 - <RootNamespace>Prx</RootNamespace> 12 - <AssemblyName>Prx</AssemblyName> 13 - <SccProjectName> 14 - </SccProjectName> 15 - <SccLocalPath> 16 - </SccLocalPath> 17 - <SccProvider> 18 - </SccProvider> 19 - <ApplicationIcon>Prx.ico</ApplicationIcon> 20 - <FileUpgradeFlags> 21 - </FileUpgradeFlags> 22 - <OldToolsVersion>3.5</OldToolsVersion> 23 - <UpgradeBackupLocation> 24 - </UpgradeBackupLocation> 25 - <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> 26 - <IsWebBootstrapper>false</IsWebBootstrapper> 27 - <ApplicationManifest>app.manifest</ApplicationManifest> 28 - <TargetFrameworkProfile> 29 - </TargetFrameworkProfile> 30 - <PublishUrl>publish\</PublishUrl> 31 - <Install>true</Install> 32 - <InstallFrom>Disk</InstallFrom> 33 - <UpdateEnabled>false</UpdateEnabled> 34 - <UpdateMode>Foreground</UpdateMode> 35 - <UpdateInterval>7</UpdateInterval> 36 - <UpdateIntervalUnits>Days</UpdateIntervalUnits> 37 - <UpdatePeriodically>false</UpdatePeriodically> 38 - <UpdateRequired>false</UpdateRequired> 39 - <MapFileExtensions>true</MapFileExtensions> 40 - <ApplicationRevision>0</ApplicationRevision> 41 - <ApplicationVersion>1.0.0.%2a</ApplicationVersion> 42 - <UseApplicationTrust>false</UseApplicationTrust> 43 - <BootstrapperEnabled>true</BootstrapperEnabled> 44 - </PropertyGroup> 45 - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 46 - <DebugSymbols>true</DebugSymbols> 47 - <DebugType>full</DebugType> 48 - <Optimize>false</Optimize> 49 - <OutputPath>bin\Debug\</OutputPath> 50 - <DefineConstants>DEBUG;TRACE</DefineConstants> 51 - <ErrorReport>prompt</ErrorReport> 52 - <WarningLevel>4</WarningLevel> 53 - <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 54 - <Prefer32Bit>false</Prefer32Bit> 55 - <LangVersion>6</LangVersion> 56 - </PropertyGroup> 57 - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 58 - <DebugType>none</DebugType> 59 - <Optimize>true</Optimize> 60 - <OutputPath>bin\Release\</OutputPath> 61 - <DefineConstants>TRACE</DefineConstants> 62 - <ErrorReport>prompt</ErrorReport> 63 - <WarningLevel>4</WarningLevel> 64 - <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 65 - <Prefer32Bit>false</Prefer32Bit> 66 - </PropertyGroup> 67 - <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 68 - <DebugSymbols>true</DebugSymbols> 69 - <OutputPath>bin\x86\Debug\</OutputPath> 70 - <DefineConstants>DEBUG;TRACE</DefineConstants> 71 - <DebugType>full</DebugType> 72 - <PlatformTarget>x86</PlatformTarget> 73 - <CodeAnalysisLogFile>bin\Debug\Prx.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> 74 - <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> 75 - <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> 76 - <ErrorReport>prompt</ErrorReport> 77 - <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 78 - <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> 79 - <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> 80 - <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> 81 - <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> 82 - <Prefer32Bit>false</Prefer32Bit> 83 - </PropertyGroup> 84 - <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 85 - <OutputPath>bin\x86\Release\</OutputPath> 86 - <DefineConstants>TRACE</DefineConstants> 87 - <Optimize>true</Optimize> 88 - <PlatformTarget>x86</PlatformTarget> 89 - <CodeAnalysisLogFile>bin\Release\Prx.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> 90 - <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> 91 - <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> 92 - <ErrorReport>prompt</ErrorReport> 93 - <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 94 - <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> 95 - <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> 96 - <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> 97 - <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> 98 - <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules> 99 - <Prefer32Bit>false</Prefer32Bit> 100 - </PropertyGroup> 101 - <PropertyGroup> 102 - <StartupObject>Prx.Program</StartupObject> 103 - </PropertyGroup> 104 - <ItemGroup> 105 - <Reference Include="System" /> 106 - </ItemGroup> 107 - <ItemGroup> 108 - <Compile Include="Benchmarking\Benchmark.cs" /> 109 - <Compile Include="Benchmarking\BenchmarkEntry.cs" /> 110 - <Compile Include="Benchmarking\BenchmarkEntryCollection.cs" /> 111 - <Compile Include="Benchmarking\Measurement.cs" /> 112 - <Compile Include="PrexoniteConsole.cs" /> 113 - <Compile Include="Program.cs" /> 114 - <Compile Include="Properties\AssemblyInfo.cs" /> 115 - <Compile Include="Properties\Resources.Designer.cs"> 116 - <AutoGen>True</AutoGen> 117 - <DesignTime>True</DesignTime> 118 - <DependentUpon>Resources.resx</DependentUpon> 119 - </Compile> 120 - <Compile Include="SuperConsole.cs" /> 121 - <Compile Include="Win32\User32.cs" /> 122 - </ItemGroup> 123 - <ItemGroup> 124 - <None Include="app.config" /> 125 - <None Include="app.manifest" /> 126 - <Content Include="psr\ast.pxs"> 127 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 128 - </Content> 129 - <Content Include="psr\console.pxs"> 130 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 131 - </Content> 132 - <Content Include="psr\csp.pxs"> 133 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 134 - </Content> 135 - <Content Include="psr\debug.pxs"> 136 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 137 - </Content> 138 - <Content Include="psr\call_sub.pxs"> 139 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 140 - </Content> 141 - <None Include="config\app.Release.config" /> 142 - <None Include="config\app.Debug.config" /> 143 - <None Include="psr\debug\debug.pxs"> 144 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 145 - </None> 146 - <None Include="psr\debug\disassembler.pxs"> 147 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 148 - </None> 149 - <Content Include="psr\file.pxs"> 150 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 151 - </Content> 152 - <Content Include="psr\hook.pxs"> 153 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 154 - </Content> 155 - <Content Include="psr\json.pxs"> 156 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 157 - </Content> 158 - <Content Include="psr\loop.pxs"> 159 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 160 - </Content> 161 - <Content Include="psr\macro.pxs"> 162 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 163 - </Content> 164 - <Content Include="psr\experimental\args.pxs"> 165 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 166 - </Content> 167 - <Content Include="psr\misc.pxs"> 168 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 169 - </Content> 170 - <Content Include="psr\pattern.pxs"> 171 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 172 - </Content> 173 - <Content Include="psr\prop.pxs"> 174 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 175 - </Content> 176 - <Content Include="psr\queue.pxs"> 177 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 178 - </Content> 179 - <Content Include="psr\set.pxs"> 180 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 181 - </Content> 182 - <Content Include="psr\stack.pxs"> 183 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 184 - </Content> 185 - <Content Include="psr\struct.pxs"> 186 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 187 - </Content> 188 - <Content Include="psr\dependency_analysis.pxs"> 189 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 190 - </Content> 191 - <None Include="psr\experimental\indentation.pxs"> 192 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 193 - </None> 194 - <None Include="psr\impl\ast.pxs"> 195 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 196 - </None> 197 - <None Include="psr\impl\call_sub.pxs"> 198 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 199 - </None> 200 - <None Include="psr\impl\console.pxs"> 201 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 202 - </None> 203 - <None Include="psr\impl\csp.pxs"> 204 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 205 - </None> 206 - <None Include="psr\impl\debug.pxs"> 207 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 208 - </None> 209 - <None Include="psr\impl\dependency_analysis.pxs"> 210 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 211 - </None> 212 - <None Include="psr\impl\file.pxs"> 213 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 214 - </None> 215 - <None Include="psr\impl\hook.pxs"> 216 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 217 - </None> 218 - <None Include="psr\impl\json.pxs"> 219 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 220 - </None> 221 - <None Include="psr\impl\loop.pxs"> 222 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 223 - </None> 224 - <None Include="psr\impl\macro.pxs"> 225 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 226 - </None> 227 - <None Include="psr\impl\misc.pxs"> 228 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 229 - </None> 230 - <None Include="psr\impl\pattern.pxs"> 231 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 232 - </None> 233 - <None Include="psr\impl\prop.pxs"> 234 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 235 - </None> 236 - <None Include="psr\impl\queue.pxs"> 237 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 238 - </None> 239 - <None Include="psr\impl\set.pxs"> 240 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 241 - </None> 242 - <None Include="psr\impl\stack.pxs"> 243 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 244 - </None> 245 - <None Include="psr\impl\struct.pxs"> 246 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 247 - </None> 248 - <None Include="psr\test.pxs"> 249 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 250 - </None> 251 - <None Include="psr\test\meta_macro.pxs"> 252 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 253 - </None> 254 - <None Include="samples\beer.pxs"> 255 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 256 - </None> 257 - <None Include="samples\beer_fancy.pxs"> 258 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 259 - </None> 260 - <None Include="samples\tictactoe.pxs"> 261 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 262 - </None> 263 - <None Include="src\prx_interactive.pxs"> 264 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 265 - </None> 266 - <None Include="src\prx_lib.pxs"> 267 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 268 - </None> 269 - <None Include="src\prx_main.pxs"> 270 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 271 - </None> 272 - </ItemGroup> 273 - <ItemGroup> 274 - <EmbeddedResource Include="Properties\Resources.resx"> 275 - <SubType>Designer</SubType> 276 - <Generator>ResXFileCodeGenerator</Generator> 277 - <LastGenOutput>Resources.Designer.cs</LastGenOutput> 278 - </EmbeddedResource> 279 - </ItemGroup> 280 - <ItemGroup> 281 - <Content Include="..\LICENSE.txt"> 282 - <Link>LICENSE.txt</Link> 283 - <CopyToOutputDirectory>Always</CopyToOutputDirectory> 284 - </Content> 285 - <Content Include="Prx.ico" /> 286 - </ItemGroup> 287 - <ItemGroup> 288 - <Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" /> 289 - </ItemGroup> 290 - <ItemGroup> 291 - <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> 292 - <Visible>False</Visible> 293 - <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> 294 - <Install>false</Install> 295 - </BootstrapperPackage> 296 - <BootstrapperPackage Include="Microsoft.Net.Framework.2.0"> 297 - <Visible>False</Visible> 298 - <ProductName>.NET Framework 2.0 %28x86%29</ProductName> 299 - <Install>true</Install> 300 - </BootstrapperPackage> 301 - <BootstrapperPackage Include="Microsoft.Net.Framework.3.0"> 302 - <Visible>False</Visible> 303 - <ProductName>.NET Framework 3.0 %28x86%29</ProductName> 304 - <Install>false</Install> 305 - </BootstrapperPackage> 306 - <BootstrapperPackage Include="Microsoft.Net.Framework.3.5"> 307 - <Visible>False</Visible> 308 - <ProductName>.NET Framework 3.5</ProductName> 309 - <Install>false</Install> 310 - </BootstrapperPackage> 311 - <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> 312 - <Visible>False</Visible> 313 - <ProductName>.NET Framework 3.5 SP1</ProductName> 314 - <Install>false</Install> 315 - </BootstrapperPackage> 316 - </ItemGroup> 317 - <ItemGroup> 318 - <ProjectReference Include="..\Prexonite\Prexonite.csproj"> 319 - <Project>{2FE722CA-B671-4EE8-9BF1-9F3ACFACD24D}</Project> 320 - <Name>Prexonite</Name> 321 - </ProjectReference> 322 - </ItemGroup> 323 - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 324 - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 325 - Other similar extension points exist, see Microsoft.Common.targets. 326 - <Target Name="BeforeBuild"> 327 - </Target> 328 - <Target Name="AfterBuild"> 329 - </Target> 330 - --> 331 - <Target Name="AfterBuild"> 332 - <!-- Choose configuration file depending on MSBuild configuration --> 333 - <Delete Files="$(TargetDir)$(TargetFileName).config" /> 334 - <Copy SourceFiles="$(ProjectDir)\config\app.$(Configuration).config" DestinationFiles="$(TargetDir)$(TargetFileName).config" /> 335 - </Target> 1 + <?xml version="1.0" encoding="utf-8"?> 2 + <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0"> 3 + <Import Project="..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props')" /> 4 + <PropertyGroup> 5 + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 6 + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 7 + <ProductVersion>9.0.30729</ProductVersion> 8 + <SchemaVersion>2.0</SchemaVersion> 9 + <ProjectGuid>{8C90E0C5-8FD3-407C-ABE8-9EE856F87269}</ProjectGuid> 10 + <OutputType>Exe</OutputType> 11 + <AppDesignerFolder>Properties</AppDesignerFolder> 12 + <RootNamespace>Prx</RootNamespace> 13 + <AssemblyName>Prx</AssemblyName> 14 + <SccProjectName> 15 + </SccProjectName> 16 + <SccLocalPath> 17 + </SccLocalPath> 18 + <SccProvider> 19 + </SccProvider> 20 + <ApplicationIcon>Prx.ico</ApplicationIcon> 21 + <FileUpgradeFlags> 22 + </FileUpgradeFlags> 23 + <OldToolsVersion>3.5</OldToolsVersion> 24 + <UpgradeBackupLocation> 25 + </UpgradeBackupLocation> 26 + <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> 27 + <IsWebBootstrapper>false</IsWebBootstrapper> 28 + <ApplicationManifest>app.manifest</ApplicationManifest> 29 + <TargetFrameworkProfile> 30 + </TargetFrameworkProfile> 31 + <PublishUrl>publish\</PublishUrl> 32 + <Install>true</Install> 33 + <InstallFrom>Disk</InstallFrom> 34 + <UpdateEnabled>false</UpdateEnabled> 35 + <UpdateMode>Foreground</UpdateMode> 36 + <UpdateInterval>7</UpdateInterval> 37 + <UpdateIntervalUnits>Days</UpdateIntervalUnits> 38 + <UpdatePeriodically>false</UpdatePeriodically> 39 + <UpdateRequired>false</UpdateRequired> 40 + <MapFileExtensions>true</MapFileExtensions> 41 + <ApplicationRevision>0</ApplicationRevision> 42 + <ApplicationVersion>1.0.0.%2a</ApplicationVersion> 43 + <UseApplicationTrust>false</UseApplicationTrust> 44 + <BootstrapperEnabled>true</BootstrapperEnabled> 45 + </PropertyGroup> 46 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 47 + <DebugSymbols>true</DebugSymbols> 48 + <DebugType>full</DebugType> 49 + <Optimize>false</Optimize> 50 + <OutputPath>bin\Debug\</OutputPath> 51 + <DefineConstants>DEBUG;TRACE</DefineConstants> 52 + <ErrorReport>prompt</ErrorReport> 53 + <WarningLevel>4</WarningLevel> 54 + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 55 + <Prefer32Bit>false</Prefer32Bit> 56 + <LangVersion>7.2</LangVersion> 57 + </PropertyGroup> 58 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 59 + <DebugType>none</DebugType> 60 + <Optimize>true</Optimize> 61 + <OutputPath>bin\Release\</OutputPath> 62 + <DefineConstants>TRACE</DefineConstants> 63 + <ErrorReport>prompt</ErrorReport> 64 + <WarningLevel>4</WarningLevel> 65 + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 66 + <Prefer32Bit>false</Prefer32Bit> 67 + </PropertyGroup> 68 + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 69 + <DebugSymbols>true</DebugSymbols> 70 + <OutputPath>bin\x86\Debug\</OutputPath> 71 + <DefineConstants>DEBUG;TRACE</DefineConstants> 72 + <DebugType>full</DebugType> 73 + <PlatformTarget>x86</PlatformTarget> 74 + <CodeAnalysisLogFile>bin\Debug\Prx.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> 75 + <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> 76 + <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> 77 + <ErrorReport>prompt</ErrorReport> 78 + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 79 + <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> 80 + <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> 81 + <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> 82 + <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> 83 + <Prefer32Bit>false</Prefer32Bit> 84 + </PropertyGroup> 85 + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 86 + <OutputPath>bin\x86\Release\</OutputPath> 87 + <DefineConstants>TRACE</DefineConstants> 88 + <Optimize>true</Optimize> 89 + <PlatformTarget>x86</PlatformTarget> 90 + <CodeAnalysisLogFile>bin\Release\Prx.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> 91 + <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> 92 + <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> 93 + <ErrorReport>prompt</ErrorReport> 94 + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 95 + <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories> 96 + <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets> 97 + <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories> 98 + <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules> 99 + <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules> 100 + <Prefer32Bit>false</Prefer32Bit> 101 + </PropertyGroup> 102 + <PropertyGroup> 103 + <StartupObject>Prx.Program</StartupObject> 104 + </PropertyGroup> 105 + <ItemGroup> 106 + <Reference Include="System" /> 107 + <Reference Include="System.Threading.Tasks.Extensions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"> 108 + <HintPath>..\packages\System.Threading.Tasks.Extensions.4.4.0\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath> 109 + <Private>True</Private> 110 + </Reference> 111 + </ItemGroup> 112 + <ItemGroup> 113 + <Compile Include="Benchmarking\Benchmark.cs" /> 114 + <Compile Include="Benchmarking\BenchmarkEntry.cs" /> 115 + <Compile Include="Benchmarking\BenchmarkEntryCollection.cs" /> 116 + <Compile Include="Benchmarking\Measurement.cs" /> 117 + <Compile Include="PrexoniteConsole.cs" /> 118 + <Compile Include="Program.cs" /> 119 + <Compile Include="Properties\AssemblyInfo.cs" /> 120 + <Compile Include="Properties\Resources.Designer.cs"> 121 + <AutoGen>True</AutoGen> 122 + <DesignTime>True</DesignTime> 123 + <DependentUpon>Resources.resx</DependentUpon> 124 + </Compile> 125 + <Compile Include="SuperConsole.cs" /> 126 + <Compile Include="Win32\User32.cs" /> 127 + </ItemGroup> 128 + <ItemGroup> 129 + <None Include="app.config" /> 130 + <None Include="app.manifest" /> 131 + <Content Include="psr\ast.pxs"> 132 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 133 + </Content> 134 + <Content Include="psr\console.pxs"> 135 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 136 + </Content> 137 + <Content Include="psr\csp.pxs"> 138 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 139 + </Content> 140 + <Content Include="psr\debug.pxs"> 141 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 142 + </Content> 143 + <Content Include="psr\call_sub.pxs"> 144 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 145 + </Content> 146 + <None Include="config\app.Release.config" /> 147 + <None Include="config\app.Debug.config" /> 148 + <None Include="packages.config" /> 149 + <None Include="psr\debug\debug.pxs"> 150 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 151 + </None> 152 + <None Include="psr\debug\disassembler.pxs"> 153 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 154 + </None> 155 + <Content Include="psr\file.pxs"> 156 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 157 + </Content> 158 + <Content Include="psr\hook.pxs"> 159 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 160 + </Content> 161 + <Content Include="psr\json.pxs"> 162 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 163 + </Content> 164 + <Content Include="psr\loop.pxs"> 165 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 166 + </Content> 167 + <Content Include="psr\macro.pxs"> 168 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 169 + </Content> 170 + <Content Include="psr\experimental\args.pxs"> 171 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 172 + </Content> 173 + <Content Include="psr\misc.pxs"> 174 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 175 + </Content> 176 + <Content Include="psr\pattern.pxs"> 177 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 178 + </Content> 179 + <Content Include="psr\prop.pxs"> 180 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 181 + </Content> 182 + <Content Include="psr\queue.pxs"> 183 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 184 + </Content> 185 + <Content Include="psr\set.pxs"> 186 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 187 + </Content> 188 + <Content Include="psr\stack.pxs"> 189 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 190 + </Content> 191 + <Content Include="psr\struct.pxs"> 192 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 193 + </Content> 194 + <Content Include="psr\dependency_analysis.pxs"> 195 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 196 + </Content> 197 + <None Include="psr\experimental\indentation.pxs"> 198 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 199 + </None> 200 + <None Include="psr\impl\ast.pxs"> 201 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 202 + </None> 203 + <None Include="psr\impl\call_sub.pxs"> 204 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 205 + </None> 206 + <None Include="psr\impl\console.pxs"> 207 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 208 + </None> 209 + <None Include="psr\impl\csp.pxs"> 210 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 211 + </None> 212 + <None Include="psr\impl\debug.pxs"> 213 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 214 + </None> 215 + <None Include="psr\impl\dependency_analysis.pxs"> 216 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 217 + </None> 218 + <None Include="psr\impl\file.pxs"> 219 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 220 + </None> 221 + <None Include="psr\impl\hook.pxs"> 222 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 223 + </None> 224 + <None Include="psr\impl\json.pxs"> 225 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 226 + </None> 227 + <None Include="psr\impl\loop.pxs"> 228 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 229 + </None> 230 + <None Include="psr\impl\macro.pxs"> 231 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 232 + </None> 233 + <None Include="psr\impl\misc.pxs"> 234 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 235 + </None> 236 + <None Include="psr\impl\pattern.pxs"> 237 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 238 + </None> 239 + <None Include="psr\impl\prop.pxs"> 240 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 241 + </None> 242 + <None Include="psr\impl\queue.pxs"> 243 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 244 + </None> 245 + <None Include="psr\impl\set.pxs"> 246 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 247 + </None> 248 + <None Include="psr\impl\stack.pxs"> 249 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 250 + </None> 251 + <None Include="psr\impl\struct.pxs"> 252 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 253 + </None> 254 + <None Include="psr\test.pxs"> 255 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 256 + </None> 257 + <None Include="psr\test\meta_macro.pxs"> 258 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 259 + </None> 260 + <None Include="samples\beer.pxs"> 261 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 262 + </None> 263 + <None Include="samples\beer_fancy.pxs"> 264 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 265 + </None> 266 + <None Include="samples\tictactoe.pxs"> 267 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 268 + </None> 269 + <None Include="src\prx_interactive.pxs"> 270 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 271 + </None> 272 + <None Include="src\prx_lib.pxs"> 273 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 274 + </None> 275 + <None Include="src\prx_main.pxs"> 276 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 277 + </None> 278 + </ItemGroup> 279 + <ItemGroup> 280 + <EmbeddedResource Include="Properties\Resources.resx"> 281 + <SubType>Designer</SubType> 282 + <Generator>ResXFileCodeGenerator</Generator> 283 + <LastGenOutput>Resources.Designer.cs</LastGenOutput> 284 + </EmbeddedResource> 285 + </ItemGroup> 286 + <ItemGroup> 287 + <Content Include="..\LICENSE.txt"> 288 + <Link>LICENSE.txt</Link> 289 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 290 + </Content> 291 + <Content Include="Prx.ico" /> 292 + </ItemGroup> 293 + <ItemGroup> 294 + <Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" /> 295 + </ItemGroup> 296 + <ItemGroup> 297 + <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> 298 + <Visible>False</Visible> 299 + <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> 300 + <Install>false</Install> 301 + </BootstrapperPackage> 302 + <BootstrapperPackage Include="Microsoft.Net.Framework.2.0"> 303 + <Visible>False</Visible> 304 + <ProductName>.NET Framework 2.0 %28x86%29</ProductName> 305 + <Install>true</Install> 306 + </BootstrapperPackage> 307 + <BootstrapperPackage Include="Microsoft.Net.Framework.3.0"> 308 + <Visible>False</Visible> 309 + <ProductName>.NET Framework 3.0 %28x86%29</ProductName> 310 + <Install>false</Install> 311 + </BootstrapperPackage> 312 + <BootstrapperPackage Include="Microsoft.Net.Framework.3.5"> 313 + <Visible>False</Visible> 314 + <ProductName>.NET Framework 3.5</ProductName> 315 + <Install>false</Install> 316 + </BootstrapperPackage> 317 + <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> 318 + <Visible>False</Visible> 319 + <ProductName>.NET Framework 3.5 SP1</ProductName> 320 + <Install>false</Install> 321 + </BootstrapperPackage> 322 + </ItemGroup> 323 + <ItemGroup> 324 + <ProjectReference Include="..\Prexonite\Prexonite.csproj"> 325 + <Project>{2FE722CA-B671-4EE8-9BF1-9F3ACFACD24D}</Project> 326 + <Name>Prexonite</Name> 327 + </ProjectReference> 328 + </ItemGroup> 329 + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 330 + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 331 + Other similar extension points exist, see Microsoft.Common.targets. 332 + <Target Name="BeforeBuild"> 333 + </Target> 334 + <Target Name="AfterBuild"> 335 + </Target> 336 + --> 337 + <Target Name="AfterBuild"> 338 + <!-- Choose configuration file depending on MSBuild configuration --> 339 + <Delete Files="$(TargetDir)$(TargetFileName).config" /> 340 + <Copy SourceFiles="$(ProjectDir)\config\app.$(Configuration).config" DestinationFiles="$(TargetDir)$(TargetFileName).config" /> 341 + </Target> 342 + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> 343 + <PropertyGroup> 344 + <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText> 345 + </PropertyGroup> 346 + <Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.7.0\build\Microsoft.Net.Compilers.props'))" /> 347 + </Target> 336 348 </Project>
+5
Prx/packages.config
··· 1 + <?xml version="1.0" encoding="utf-8"?> 2 + <packages> 3 + <package id="Microsoft.Net.Compilers" version="2.7.0" targetFramework="net462" developmentDependency="true" /> 4 + <package id="System.Threading.Tasks.Extensions" version="4.4.0" targetFramework="net462" /> 5 + </packages>