我是haskell的新手,正在进行单元测试,但我发现生态系统非常混乱.我对HTF和HUnit之间的关系感到困惑.
在一些示例中,我看到您设置测试用例,将它们导出到测试列表中,然后在ghci中运行runTestsTT(如此HUnit示例).
在其他示例中,您创建一个绑定到cabal文件的测试运行器,该文件使用一些预处理器魔法来查找您的测试,就像在这个git示例中一样.似乎HTF测试需要加上前缀test_或者它们不运行?我很难找到任何相关的文档,我只是注意到每个人都有的模式.
无论如何,有人可以帮我解决这个问题吗?什么被认为是在Haskell做事的标准方式?什么是最佳做法?什么是最容易设置和维护?
出于好奇,我试图使用C#生成尾调用操作码.Fibinacci是一个简单的,所以我的c#示例如下所示:
private static void Main(string[] args)
{
Console.WriteLine(Fib(int.MaxValue, 0));
}
public static int Fib(int i, int acc)
{
if (i == 0)
{
return acc;
}
return Fib(i - 1, acc + i);
}
Run Code Online (Sandbox Code Playgroud)
如果我在发布中构建并在没有调试的情况下运行它,我就不会出现堆栈溢出.在没有优化的情况下调试或运行它,我确实得到了堆栈溢出,这意味着尾部调用在发布时具有优化功能(这是我的预期).
这个MSIL看起来像这样:
.method public hidebysig static int32 Fib(int32 i, int32 acc) cil managed
{
// Method Start RVA 0x205e
// Code Size 17 (0x11)
.maxstack 8
L_0000: ldarg.0
L_0001: brtrue.s L_0005
L_0003: ldarg.1
L_0004: ret
L_0005: ldarg.0
L_0006: ldc.i4.1
L_0007: sub
L_0008: ldarg.1
L_0009: ldarg.0
L_000a: …Run Code Online (Sandbox Code Playgroud) 我正在调试我的构建过程中偶尔发生的错误,但我无法直接重现它.我正在使用msbuild和teamcity.
我有一个这样的依赖层次结构:
Some.Interop.dll
Dependency-> SharedDllABC.dll
SomeService.exe
Depenendcy-> Some.Interop
Run Code Online (Sandbox Code Playgroud)
通常,最终服务exectuable进入其发布目录:
Some.Interop
SharedDllABC.Dll
ServiceExectuable.exe
Run Code Online (Sandbox Code Playgroud)
但是我可以在我们的msbuild日志中看到,在构建完所有内容后,有时会在Incremental Clean期间删除三级依赖项,从而导致:
Some.Interop
ServiceExectuable.exe
Run Code Online (Sandbox Code Playgroud)
您可以在msbuild日志中看到它:
[src\SomeService\SomeService.csproj] _TimeStampAfterCompile
[12:32:43]: [src\SomeService\SomeService.csproj] Compile
// some other targets
[12:32:43]: [src\SomeService\SomeService.csproj] _CopyFilesMarkedCopyLocal
[12:32:43]: [_CopyFilesMarkedCopyLocal] Copy
[12:32:43]: [Copy] Copying file from "C:Projects\trunk\src\Some.Interop\bin\Release\Some.Interop.dll" to "bin\Release\Some.Interop.dll".
// some other targets
[src\Project\SomeService\SomeService.csproj] IncrementalClean
[18:54:42]: [IncrementalClean] Delete
[18:54:42]: [Delete] Deleting file "C:\Projects\trunk\src\Project\SomeService\bin\Release\SharedDllABC.dll".
[18:54:42]: [Delete] Deleting file "C:\Projects\trunk\src\Project\SomeServiceService\bin\Release\SharedDllABC.pdb".
[18:54:42]: [src\Project\SomeService\SomeService.csproj] CoreBuild
[18:54:42]: [src\Project\SomeService\SomeService.csproj] AfterBuild
[18:54:42]: [src\Project\SomeService\SomeService.csproj] Build
Run Code Online (Sandbox Code Playgroud)
这是我的直接msbuild输出,我刚刚更改了项目名称/ dll名称以匹配我的示例.当这个增量清洁已经发生时,SomeService.csproj已经建成了.你可以看到它没有被复制.但是在其他msbuild日志中,它会被正确复制,然后增量清理不会删除它.
我认为从这篇文章中增加清理应该是清理从以前版本创建的dll,但这并不能解释这个dll在大多数情况下是如何构建的.在视觉工作室,这总是有效.
我想我只是想知道究竟是Incremental clean什么,是什么导致它开始,也许在调试这样的情况时我应该寻找什么样的东西(汇编版本,时间戳等?)
我的同事和我正在比较传递lambda来做工作时C#函数的速度,而内联函数与工作时间有关.我们发现,在将lambda投影传递给C#select函数时(例如),您想要查看F#是否存在相同的问题,或者它是否有不同之处.
无论我们的初衷是什么,我们偶然发现了一些我们无法弄清楚的事情.在下面的例子中,我们总结了3种不同的方式
module fs
open NUnit.Framework
open FsUnit
open System
open System.Diagnostics;
[<Test>]
let sumTest() =
let nums = [0..1000]
let repeat = 100000
let stopWatch = new Stopwatch()
stopWatch.Start()
let sumsReduce =
[
for i in [0..repeat] do
yield List.reduce (+) nums
]
Console.WriteLine("reduce = {0} - Time = {1}", List.head sumsReduce, stopWatch.Elapsed.TotalSeconds);
stopWatch.Restart()
let sumsSum =
[
for i in [0..repeat] do
yield List.sum nums
]
Console.WriteLine("sum = {0} - Time = {1}", List.head sumsSum, …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,在调试模式下写入许多单独的JavaScript文件,但作为页面的head块的一部分同步加载.在发布中,我将所有这些文件合并在一起并将它们缩小.今天我一直在缩小版本中发现错误,所以我加载了一个合并文件来调试问题,发现一个库是自动执行一个函数,它导致其他函数window被执行.
我已经使用通用对象回复了这里的行为,无论窗口与否都无关紧要:
<head>
<script>
var a = {}
a.X = function x(){
console.log("shouldn't be executed");
}
(function(a){
console.log("self execution");
}(a));
</script>
</head>
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我得到了输出
self execution
shouldn't be executed
Run Code Online (Sandbox Code Playgroud)
如果我将呼叫改为
<head>
<script>
var a = {}
function x(){
console.log("shouldn't be executed");
}
a.X = x;
(function(a){
console.log("self execution");
}(a));
</script>
</head>
Run Code Online (Sandbox Code Playgroud)
然后我就明白了
self execution
Run Code Online (Sandbox Code Playgroud)
这是我的预期.在第一个例子中,为什么X在a传递给自执行函数时被调用?
我有一个类名和一个我知道类型参数的方法,我想通过反射调用这个方法。
在java中我会做类似的事情:
Class.forName("foo").getMethod("name", ... type args...).invoke(null, ..args)
Run Code Online (Sandbox Code Playgroud)
但是在 Scala 中,每当我尝试调用时,都会收到一个空引用错误。
我正在使用 Scala 2.10.4
- 编辑
我试过了:
$ scala
Welcome to Scala version 2.10.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class Foo { def bar(x: Int) = x }
defined class Foo
scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._
scala> val foo = new Foo
foo: Foo = Foo@2db7a79b
scala> runtimeMirror(getClass.getClassLoader).reflect(foo)
res0: reflect.runtime.universe.InstanceMirror = instance mirror for Foo@2db7a79b
scala> …Run Code Online (Sandbox Code Playgroud) 我正在尝试以编程方式将绑定添加到我的默认网站,但是我一直在Microsoft.Web.Administration dll中获得空引用异常.最初我想分配证书和绑定.我能够用这个来查询我想要的证书:
var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);
var certificate = store.Certificates.Find(X509FindType.FindByIssuerName,
"TEST_SELF_SIGNED", true)
.OfType<X509Certificate>().FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
这正确地给了我我想要的证书,它是非空的并且有我期望的信息.
Site site = GetSite("Default Web Site");
var binding = site.Bindings.Add("*:443", certificate.GetCertHash(), "https");
Run Code Online (Sandbox Code Playgroud)
鉴于我的变量或示例代码中的任何其他项都不为null(包括返回20字节数组的GetCertHash),我很困惑为什么我在这里得到一个null.我甚至尝试了以下重载:
site.Bindings.Add("*:443", "https");
Run Code Online (Sandbox Code Playgroud)
我仍然得到相同的空ref堆栈:
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=Microsoft.Web.Administration
StackTrace:
at Microsoft.Web.Administration.Configuration.SetDirty()
at Microsoft.Web.Administration.ConfigurationElement.SetDirty()
at Microsoft.Web.Administration.ConfigurationElement.SetAttributeValue(String attributeName, Object value)
at Microsoft.Web.Administration.Binding.SetBindingProperty(String attributeName, String value)
at Microsoft.Web.Administration.BindingCollection.Add(String bindingInformation, Byte[] certificateHash, String certificateStoreName)
at TestApp.Program.Main(String[] args) in C:\Projects\Cube\trunk\src\AutoUpdate\TestApp\Program.cs:line 33
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, … 我将数据发布到由一些消费者处理的kinesis流.我希望发布到流的原始数据也存储在s3中.是否有可能将kinesis流自动连接到kinesis firehose或我是否需要直接从kinesis消费者发布到firehose?
我正在尝试使用纱线建立一个monorepo。我对如何使用项目引用设置打字稿感到困惑,以便正确解决问题。
例如,如果我有一个类似的文件夹结构
/cmd
/client
Run Code Online (Sandbox Code Playgroud)
我想cmd依靠client我可以拥有:
cmd/tsconfig.json:
{
"compilerOptions": {
"types": ["reflect-metadata", "jest"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"declaration": true,
"importHelpers": true,
"composite": true,
"target": "esnext"
"sourceRoot": "src",
"outDir": "dist"
},
"references": [
{
"path": "../client"
}
],
"include": [
"src/**/*"
]
}
Run Code Online (Sandbox Code Playgroud)
与一个 package.json
{
"name": "cmd",
"version": "1.0.0",
"dependencies": {
"client": "^1.0.0",
}
}
Run Code Online (Sandbox Code Playgroud)
在此模型中,cmd并client使用在tsconfig中设置的outDir和sourceRoot字段进行编译。这意味着所有的编译的JavaScript进入dist/的子文件夹cmd/dist和client/dist
如果我现在尝试和引用类client为cmd像 …
我确信这个问题已在某个地方得到解答,但我遇到了一些重大问题,找到了正确的关键字组合来找到它.
我很想知道它是否有可能做到这样的事情:
dynamic someObj = new SomeObject();
var methodName = "someMethodName";
// execute methodName on someObj
Run Code Online (Sandbox Code Playgroud)
我基本上想知道是否可以使用存储方法名称的变量在动态对象上执行方法.