我一直在使用Cobertura插件进行报告生成和检测(使用surefire).这是我面临的问题:
我无法为我的项目中的特定类生成插件忽略报告生成.
PF低于pom.xml的相关摘录,我添加了ignore标记,但这只是忽略了忽略类的检测.
我希望根本不生成特定项目的报告.
首先,由于我对Maven和Conberture的了解有限,我想知道它是否可能,如果是,那么我需要在pom.xml中完成哪些更改.
的pom.xml
<report>
<!-- other plugins exist but are not important to be listed here I guess -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
<systemProperties>
<property>
<name>net.sourceforge.cobertura.datafile</name>
<value>target/cobertura/cobertura.ser</value>
</property>
</systemProperties>
</configuration>
</plugin>
<!-- The following is the plugin for cobertura, which takes care of integration and report generation-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<check>
<branchRate>50</branchRate>
<lineRate>50</lineRate>
<haltOnFailure>true</haltOnFailure>
<totalBranchRate>50</totalBranchRate>
<totalLineRate>50</totalLineRate>
<packageLineRate>50</packageLineRate>
<packageBranchRate>50</packageBranchRate>
</check>
<instrumentation>
<ignores>
<ignore>deshaw.dportal.alert.*</ignore>
<ignore>deshaw.dportal.atc.*</ignore>
<ignore>deshaw.dportal.basket.*</ignore>
<ignore>deshaw.dportal.fcs.*</ignore>
<ignore>deshaw.dportal.event.*</ignore>
<ignore>deshaw.dportal.filings.*</ignore>
<ignore>deshaw.dportal.glg.*</ignore>
<ignore>deshaw.dportal.icp.*</ignore>
</ignores>
</instrumentation>
</configuration>
</plugin>
</report>
Run Code Online (Sandbox Code Playgroud)
编辑:
这是我的目录结构: …
instrumentation maven-2 code-coverage cobertura maven-plugin
我创建了一个示例应用程序来加载所有特殊字符,同时将粘贴从Openoffice编写器复制到记事本.双重代码不同,当我尝试加载它时.
var lines = File.ReadAllLines("..\\ter34.txt");
Run Code Online (Sandbox Code Playgroud)
这会产生65533问题的问题,文本文件包含:
“
Run Code Online (Sandbox Code Playgroud)
这已更改为符号:
?
Run Code Online (Sandbox Code Playgroud) 我在Visual Studio 2012中创建了一个新的VSIX扩展项目,并编写了一个MEF分类器(作为测试),它应该只是突出显示.mylang文件中的所有文本.以下是我的.NET 4.5代码的相关部分:
internal static class MyLangLanguage
{
public const string ContentType = "mylang";
public const string FileExtension = ".mylang";
[Export(typeof(ClassificationTypeDefinition))]
[Name(ContentType)]
[BaseDefinition("code")]
internal static ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;
[Export]
[FileExtension(FileExtension)]
[ContentType(ContentType)]
internal static FileExtensionToContentTypeDefinition MyLangSyntaxFileExtensionDefinition = null;
}
[Export(typeof(IClassifierProvider))]
[ContentType(MyLangLanguage.ContentType)]
[Name("MyLangSyntaxProvider")]
internal sealed class MyLangSyntaxProvider : IClassifierProvider
{
[Import]
internal IClassificationTypeRegistryService ClassificationRegistry = null;
public IClassifier GetClassifier(ITextBuffer buffer)
{
return buffer.Properties.GetOrCreateSingletonProperty(() => new MyLangSyntax(ClassificationRegistry, buffer));
}
}
internal sealed class MyLangSyntax : IClassifier { }
Run Code Online (Sandbox Code Playgroud)
我是Rust的新手,并试图围绕所有权/借款概念.现在我已经将代码缩减到这个给出编译错误的最小代码示例.
pub struct Display {
color: Color,
}
pub enum Color {
Blue = 0x1,
Red = 0x4,
}
impl Display {
fn get_color_value(&self) -> u16 {
self.color as u16
}
}
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)src/display.rs:12:9: 12:13 error: cannot move out of borrowed content src/display.rs:12 self.color as u16 ^~~~ error: aborting due to previous error Could not compile.
我仍然在所有的东西都被价值心态所复制,在那里它完全合法,self.color因为那会得到我的副本Color.显然,我错了.我在SO上发现了一些关于同样错误的其他问题,但没有解决我的问题.
据我了解,该领域由拥有者的所有者拥有Display.由于我只借用了一个参考Display,我不拥有它.提取color转移Color给我的所有权的尝试,这是不可能的,因为我没有拥有Display.它是否正确?
我该如何解决?
A HashSet<T>可以在O(1)中确定它是否包含某个项目.如果我覆盖Equals()并GetHashCode()在我的自定义类上,我可以有一个对象A和另一个对象A',它们不相同,但是Equals()返回true并GetHashCode()返回相同的哈希码.
现在,假设A在哈希集中,我想在给定A'的O(1)中检索A(从哈希集的角度看它等于A).
var a = new MyClass("A");
var a_prime = new MyClass("A");
Debug.Assert(a.Equals(a_prime));
Debug.Assert(a.GetHashCode() == a_prime.GetHashCode());
var set = new HashSet<MyClass>();
set.Add(a);
Debug.Assert(set.Contains(a_prime));
// This:
var retrieved_a = set.Get(a_prime);
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
一些背景信息:我想使用set来实习我自己的对象,就像C#interns strings一样:等于对象只需要一个实例.通过这种方式,我可以将元数据附加到这样的对象,并确保没有该元数据,在任何地方都没有其他相同的实例.
我正在编写一个处理某些文件的工具.此工具将具有命令行界面,但也可以用作第三方代码的类库.为了处理错误,我只是抛出异常.第三方代码可以处理异常,命令行界面可能只打印它并中止.然而,除了致命的错误之外,还有可能出现一种并非致命的情况,而且这个过程可以继续,为此我想"发出警告"并继续.
我如何处理警告,以便第三方代码和命令行界面都能用它做什么?
有没有办法利用初始化列表来选择性地初始化构造函数中的可选参数?下面的示例转换为if(?x)类型中的逻辑,因为不清楚如何在传入的情况下如何在初始化列表中设置_x.
class Point {
double _x = 0.0;
double get x => _x;
double _y = 0.0;
double get y => _y;
Point(
{
double x,
double y
})
{
if(?x) { _x = x; }
if(?y) { _y = y; }
}
}
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用构造函数:
Point(
{
double x: 0.0,
double y: 0.0
}) : _x = x, _y = y
{
}
Run Code Online (Sandbox Code Playgroud)
但是你重复自己(0.0多个地方),它看起来像_x和_y初始化两次,一次为成员,然后再由初始化列表.此外,成员初始化程序的好处是它可以是函数调用,而默认参数的默认值似乎需要常量.我希望/意识到性能影响很小.只是想要一个很好的规范方法,可能会用于代码生成.
有没有办法在C++ 11(使用最新的GCC)中获取调用当前执行的方法(调用者)的方法的名称,或文件和行号?
我想在错误消息中使用此信息,例如,以下代码失败:
void SomewhereInMyProgram()
{
DoSomething(nullptr);
}
void DoSomething(const char* str)
{
Contract::Requires(str != nullptr);
// ...
}
Run Code Online (Sandbox Code Playgroud)
目前我有代码报告错误发生在DoSomething.虽然这在技术上是正确的,但我希望它报告错误发生在SomewhereInMyProgram任何可能的地方.这会让我的生活变得更轻松!
该解决方案可以使用任何C++ 11功能,宏或GCC特定的东西,但不是我必须在每个呼叫站点添加的东西.
我认为堆栈跟踪不会帮助我,因为我不能使用异常处理.实际上,我非常有限:它是一个独立的环境,标准的C++标头不可用.我希望得到某种宏观解决方案.
class Contract
{
public:
static void RequiresImpl(bool condition, const char* expression,
const char* file, int line);
#define Requires(condition) RequiresImpl(condition, #condition , \
__FILE__, __LINE__ )
};
Run Code Online (Sandbox Code Playgroud) 我为Visual Studio 1.0.2下载了MySQL Connector/Net 6.7.4和MySQL,然后按照这些说明进行测试:
运行应用程序,我得到了这个例外:
ConfigurationErrorsException:无法找到或加载已注册的.Net Framework数据提供程序.
然后我将对6.7.4.0 MySql.Data和MySql.Data.Entity库版本6.7.4.0的引用添加到我的.NET 4.5项目中.现在当我运行应用程序时,我得到一个不同的例外:
FileLoadException:无法加载文件或程序集"MySql.Data,Version = 6.6.5.0,culture = neutral,PublicKeyToken = c5687fc88969c44d"或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
请注意版本号,它不是我安装的MySQL Connector的版本.
如何让它正常工作?
如何最有效地跳过任何字节数Stream?
如果可能的话,我想EndOfStreamException在尝试跳过流的末尾时获取或抛出.
我正在Reader为ISO 9660原始数据类型编写自定义流,这可能涉及大量跳过可搜索和不可搜索的流,包括小数(4)和大数(2048)字节.因此,我想实现一种Skip(int count)比读取和丢弃跳过的字节更有效的方法.
例如,在一个可搜索的流中,我可能会这样做stream.Position += 4,但是这不会EndOfStreamException在搜索流的末尾时抛出,并且我不知道如何在不读取内容的情况下测试它.对于不可搜索的流,设置Position甚至不是一个选项,但是读取并随后丢弃大量字节并分配未使用的字节数组似乎非常浪费.