Expecto allows you to set parameters via CLIArguments and also by overriding its defaultConfig. One of the parameters is --summary. Currently I just directly pass "--summary" and merge it with argv but is there a parameter (I assume 'printer') that can be overridden? In that case, how? This is what I do now:
open Expecto
open Expecto.Impl
open Expecto.Logging
[<EntryPoint>]
let main argv =
let defaultConfig = {
defaultConfig with
colour = Logging.Colour256
verbosity = LogLevel.Info
}
let argv = Array.append argv [|"--summary"|]
Tests.runTestsInAssembly defaultConfig argv
From source code
| Summary -> fun o -> {o with printer = TestPrinters.summaryPrinter o.printer}
Related
I'm rewriting this code:
use regex::Regex;
use std::fs;
use std::io;
fn main() {
let contents = fs::read_to_string("/home/jerzy/trackers_best.txt")
.expect("Something went wrong reading the file");
println!("Give me the magnet link.");
let mut magnet = String::new();
io::stdin()
.read_line(&mut magnet)
.expect("Failed to read line");
magnet = magnet.trim().to_string();
let re = Regex::new(r"\&tr=.{3,1000}").expect("Failed to initialize the variable `re`.");
magnet = re.replace(&magnet, contents).to_string();
println!("The updated magnet link:\n{}", magnet);
}
/home/jerzy/trackers_best.txt is a text file that gets automatically downloaded every evening to my home directory from https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt with the help of wget and cron.
I want to use the hyperscan crate instead of the regex crate to improve the performance.
The new code:
use hyperscan::regex::Regex;
use std::fs;
use std::io;
fn main() {
let contents = fs::read_to_string("/home/jerzy/trackers_best.txt")
.expect("Something went wrong reading the file");
println!("Give me the magnet link.");
let mut magnet = String::new();
io::stdin()
.read_line(&mut magnet)
.expect("Failed to read line");
magnet = magnet.trim().to_string();
let re = Regex::new(r"\&tr=.{3,1000}").expect("Failed to initialize the variable `re`.");
magnet = re.replace(&magnet, contents).to_string();
println!("The updated magnet link:\n{}", magnet);
}
The dependencies section of my Cargo.toml:
[dependencies]
hyperscan = "0.2.2"
This code does not compile, I get the following output from the compiler:
error[E0599]: no method named `replace` found for struct `Regex` in the current scope
--> src/main.rs:26:14
|
26 | magnet = re.replace(&magnet, contents).to_string();
| ^^^^^^^ method not found in `Regex`
How might I rewrite the line in question? What method should I use instead of .replace()?
I looked for resources about using hyperscan, but there is not much on their GitHub.
I need to generate a value with a different type from my passed type. This is the first time I write on ocaml-like, and for example, in a familiar me haskell I would use Data.Generics.
How I have understood I need to use decorator and ppx. I wrote simple example
let recordHandler = (loc: Location.t, _recFlag: rec_flag, _t: type_declaration, fields: list(label_declaration)) => {
let (module Builder) = Ast_builder.make(loc);
let test = [%str
let schema: Schema = { name: "", _type: String, properties: [] }
]
let moduleExpr = Builder.pmod_structure(test);
[%str
module S = [%m moduleExpr]
]
}
let str_gen = (~loc, ~path as _, (_rec: rec_flag, t: list(type_declaration))) => {
let t = List.hd(t)
switch t.ptype_kind {
| Ptype_record(fields) => recordHandler(loc, _rec, t, fields);
| _ => Location.raise_errorf(~loc, "schema is used only for records.");
};
};
let name = "my_schema";
let () = {
let str_type_decl = Deriving.Generator.make_noarg(str_gen);
Deriving.add(name, ~str_type_decl) |> Deriving.ignore;
};
And
open Ppxlib;
let _ = Driver.run_as_ppx_rewriter()
But in using in rescript code
module User = {
#deriving(my_schema)
type my_typ = {
foo: int,
};
};
I caught:
schema is not supported
. And I made myself sure me to connect it right when I had changed #deriving(my_schema) for #deriving(abcd) and #deriving(sschema).
I got different error
Ppxlib.Deriving: 'abcd' is not a supported type deriving generator.
And my last experiment was to copy past existing library deriving accessors .
ppx_accessor
I copied-pasted it and renamed for accessors_2. And I got same error such as experiment.
accessors_2 is not supported
Also I haven't found examples "ppx rescript". Can you please help me.
What am I doing wrong (ALL , I know)
I have found answer in the article
Dropping support for custom PPXes such as ppx_deriving (the deriving
attribute is now exclusively interpreted as bs.deriving)
Suppose I have the following three paths:
let file = path::Path::new("/home/meurer/test/a/01/foo.txt");
let src = path::Path::new("/home/meurer/test/a");
let dst = path::Path::new("/home/meurer/test/b");
Now, I want to copy file into dst, but for that I need to correct the paths, so that I can have new_file with a path that resolves to /home/meurer/test/b/01/foo.txt. In other words, how do I remove src from file and then append the result to dst?
/home/meurer/test/a/01/foo.txt -> /home/meurer/test/b/01/foo.txt
Note that we can't assume that src will always be this similar to dst.
You can use Path::strip_prefix and Path::join:
use std::path::Path;
fn main() {
let file = Path::new("/home/meurer/test/a/01/foo.txt");
let src = Path::new("/home/meurer/test/a");
let dst = Path::new("/home/meurer/test/b");
let relative = file.strip_prefix(src).expect("Not a prefix");
let result = dst.join(relative);
assert_eq!(result, Path::new("/home/meurer/test/b/01/foo.txt"));
}
As usual, you probably don't want to use expect in your production code, it's only for terseness of the answer.
I have added a new feature to CIL(C Intermediate Language). I am able to execute my new module using
$cilly --dotestmodule --save-temps -D HAPPY_MOOD -o test test.c
Now, in my testmodule, I want to call Cfg.computeFileCFG for test.c file. But I don't know how to access test.c file in my module.
I tried using Cil.file. but it says "Unbound value Cil.file".
my code:
open Pretty
open Cfg
open Cil
module RD = Reachingdefs
let () = Cfg.computeFileCFG Cil.file
let rec fact n = if n < 2 then 1 else n * fact(n-1)
let doIt n = fact n
let feature : featureDescr =
{ fd_name = "testmodule";
fd_enabled = ref false;
fd_description = "simple test 1240";
fd_extraopt = [];
fd_doit = (function (f: file) -> ignore (doIt 10));
fd_post_check = true;
}
please tell me how to compute the Cfg for test.c file.
I am not a CIL expert, but here are a few remarks:
the CIL online documentation states that Cil.file is an Ocaml type. Passing a type as an argument to a function is probably not what you want to do here;
it seems like the fd_doit function in your feature descriptor takes the file you are looking to process as its argument f;
according to the Cilly manual, the type of f is Cil.file. Conveniently, this seems to be the type of the argument required by the function computeFileCFG.
Hopefully you can take it from here. Good luck!
I use the Exchange webservices to extract attachments from exchange mailserver.
When i call the code on linux with mono a certain text attachment contain some mixed-up strings.
like so
"sam winglin vz" becomes "sainglin vz" -> so it is missing "m w".
I see this about 3 times in a 150kb file. 3 bytes are missing in the linux output vs the windows output.
When i extract it from visual studio the text attachment is perfect.
It is like this example
Save attachments from exchange inbox
Any idea in what direction i should look to fix this?
Code:
#r "Microsoft.Exchange.WebServices.dll"
open Microsoft
open Microsoft.Exchange.WebServices.Data
open System
open System.Net
type PgzExchangeService(url,user,password) =
let service = new ExchangeService(ExchangeVersion.Exchange2007_SP1,
TimeZoneInfo.CreateCustomTimeZone("Central Standard Time",new TimeSpan(-6, 0, 0),"(GMT-06:00) Central Time (US & Canada)","Central Standard Time"))
do
ServicePointManager.ServerCertificateValidationCallback <- ( fun _ _ _ _ -> true )
service.Url <- new Uri(url)
service.Credentials <- new WebCredentials(user, password, "domain")
member this.Service with get() = service
member this.InboxItems = this.Service.FindItems(WellKnownFolderName.Inbox, new ItemView(10))
member this.GetFileAttachments ( item : Item ) =
let emailMessage =
EmailMessage.Bind( this.Service,
item.Id,
new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments))
item, emailMessage.Attachments |> Seq.choose (fun attachment -> match box attachment with
| :? FileAttachment as x -> Some(x) | _ -> None)
let mailAtdomain = new PgzExchangeService("https://xx.xx.XX.XX/EWS/Exchange.asmx", "user", "passw")
let printsave (item : Item ,att : seq<FileAttachment>) =
if (Seq.length att) > 0 then
printfn "%A - saving %i attachments" item.Subject (Seq.length att)
att |> Seq.iter ( fun attachment -> printfn "%A" attachment.Name
attachment.Load(#"/tmp/test/" + attachment.Name ) )
// filter so we only have items with attachements and ...
let itemsWithAttachments = mailAtdomain.InboxItems
|> Seq.map mailAtdomain.GetFileAttachments
|> Seq.iter printsave
The code doesn't run on Windows with mono due to a bug in TimeZoneInfo
This sample code runs on linux but not on windows. because of the TimeZoneInfo bug.
But with this the code that works on linux to extract attachments.
Try csv attachments and see if the result is the same. i loose data ! about 3 bytes every somemany lines
mail me if you need the sample csv attachment that gives the problem
Here is a c# version that i used for testing. Running from VS2010 it works perfect but on linux with mono the attachment has wrong size , some bytes are missing?!.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
using System.Net;
namespace Exchange_SDP_Attachment_Extracter
{
public class PgzExchangeService
{
public void Extract()
{
ExchangeService service = new ExchangeService (ExchangeVersion.Exchange2007_SP1,TimeZoneInfo.Local);
service.Credentials = new NetworkCredential("user", "pass", "domain");
service.Url = new Uri("https://xx.xx.xx.xx/EWS/Exchange.asmx");
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
foreach (Item item in findResults.Items)
{
EmailMessage e = EmailMessage.Bind
(service,
item.Id,
new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
foreach ( Attachment att in e.Attachments )
{
if (att is FileAttachment)
{
FileAttachment fileAttachment = (FileAttachment)att;
fileAttachment.Load(#"/tmp/testsdp/" + fileAttachment.Name);
}
}
}
}
}
class Program
{
static void Main(string[] args)
{
PgzExchangeService pgz = new PgzExchangeService();
pgz.Extract();
}
}
}
My suggestion would be to try examining the text attachment with a hex editor. There has be something unusual about those three occurrences. You need to find out what those three lines have in common before any of us can recommend a course of action to you.